当前位置: 首页>>代码示例>>Java>>正文


Java TupleExpr类代码示例

本文整理汇总了Java中org.openrdf.query.algebra.TupleExpr的典型用法代码示例。如果您正苦于以下问题:Java TupleExpr类的具体用法?Java TupleExpr怎么用?Java TupleExpr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TupleExpr类属于org.openrdf.query.algebra包,在下文中一共展示了TupleExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: rewrite

import org.openrdf.query.algebra.TupleExpr; //导入依赖的package包/类
/**
 * Rewrite a given query to add inference.
 *
 * @param ql the query language used for the query
 * @param query the query to rewrite
 * @param baseuri a base URI to use for the query
 * @return rewritten query that includes inference
 * @throws MalformedQueryException if the query is malformed
 * @throws RepositoryException if there was a problem while rewriting
 */
public Query rewrite(QueryLanguage ql, String query, String baseuri)
		throws MalformedQueryException, RepositoryException {
	// parse query using Sesame
	QueryParserFactory f = QueryParserRegistry.getInstance().get(ql);
	QueryParser parser = f.getParser();
	ParsedQuery parsed = parser.parseQuery(query, baseuri);
	// get SPARQL algebra expression from parsed query
	TupleExpr expr = parsed.getTupleExpr();
	// rewrite query using visitor pattern
	RuleTransformationVisitor visitor
			= new RuleTransformationVisitor(rules);
	expr.visit(visitor);
	// return new query based on rewritten algebra expression
	return getExprQuery(parsed, expr);
}
 
开发者ID:lszeremeta,项目名称:neo4j-sparql-extension-yars,代码行数:26,代码来源:QueryRewriter.java

示例2: getJoinSelect

import org.openrdf.query.algebra.TupleExpr; //导入依赖的package包/类
public double getJoinSelect(RdfCloudTripleStoreConfiguration conf, TupleExpr te1, TupleExpr te2) throws TableNotFoundException {

      SpExternalCollector spe = new SpExternalCollector();
      te2.visit(spe);
      List<QueryModelNode> espList = spe.getSpExtTup();  
      
      double min = Double.MAX_VALUE;

      for (QueryModelNode node : espList) {
        double select = getSelectivity(conf, te1, node);
        if (min > select) {
          min = select;
        }
      }

      return min;
    }
 
开发者ID:apache,项目名称:incubator-rya,代码行数:18,代码来源:AccumuloSelectivityEvalDAO.java

示例3: groupEquivalentPlans

import org.openrdf.query.algebra.TupleExpr; //导入依赖的package包/类
public Set<Set<TupleExpr>> groupEquivalentPlans(Collection<TupleExpr> plans) {
	
	// put query plans in same category if the have the same patterns
	Map<Set<StatementPattern>, Set<TupleExpr>> equivalent = new HashMap<Set<StatementPattern>, Set<TupleExpr>>();

	// Collect all equivalent plans, i.e. plans with the same patterns
	for (TupleExpr plan : plans) {
		Set<StatementPattern> patterns = new HashSet<StatementPattern>(StatementPatternCollector.process(plan));
		Set<TupleExpr> planSet = equivalent.get(patterns);
		
		if (planSet == null) {
			planSet = new HashSet<TupleExpr>();
			equivalent.put(patterns, planSet);
		}
		
		planSet.add(plan);
	}
	return new HashSet<Set<TupleExpr>>(equivalent.values());
}
 
开发者ID:goerlitz,项目名称:rdffederator,代码行数:20,代码来源:DynamicProgrammingOptimizer.java

示例4: getJoinArgs

import org.openrdf.query.algebra.TupleExpr; //导入依赖的package包/类
/**
 * This method is used to retrieve a set view of all descendants of the
 * rightArg of the LeftJoin (the optional part)
 *
 * @param tupleExpr
 *            - tupleExpr whose args are being retrieved
 * @param joinArgs
 *            - set view of all non-join args that are descendants of
 *            tupleExpr
 * @return joinArgs
 */
