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

The following examples show how to use org.openrdf.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: SubstitutionApplier.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void meet(Var var) {
	Var replacement = s.get(var);
	if (replacement == null)
		return;
	var.setName(replacement.getName());
	var.setConstant(replacement.isConstant());
	var.setValue(replacement.getValue());
}
 
Example 2
Source File: Rule.java    From quetzal with Eclipse Public License 2.0 4 votes vote down vote up
private void extractConsequent(TupleExpr constructQuery, Projection projection, Extension extension) {
	StatementPattern consequent = new StatementPattern();
	Var sub = new Var();
	Var pred = new Var();
	Var obj = new Var();
	
	HashMap<String, ValueConstant> index = new HashMap<String, ValueConstant>();
	for (ExtensionElem extElem: extension.getElements()) {
		try {
			index.put(extElem.getName(), (ValueConstant) extElem.getExpr());
		} catch (ClassCastException e) {
			e.printStackTrace();
			throw new RuntimeException("Unsupported construct query rule: \n" + constructQuery.toString());
		}
	}
	
	for (ProjectionElem elem: projection.getProjectionElemList().getElements()) {
		Var currentComponent = null;
		if (elem.getTargetName().equals("subject")) {
			currentComponent = sub;
		} else if (elem.getTargetName().equals("predicate")) {
			currentComponent = pred;
		} else if (elem.getTargetName().equals("object")) {
			currentComponent = obj;
		} else {
			throw new RuntimeException("Unsupported construct query rule: " + constructQuery.toString());
		}
		
		ValueConstant valueConstant = index.get(elem.getSourceName());
		if (valueConstant != null) {
			currentComponent.setConstant(true);
			currentComponent.setValue(valueConstant.getValue());
			currentComponent.setName(elem.getSourceName());
		} else {
			currentComponent.setConstant(false);
			currentComponent.setName(elem.getSourceName());
		}
	}
	
	consequent.setSubjectVar(sub);
	consequent.setPredicateVar(pred);
	consequent.setObjectVar(obj);

	this.consequent = consequent;
}