Java Code Examples for com.hp.hpl.jena.sparql.core.Var#asNode()

The following examples show how to use com.hp.hpl.jena.sparql.core.Var#asNode() . 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: IsATestEvaluator.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Override
public Expr evaluate(NodeTest nodeTest, ElementGroup elementGroup, Var var, LDPathEvaluatorConfiguration evaluatorConfiguration) {
    IsATest isATest = (IsATest) nodeTest;
    Var tmpVar = Var.alloc(Var.alloc(VarIDGenerator.createID()));
    elementGroup.addTriplePattern(new Triple(var.asNode(), RDF.type.asNode(), tmpVar.asNode()));
    return new E_Equals(new ExprVar(tmpVar.asNode()), new NodeValueNode(NodeFactory.createURI(isATest.getPathExpression(new SesameValueBackend()).replace("<", "").replace(">", "").replaceFirst("is-a ", ""))));
}
 
Example 2
Source File: PathEqualityTestEvaluator.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Override
public Expr evaluate(NodeTest nodeTest, ElementGroup elementGroup, Var var, LDPathEvaluatorConfiguration evaluatorConfiguration) {
    PathEqualityTest pathEqualityTest = (PathEqualityTest) nodeTest;
    Var tmpVar =  LDPathEvaluator.evaluate(pathEqualityTest.getPath(), elementGroup, var, evaluatorConfiguration);
    if(pathEqualityTest.getNode() instanceof org.openrdf.model.impl.LiteralImpl) {
        return new E_Equals(new ExprVar(tmpVar.asNode()), new NodeValueNode(NodeFactory.createLiteral(((LiteralImpl) pathEqualityTest.getNode()).getLabel().toString())));
    } else {
        return new E_Equals(new ExprVar(tmpVar.asNode()), new NodeValueNode(NodeFactory.createURI(pathEqualityTest.getNode().toString())));
    }
}
 
Example 3
Source File: RecursivePathSelectorEvaluator.java    From anno4j with Apache License 2.0 5 votes vote down vote up
@Override
public Var evaluate(NodeSelector nodeSelector, ElementGroup elementGroup, Var var, LDPathEvaluatorConfiguration evaluatorConfiguration) {
    RecursivePathSelector recursivePathSelector = (RecursivePathSelector) nodeSelector;

    Var id = Var.alloc(VarIDGenerator.createID());
    ElementPathBlock epb = new ElementPathBlock();
    String pathExpression = recursivePathSelector.getPathExpression(new SesameValueBackend());
    /**
     * initial pathExpression contains:
     *      (<http://www.w3.org/ns/oa#hasBody> / <http://www.example.com/schema#recursiveBodyValue>)*
     *
     * Because P_ZeroOrMore and so one, creates the same expression we have to strip the redundant chars.
     */
    String strippedPathExpression = pathExpression.substring(2, pathExpression.length() -3 );

    TriplePath triplePath = null;
    if (pathExpression.contains("*")) {
        triplePath = new TriplePath(var.asNode(), new P_ZeroOrMore1(new P_Link(NodeFactory.createURI(strippedPathExpression))), id.asNode());
    } else if (pathExpression.contains("+")) {
        triplePath = new TriplePath(var.asNode(), new P_OneOrMore1(new P_Link(NodeFactory.createURI(strippedPathExpression))), id.asNode());
    } else {
        throw new IllegalStateException("Only ZeroOrMorePath(*), OneOrMorePath(+) path selectors are currently supported.");
    }

    epb.addTriple(triplePath);
    ElementGroup group = new ElementGroup();
    group.addElement(epb);
    elementGroup.addElement(group);
    return id;
}
 
Example 4
Source File: EvalComparison.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public static void evaluate(ElementGroup elementGroup, Criteria criteria, Var variable, String resolvedConstraint) {

        if (criteria.isNaN()) {

            String constraint = "";

            // Setting the boundaries (\b) to the RegExp, according to the comparison type
            if (Comparison.EQ.equals(criteria.getComparison())) {
                constraint = "^" + resolvedConstraint + "$";
            } else if (Comparison.CONTAINS.equals(criteria.getComparison())) {
                constraint = resolvedConstraint;
            } else if (Comparison.STARTS_WITH.equals(criteria.getComparison())) {
                constraint = "^" + resolvedConstraint;
            } else if (Comparison.ENDS_WITH.equals(criteria.getComparison())) {
                constraint = resolvedConstraint + "$";
            } else {
                throw new IllegalStateException(criteria.getComparison() + " is only allowed on Numbers.");
            }

            if (!constraint.equals("")) {
                elementGroup.addElementFilter(new ElementFilter(new E_Regex(new E_Str(new ExprVar(variable.asNode())), constraint , "")));
            }
        } else {
            Expr expr;

            if (criteria.getComparison().equals(Comparison.GT)) {
                expr = new E_GreaterThan(new ExprVar(variable.asNode()), new NodeValueDouble(Double.parseDouble(resolvedConstraint)));
            } else if (criteria.getComparison().equals(Comparison.GTE)) {
                expr = new E_GreaterThanOrEqual(new ExprVar(variable.asNode()), new NodeValueDouble(Double.parseDouble(resolvedConstraint)));
            } else if (criteria.getComparison().equals(Comparison.LT)) {
                expr = new E_LessThan(new ExprVar(variable.asNode()), new NodeValueDouble(Double.parseDouble(resolvedConstraint)));
            } else if (criteria.getComparison().equals(Comparison.LTE)) {
                expr = new E_LessThanOrEqual(new ExprVar(variable.asNode()), new NodeValueDouble(Double.parseDouble(resolvedConstraint)));
            } else if (criteria.getComparison().equals(Comparison.EQ)) {
                expr = new E_Equals(new ExprVar(variable.asNode()), new ExprVar(criteria.getConstraint()));
            } else {
                throw new IllegalStateException(criteria.getComparison() + " is not allowed on Numbers.");
            }

            if(expr != null) {
                elementGroup.addElementFilter(new ElementFilter(expr));
            }
        }
    }