private Set<TupleExpr> getJoinArgs(TupleExpr tupleExpr, Set<TupleExpr> joinArgs) {
    if (tupleExpr instanceof Join) {
        if (!(((Join) tupleExpr).getLeftArg() instanceof FixedStatementPattern)
                && !(((Join) tupleExpr).getRightArg() instanceof DoNotExpandSP)) {
            Join join = (Join) tupleExpr;
            getJoinArgs(join.getLeftArg(), joinArgs);
            getJoinArgs(join.getRightArg(), joinArgs);
        }
    } else if (tupleExpr instanceof LeftJoin) { // TODO probably not
                                                // necessary if not
                                                // including leftarg
        LeftJoin lj = (LeftJoin) tupleExpr;
        joinArgs.add(new FlattenedOptional(lj));
        getJoinArgs(lj.getLeftArg(), joinArgs);
    } else if (tupleExpr instanceof Filter) {
        getJoinArgs(((Filter) tupleExpr).getArg(), joinArgs);
    } else {
        joinArgs.add(tupleExpr);
    }

    return joinArgs;
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:34,代码来源:FlattenedOptional.java

示例5: meet

import org.openrdf.query.algebra.TupleExpr; //导入依赖的package包/类
@Override
public void meet(final Join node) throws Exception {
    super.meet(node);

    final TupleExpr leftArg = node.getLeftArg();
    final TupleExpr rightArg = node.getRightArg();

    /**
     * if join(join(1, 2), join(3,4))
     * should be:
     * join(join(join(1,2), 3), 4)
     */
    if (leftArg instanceof Join && rightArg instanceof Join) {
        final Join leftJoin = (Join) leftArg;
        final Join rightJoin = (Join) rightArg;
        final TupleExpr right_LeftArg = rightJoin.getLeftArg();
        final TupleExpr right_rightArg = rightJoin.getRightArg();
        final Join inner = new Join(leftJoin, right_LeftArg);
        final Join outer = new Join(inner, right_rightArg);
        node.replaceWith(outer);
    }

}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:24,代码来源:PushJoinDownVisitor.java

示例6: evaluate

import org.openrdf.query.algebra.TupleExpr; //导入依赖的package包/类
static CloseableIteration<BindingSet, QueryEvaluationException> evaluate(
        final TripleTransaction transaction, final TupleExpr expr,
        @Nullable final Dataset dataset, @Nullable final BindingSet bindings,
        @Nullable final Long timeout) throws QueryEvaluationException {

    Preconditions.checkNotNull(transaction);

    final AtomicBoolean delegate = new AtomicBoolean(false);
    expr.visit(new QueryModelVisitorBase<RuntimeException>() {

        @Override
        public void meet(final StatementPattern node) throws RuntimeException {
            delegate.set(true);
        }

    });

    final EvaluationStrategy strategy = delegate.get() ? new DelegatingEvaluationStrategy(
            transaction, dataset, timeout, false) : new LocalEvaluationStrategy(transaction,
            dataset, timeout);

    return strategy
            .evaluate(expr, bindings != null ? bindings : EmptyBindingSet.getInstance());
}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:25,代码来源:SparqlHelper.java

示例7: testNoConstants

import org.openrdf.query.algebra.TupleExpr; //导入依赖的package包/类
/**
 * @throws Exception
 *             Tests QueryVariableNormalizerContext with two queries whose
 *             StatementPattern nodes contain no constant Vars.
 */
@Test
public void testNoConstants() throws Exception {

    SPARQLParser parser1 = new SPARQLParser();
    SPARQLParser parser2 = new SPARQLParser();

    ParsedQuery pq1 = parser1.parseQuery(q15, null);
    ParsedQuery pq2 = parser2.parseQuery(q16, null);

    List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(),
            pq2.getTupleExpr());

    Assert.assertEquals(2,normalize.size());
    for (TupleExpr s : normalize) {
        Assert.assertTrue(isTupleSubset(pq1.getTupleExpr(), s));
    }

    pq1 = parser1.parseQuery(q16, null);
    pq2 = parser2.parseQuery(q17, null);
    normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(), pq2.getTupleExpr());

    Assert.assertTrue(normalize.size() == 0);

}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:30,代码来源:VarConstQueryVariableNormalizerTest.java

示例8: testNoConstants

import org.openrdf.query.algebra.TupleExpr; //导入依赖的package包/类
/**
 * @throws Exception
 *             Tests QueryVariableNormalizerContext with two queries whose
 *             StatementPattern nodes contain no constant Vars.
 */
