Java Code Examples for org.eclipse.rdf4j.query.algebra.BindingSetAssignment#setBindingNames()

The following examples show how to use org.eclipse.rdf4j.query.algebra.BindingSetAssignment#setBindingNames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LuceneSailConnection.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Evaluate the given Lucene queries, generate bindings from the query result, add the bindings to the query tree,
 * and remove the Lucene queries from the given query tree.
 *
 * @param queries
 * @throws SailException
 */
private void evaluateLuceneQueries(Collection<SearchQueryEvaluator> queries) throws SailException {
	// TODO: optimize lucene queries here
	// - if they refer to the same subject, merge them into one lucene query
	// - multiple different property constraints can be put into the lucene
	// query string (escape colons here)

	if (closed.get()) {
		throw new SailException("Sail has been closed already");
	}

	// evaluate queries, generate binding sets, and remove queries
	for (SearchQueryEvaluator query : queries) {
		// evaluate the Lucene query and generate bindings
		final Collection<BindingSet> bindingSets = luceneIndex.evaluate(query);

		final BindingSetAssignment bsa = new BindingSetAssignment();

		// found something?
		if (bindingSets != null && !bindingSets.isEmpty()) {
			bsa.setBindingSets(bindingSets);
			if (bindingSets instanceof BindingSetCollection) {
				bsa.setBindingNames(((BindingSetCollection) bindingSets).getBindingNames());
			}
		}

		query.replaceQueryPatternsWithResults(bsa);
	}
}
 
Example 2
Source File: TupleExprBuilder.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public BindingSetAssignment visit(ASTInlineData node, Object data) throws VisitorException {

	BindingSetAssignment bsa = new BindingSetAssignment();

	List<ASTVar> varNodes = node.jjtGetChildren(ASTVar.class);
	List<Var> vars = new ArrayList<>(varNodes.size());

	// preserve order in query
	Set<String> bindingNames = new LinkedHashSet<>(varNodes.size());
	for (ASTVar varNode : varNodes) {
		Var var = (Var) varNode.jjtAccept(this, data);
		vars.add(var);
		bindingNames.add(var.getName());
	}

	bsa.setBindingNames(bindingNames);

	List<ASTBindingSet> bindingNodes = node.jjtGetChildren(ASTBindingSet.class);
	List<BindingSet> bindingSets = new ArrayList<>(bindingNodes.size());

	for (ASTBindingSet bindingNode : bindingNodes) {
		BindingSet bindingSet = (BindingSet) bindingNode.jjtAccept(this, vars);
		bindingSets.add(bindingSet);
	}

	bsa.setBindingSets(bindingSets);

	graphPattern.addRequiredTE(bsa);
	return bsa;
}
 
Example 3
Source File: TupleExprBuilder.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public BindingSetAssignment visit(ASTBindingsClause node, Object data) throws VisitorException {
	BindingSetAssignment bsa = new BindingSetAssignment();

	List<ASTVar> varNodes = node.jjtGetChildren(ASTVar.class);
	List<Var> vars = new ArrayList<>(varNodes.size());

	// preserve order in query
	Set<String> bindingNames = new LinkedHashSet<>(varNodes.size());
	for (ASTVar varNode : varNodes) {
		Var var = (Var) varNode.jjtAccept(this, data);
		vars.add(var);
		bindingNames.add(var.getName());
	}

	bsa.setBindingNames(bindingNames);

	List<ASTBindingSet> bindingNodes = node.jjtGetChildren(ASTBindingSet.class);
	List<BindingSet> bindingSets = new ArrayList<>(bindingNodes.size());

	for (ASTBindingSet bindingNode : bindingNodes) {
		BindingSet bindingSet = (BindingSet) bindingNode.jjtAccept(this, vars);
		bindingSets.add(bindingSet);
	}

	bsa.setBindingSets(bindingSets);

	return bsa;
}
 
Example 4
Source File: BindingSetAssignmentBlock.java    From semagrow with Apache License 2.0 4 votes vote down vote up
public Collection<Plan> getPlans(CompilerContext context) {
    BindingSetAssignment expr = new BindingSetAssignment();
    expr.setBindingNames(bindingNames);
    expr.setBindingSets(bindingSets);
    return Collections.singleton(context.asPlan(expr));
}