Java Code Examples for org.eclipse.rdf4j.query.algebra.Var#setValue()

The following examples show how to use org.eclipse.rdf4j.query.algebra.Var#setValue() . 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: FilterRangeVisitor.java    From rya with Apache License 2.0 6 votes vote down vote up
@Override
public void meet(final StatementPattern node) throws Exception {
    super.meet(node);

    final Var subjectVar = node.getSubjectVar();
    final RangeValue subjRange = rangeValues.get(subjectVar);
    final Var predVar = node.getPredicateVar();
    final RangeValue predRange = rangeValues.get(predVar);
    final Var objVar = node.getObjectVar();
    final RangeValue objRange = rangeValues.get(objVar);
    if(subjRange != null) {
        subjectVar.setValue(new RangeIRI(subjRange));//Assumes no blank nodes can be ranges
    }
    if(predRange != null) {
        predVar.setValue(new RangeIRI(predRange));
    }
    if(objRange != null) {
        objVar.setValue(objRange);
    }
}
 
Example 2
Source File: QueryAlgebraUtil.java    From CostFed with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Clone the specified variable and attach bindings, moreover change name of variable
 * by appending "_varId" to it.
 * 
 * @param sb
 * @param var
 * @param varNames
 * @param bindings
 * 
 * @return
 */
protected static Var appendVarId(Var var, String varID, Set<String> varNames, BindingSet bindings) {
	Var res = var.clone();
	if (!var.hasValue()) {
		if (bindings.hasBinding(var.getName())) {
			res.setValue( bindings.getValue(var.getName()) );
		} else {
			String newName = var.getName() + "_" + varID;
			varNames.add(newName);
			res.setName(newName);
		}			
	}
	return res;
}
 
Example 3
Source File: QueryAlgebraUtil.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Clone the specified variable and attach bindings.
 *
 * @param var
 * @param varNames
 * @param bindings
 *
 * @return the variable
 *
 */
protected static Var appendVar(Var var, Set<String> varNames, BindingSet bindings) {
	Var res = var.clone();
	if (!var.hasValue()) {
		if (bindings.hasBinding(var.getName())) {
			res.setValue(bindings.getValue(var.getName()));
		} else {
			varNames.add(var.getName());
		}
	}
	return res;
}
 
Example 4
Source File: QueryAlgebraUtil.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Clone the specified variable and attach bindings, moreover change name of variable by appending "_varId" to it.
 *
 * @param var
 * @param varID
 * @param varNames
 * @param bindings
 *
 * @return the variable
 */
protected static Var appendVarId(Var var, String varID, Set<String> varNames, BindingSet bindings) {
	Var res = var.clone();
	if (!var.hasValue()) {
		if (bindings.hasBinding(var.getName())) {
			res.setValue(bindings.getValue(var.getName()));
		} else {
			String newName = var.getName() + "_" + varID;
			varNames.add(newName);
			res.setName(newName);
		}
	}
	return res;
}
 
Example 5
Source File: QueryAlgebraUtil.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void meet(Var node) throws QueryEvaluationException {
	if (node.hasValue()) {
		if (bindings.hasBinding(node.getName())) {
			node.setValue(bindings.getValue(node.getName()));
		}
	} else {
		freeVars.add(node.getName());
	}
	super.meet(node);
}
 
Example 6
Source File: ConstantOptimizer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Applies generally applicable optimizations to the supplied query: variable assignments are inlined.
 */
@Override
public void optimize(TupleExpr tupleExpr, Dataset dataset, BindingSet bindings) {
	ConstantVisitor visitor = new ConstantVisitor();
	tupleExpr.visit(visitor);
	Set<String> varsBefore = visitor.varNames;

	VarNameCollector varCollector = new VarNameCollector();
	tupleExpr.visit(varCollector);
	Set<String> varsAfter = varCollector.varNames;

	if (varsAfter.size() < varsBefore.size()) {
		varsBefore.removeAll(varsAfter);
		for (ProjectionElemList projElems : visitor.projElemLists) {
			for (ProjectionElem projElem : projElems.getElements()) {
				String name = projElem.getSourceName();
				if (varsBefore.contains(name)) {
					UnaryTupleOperator proj = (UnaryTupleOperator) projElems.getParentNode();
					Extension ext = new Extension(proj.getArg());
					proj.setArg(ext);
					Var lostVar = new Var(name);
					Value value = bindings.getValue(name);
					if (value != null) {
						lostVar.setValue(value);
					}
					ext.addElement(new ExtensionElem(lostVar, name));
				}
			}
		}
	}
}
 
Example 7
Source File: BindingAssigner.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void meet(Var var) {
	if (!var.hasValue() && bindings.hasBinding(var.getName())) {
		Value value = bindings.getValue(var.getName());
		var.setValue(value);
	}
}
 
Example 8
Source File: TupleExprs.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Creates an (anonymous) Var representing a constant value. The variable name will be derived from the actual value
 * to guarantee uniqueness.
 *
 * @param value
 * @return an (anonymous) Var representing a constant value.
 */
public static Var createConstVar(Value value) {
	String varName = getConstVarName(value);
	Var var = new Var(varName);
	var.setConstant(true);
	var.setAnonymous(true);
	var.setValue(value);
	return var;
}
 
Example 9
Source File: QueryVariableNormalizer.java    From rya with Apache License 2.0 5 votes vote down vote up
public void meet(Var var) {
    if (!var.isConstant() && hMap.containsKey(var.getName())) {
        String val = hMap.get(var.getName());
        if (VarNameUtils.isConstant(val)) {
           var.setName(val);
           var.setValue(valMap.get(val));
           var.setAnonymous(true); //TODO this might be a hack -- when are Vars not anonymous?
        } else {
            var.setName(val);
        }
    }
}
 
Example 10
Source File: SameTermFilterOptimizer.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void meet(Var var) {
	if (var.getName().equals(varName)) {
		var.setValue(value);
	}
}
 
Example 11
Source File: QueryModelBuilder.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private Var createConstantVar(Value value) {
	Var var = new Var("-const-" + constantVarID++);
	var.setAnonymous(true);
	var.setValue(value);
	return var;
}
 
Example 12
Source File: QueryAlgebraUtil.java    From CostFed with GNU Affero General Public License v3.0 3 votes vote down vote up
/**
 * Clone the specified variable and attach bindings.
 *  
 * @param sb
 * @param var
 * @param varNames
 * @param bindings
 * 
 * @return

 */
protected static Var appendVar(Var var, Set<String> varNames, BindingSet bindings) {
	Var res = var.clone();
	if (!var.hasValue()) {
		if (bindings.hasBinding(var.getName()))
			res.setValue( bindings.getValue(var.getName()) );
		else 
			varNames.add(var.getName());			
	}
	return res;
}