org.apache.jena.sparql.util.NodeFactoryExtra Java Examples

The following examples show how to use org.apache.jena.sparql.util.NodeFactoryExtra. 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: BindPlan.java    From sparql-generate with Apache License 2.0 6 votes vote down vote up
@Override
protected final Binding exec(Binding binding, Context context) {
    LOG.debug("Start " + this);
    context.set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime());
    final FunctionEnv env = new FunctionEnvBase(context);
    try {
        final NodeValue n = expr.eval(binding, env);
        if (LOG.isTraceEnabled()) {
            LOG.trace("New binding " + var + " = " + LogUtils.compress(n.asNode()));
        }
        return BindingFactory.binding(binding, var, n.asNode());
    } catch(ExprEvalException ex) {
        LOG.trace("No evaluation for " + this + " " + ex.getMessage());
        return binding;
    }
}
 
Example #2
Source File: JenaUtil.java    From shacl with Apache License 2.0 6 votes vote down vote up
private static Node invokeFunction(Resource function, ExprList args, Dataset dataset) {

		if (dataset == null) {
	        dataset = ARQFactory.get().getDataset(ModelFactory.createDefaultModel());
	    }
		
		E_Function expr = new E_Function(function.getURI(), args);
		DatasetGraph dsg = dataset.asDatasetGraph();
		Context cxt = ARQ.getContext().copy();
		cxt.set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime());
		FunctionEnv env = new ExecutionContext(cxt, dsg.getDefaultGraph(), dsg, null);
		try {
			NodeValue r = expr.eval(BindingRoot.create(), env);
			if(r != null) {
				return r.asNode();
			}
		}
		catch(ExprEvalException ex) {
		}
		return null;
	}
 
Example #3
Source File: TermFactory.java    From shacl with Apache License 2.0 6 votes vote down vote up
public JSTerm term(String str) {
       Node n;
       try {
       	n = NodeFactoryExtra.parseNode(str, pm);
       }
       catch(Exception ex) {
       	throw new IllegalArgumentException("Cannot parse node \"" + str + "\"", ex);
       }
       if(n.isURI()) {
       	return new JSNamedNode(n);
       }
       else if(n.isLiteral()) {
       	return new JSLiteral(n);
       }
       else if(n.isBlank()) {
       	return new JSBlankNode(n);
       }
       else {
       	throw new IllegalArgumentException("Unexpected node type for " + n);
       }
}
 
Example #4
Source File: Helpers.java    From tarql with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static Binding binding(List<Var> header, String... values) {
	if (header.size() != values.length) {
		throw new IllegalArgumentException(
				"header and values must have same length: " + 
						header + ", " + Arrays.toString(values));
	}
	BindingHashMap result = new BindingHashMap();
	for (int i = 0; i < header.size(); i++) {
		result.add(header.get(i), NodeFactoryExtra.parseNode(values[i]));
	}
	return result;
}
 
Example #5
Source File: TextIndexSolr5.java    From BioSolr with Apache License 2.0 4 votes vote down vote up
private Node entryToNode(String v) {
	// TEMP
	return NodeFactoryExtra.createLiteralNode(v, null, null) ;
}