@Test
public void testNoConstants() throws Exception {

	SPARQLParser parser1 = new SPARQLParser();
	SPARQLParser parser2 = new SPARQLParser();

	ParsedQuery pq1 = parser1.parseQuery(q15, null);
	ParsedQuery pq2 = parser2.parseQuery(q16, null);

	List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(),
			pq2.getTupleExpr());

	Assert.assertTrue(normalize.size() == 2);
	for (TupleExpr s : normalize) {
		Assert.assertTrue(isTupleSubset(pq1.getTupleExpr(), s));
	}

	pq1 = parser1.parseQuery(q16, null);
	pq2 = parser2.parseQuery(q17, null);
	normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(), pq2.getTupleExpr());

	Assert.assertTrue(normalize.size() == 0);

}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:30,代码来源:QueryVariableNormalizerTest.java

示例9: tupleReArrangeTest4

import org.openrdf.query.algebra.TupleExpr; //导入依赖的package包/类
@Test
public void tupleReArrangeTest4() throws MalformedQueryException {

    String queryString = ""//
            + "SELECT ?a ?b ?c ?d ?e ?x ?y" //
            + "{" //
            + " Filter(?c = <uri:label2>)" //
            + " Filter(?x = <uri:somethingFunny>) "//
            + " Filter(?d = <uri:Fred> ) " //
            + " ?e <uri:laughsAt> ?x ." //
            + " ?e <uri:livesIn> ?y . "//
            + "{ ?a a ?b .  ?a <http://www.w3.org/2000/01/rdf-schema#label> ?c  }"//
            + " UNION { ?a <uri:talksTo> ?d .  ?a <http://www.w3.org/2000/01/rdf-schema#label> ?e  }"//
            + "}";//

    SPARQLParser sp = new SPARQLParser();
    ParsedQuery pq = sp.parseQuery(queryString, null);
    TupleExpr te = pq.getTupleExpr();
    new FilterOptimizer().optimize(te, null, null);
    System.out.println(te);
    List<TupleExpr> tuples = TupleReArranger.getTupleReOrderings(te);
    System.out.println(tuples);

    Assert.assertEquals(24, tuples.size());

}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:27,代码来源:TupleReArrangerTest.java

示例10: make

import org.openrdf.query.algebra.TupleExpr; //导入依赖的package包/类
/**
 * Make a {@link MultiProjectionEvaluator} that processes the logic of a {@link MultiProjection}.
 *
 * @param multiProjection - Defines the projections that will be processed. (not null)
 * @param bNodeIdFactory - Creates the IDs for Blank Nodes. (not null)
 * @return A {@link MultiProjectionEvaluator} for the provided {@link MultiProjection}.
 */
public static MultiProjectionEvaluator make(final MultiProjection multiProjection, final BNodeIdFactory bNodeIdFactory) {
    requireNonNull(multiProjection);

    // Figure out if there are extensions.
    final TupleExpr arg = multiProjection.getArg();
    final Optional<Extension> extension = (arg instanceof Extension) ? Optional.of((Extension)arg): Optional.empty();

    // If there are, iterate through them and find any blank node source names.
    final Set<String> blankNodeSourceNames = new HashSet<>();
    if(extension.isPresent()) {
        for(final ExtensionElem elem : extension.get().getElements()) {
            if(elem.getExpr() instanceof BNodeGenerator) {
                blankNodeSourceNames.add( elem.getName() );
            }
        }
    }

    // Create a ProjectionEvaluator for each projection that is part of the multi.
    final Set<ProjectionEvaluator> projections = new HashSet<>();
    for(final ProjectionElemList projectionElemList : multiProjection.getProjections()) {
        projections.add( new ProjectionEvaluator(projectionElemList, extension) );
    }

    return new MultiProjectionEvaluator(projections, blankNodeSourceNames, bNodeIdFactory);
}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:33,代码来源:MultiProjectionEvaluator.java

示例11: optimize

import org.openrdf.query.algebra.TupleExpr; //导入依赖的package包/类
@Override
	public void optimize(TupleExpr query, Dataset dataset, BindingSet bindings) {  // Sesame 2
		
		// collect all basic graph patterns
		for (TupleExpr bgp : BasicGraphPatternExtractor.process(query)) {
			
//			// a single statement pattern needs no optimization
//			// TODO: need sources first
//			if (bgp instanceof StatementPattern)
//				continue;
			
			if (LOGGER.isTraceEnabled())
				LOGGER.trace("BGP before optimization:\n" + AnnotatingTreePrinter.print(bgp));

			bgp = optimizeBGP(bgp);
			
			if (LOGGER.isTraceEnabled() && modelEvaluator != null)
				LOGGER.trace("BGP after optimization:\n" + AnnotatingTreePrinter.print(bgp, modelEvaluator));
		}
		
	}
 
