Java Code Examples for org.apache.jena.sparql.expr.NodeValue#makeBoolean()

The following examples show how to use org.apache.jena.sparql.expr.NodeValue#makeBoolean() . 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: SHACLSPARQLARQFunction.java    From shacl with Apache License 2.0 6 votes vote down vote up
@Override
   public NodeValue executeBody(Dataset dataset, Model defaultModel, QuerySolution bindings) {
    try( QueryExecution qexec = createQueryExecution(dataset, defaultModel, bindings) ) {
        if(arqQuery.isAskType()) {
            boolean result = qexec.execAsk();
            return NodeValue.makeBoolean(result);
        }
        else {
            ResultSet rs = qexec.execSelect();
            if(rs.hasNext()) {
                QuerySolution s = rs.nextSolution();
                List<String> resultVars = rs.getResultVars();
                String varName = resultVars.get(0);
                RDFNode resultNode = s.get(varName);
                if(resultNode != null) {
                    return NodeValue.makeNode(resultNode.asNode());
                }
            }
            throw new ExprEvalException("Empty result set for SHACL function");
        }
    }
}
 
Example 2
Source File: IsValidForDatatypeFunction.java    From shacl with Apache License 2.0 6 votes vote down vote up
@Override
protected NodeValue exec(Node literalNode, Node datatypeNode, FunctionEnv env) {
	
	if(literalNode == null || !literalNode.isLiteral()) {
		throw new ExprEvalException();
	}
	String lex = literalNode.getLiteralLexicalForm();
	
	if(!datatypeNode.isURI()) {
		throw new ExprEvalException();
	}
	RDFDatatype datatype = TypeMapper.getInstance().getTypeByName(datatypeNode.getURI());
	
	if(datatype == null) {
		return NodeValue.TRUE;
	}
	else {
		boolean valid = datatype.isValid(lex);
		return NodeValue.makeBoolean(valid);
	}
}
 
Example 3
Source File: IsValidLangTagFunction.java    From shacl with Apache License 2.0 5 votes vote down vote up
@Override
protected NodeValue exec(Node arg, FunctionEnv env) {
	if(arg == null || !arg.isLiteral()) {
		throw new ExprEvalException("Argument must be a (string) literal");
	}
	return NodeValue.makeBoolean(LangTag.check(arg.getLiteralLexicalForm()));
}
 
Example 4
Source File: IsInTargetOfFunction.java    From shacl with Apache License 2.0 4 votes vote down vote up
@Override
protected NodeValue exec(Node nodeNode, Node shapeNode, FunctionEnv env) {
	Model model = ModelFactory.createModelForGraph(env.getActiveGraph());
	SHShape shape = SHFactory.asShape(model.asRDFNode(shapeNode));
	return NodeValue.makeBoolean(shape.hasTargetNode(model.asRDFNode(nodeNode)));
}
 
Example 5
Source File: IsDeactivatedFunction.java    From shacl with Apache License 2.0 4 votes vote down vote up
@Override
protected NodeValue exec(Node arg1, FunctionEnv env) {
	return NodeValue.makeBoolean(env.getActiveGraph().contains(arg1, SH.deactivated.asNode(), JenaDatatypes.TRUE.asNode()));
}