开发者ID:goerlitz,项目名称:rdffederator,代码行数:22,代码来源:AbstractFederationOptimizer.java

示例12: testVarGraph

import org.openrdf.query.algebra.TupleExpr; //导入依赖的package包/类
@Test
public void testVarGraph() throws Exception {

	SPARQLParser parser1 = new SPARQLParser();
	SPARQLParser parser2 = new SPARQLParser();

	ParsedQuery pq1 = parser1.parseQuery(q19, null);
	ParsedQuery pq2 = parser2.parseQuery(q22, null);

	List<TupleExpr> normalize = QueryVariableNormalizer.getNormalizedIndex(pq1.getTupleExpr(),
			pq2.getTupleExpr());

	Assert.assertTrue(normalize.size() == 1);
	for (TupleExpr s : normalize) {
		Assert.assertTrue(tupleEquals(s, pq1.getTupleExpr()));
	}

}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:19,代码来源:QueryVariableNormalizerTest.java

示例13: fetchArgResults

import org.openrdf.query.algebra.TupleExpr; //导入依赖的package包/类
public CloseableIteration<BindingSet, QueryEvaluationException>  fetchArgResults(final TupleExpr joinArg, final BindingSet bindings) {
//		Callable<Cursor<BindingSet>> callable = new Callable<Cursor<BindingSet>>() {
		Callable<CloseableIteration<BindingSet, QueryEvaluationException>>  callable = new Callable<CloseableIteration<BindingSet, QueryEvaluationException>>() {
//			@Override public Cursor<BindingSet> call() {
			@Override public CloseableIteration<BindingSet, QueryEvaluationException> call() {
//				return evaluate(joinArg, bindings);
				try {
					return evaluate(joinArg, bindings);
				} catch (QueryEvaluationException e) {
					e.printStackTrace();
					return null;
				}
			}
		};
//		Future<Cursor<BindingSet>> future = executor.submit(callable);
		Future<CloseableIteration<BindingSet, QueryEvaluationException>> future = executor.submit(callable);
		return new AsyncCursor<BindingSet>(future);
	}
 
开发者ID:goerlitz,项目名称:rdffederator,代码行数:19,代码来源:FederationEvalStrategy.java

示例14: delegate

import org.openrdf.query.algebra.TupleExpr; //导入依赖的package包/类
private CloseableIteration<BindingSet, QueryEvaluationException> delegate(
        final TupleExpr expr, final BindingSet bindings) throws QueryEvaluationException {

    try {
        // Skolemize bindings if necessary
        final BindingSet actualBindings = this.skolemize ? skolemize(bindings) : bindings;

        // Convert the algebraic sub-tree into a SelectQuery
        final SelectQuery query = SelectQuery.from(expr, this.dataset);

        // Delegate to TripleStore component
        return this.transaction.query(query, actualBindings, this.timeout);

    } catch (final IOException ex) {
        throw new QueryEvaluationException(ex);
    }
}
 
开发者ID:dkmfbk,项目名称:knowledgestore,代码行数:18,代码来源:SparqlHelper.java

示例15: meet

import org.openrdf.query.algebra.TupleExpr; //导入依赖的package包/类
@Override
public void meet(Join node) {

    filterList = Lists.newArrayList();
    
    List<TupleExpr> args = Lists.newArrayList();
    args = getJoinArgs(node, args);
    List<List<TupleExpr>> argPerms = Lists.newArrayList(Collections2.permutations(args));
    joinArgs.put(node, argPerms);
    filterArgs.put(node, filterList);

    for (TupleExpr te : args) {
        if (!(te instanceof StatementPattern) && !(te instanceof ExternalTupleSet)) {
            te.visit(this);
        }
    }

}
 
开发者ID:apache,项目名称:incubator-rya,代码行数:19,代码来源:TupleReArranger.java


注:本文中的org.openrdf.query.algebra.TupleExpr类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。