Search in sources :

Example 1 with TriplePath

use of org.apache.jena.sparql.core.TriplePath in project jena by apache.

the class ElementTransformSubst method transform.

private TriplePath transform(TriplePath path) {
    Node s = path.getSubject();
    Node s1 = transform(s);
    Node o = path.getObject();
    Node o1 = transform(o);
    if (path.isTriple()) {
        Node p = path.getPredicate();
        Node p1 = transform(p);
        if (s == s1 && p == p1 && o == o1)
            return path;
        return new TriplePath(Triple.create(s1, p1, o1));
    }
    if (s == s1 && o == o1)
        return path;
    return new TriplePath(s1, path.getPath(), o1);
}
Also used : Node(org.apache.jena.graph.Node) TriplePath(org.apache.jena.sparql.core.TriplePath)

Example 2 with TriplePath

use of org.apache.jena.sparql.core.TriplePath in project jena by apache.

the class PathLib method execTriplePath.

public static QueryIterator execTriplePath(Binding binding, TriplePath triplePath, ExecutionContext execCxt) {
    if (triplePath.isTriple()) {
        // Fake it. This happens only for API constructed situations.
        Path path = new P_Link(triplePath.getPredicate());
        triplePath = new TriplePath(triplePath.getSubject(), path, triplePath.getObject());
    }
    return execTriplePath(binding, triplePath.getSubject(), triplePath.getPath(), triplePath.getObject(), execCxt);
}
Also used : TriplePath(org.apache.jena.sparql.core.TriplePath) OpPath(org.apache.jena.sparql.algebra.op.OpPath) TriplePath(org.apache.jena.sparql.core.TriplePath)

Example 3 with TriplePath

use of org.apache.jena.sparql.core.TriplePath in project jena by apache.

the class WhereProcessor method list.

/**
	 * Create a list node from a list of objects as per RDF Collections.
	 * 
	 * http://www.w3.org/TR/2013/REC-sparql11-query-20130321/#collections
	 * 
	 * @param objs
	 *            the list of objects for the list.
	 * @return the first blank node in the list.
	 */
public Node list(Object... objs) {
    Node retval = NodeFactory.createBlankNode();
    Node lastObject = retval;
    for (int i = 0; i < objs.length; i++) {
        Node n = AbstractQueryBuilder.makeNode(objs[i], prefixHandler.getPrefixes());
        addWhere(new TriplePath(new Triple(lastObject, RDF.first.asNode(), n)));
        if (i + 1 < objs.length) {
            Node nextObject = NodeFactory.createBlankNode();
            addWhere(new TriplePath(new Triple(lastObject, RDF.rest.asNode(), nextObject)));
            lastObject = nextObject;
        } else {
            addWhere(new TriplePath(new Triple(lastObject, RDF.rest.asNode(), RDF.nil.asNode())));
        }
    }
    return retval;
}
Also used : Triple(org.apache.jena.graph.Triple) Node(org.apache.jena.graph.Node) TriplePath(org.apache.jena.sparql.core.TriplePath)

Example 4 with TriplePath

use of org.apache.jena.sparql.core.TriplePath in project jena by apache.

the class AbstractRewriter method rewrite.

/**
	 * Rewrite a triple path.
	 * @param t The triple path to rewrite.
	 * @return the triple path after rewriting.
	 */
protected final TriplePath rewrite(TriplePath t) {
    if (t.getPath() == null) {
        return new TriplePath(new Triple(changeNode(t.getSubject()), changeNode(t.getPredicate()), changeNode(t.getObject())));
    } else {
        PathRewriter transform = new PathRewriter(values);
        t.getPath().visit(transform);
        return new TriplePath(changeNode(t.getSubject()), transform.getResult(), changeNode(t.getObject()));
    }
}
Also used : Triple(org.apache.jena.graph.Triple) TriplePath(org.apache.jena.sparql.core.TriplePath)

Example 5 with TriplePath

use of org.apache.jena.sparql.core.TriplePath in project jena by apache.

the class WhereClauseTest method testAddOptionalTriplePath.

@ContractTest
public void testAddOptionalTriplePath() {
    WhereClause<?> whereClause = getProducer().newInstance();
    PrefixMapping pmap = new PrefixMappingImpl();
    pmap.setNsPrefix("ts", "urn:test:");
    Path path = PathParser.parse("ts:two/ts:dos", pmap);
    AbstractQueryBuilder<?> builder = whereClause.addOptional(new TriplePath(NodeFactory.createURI("one"), path, NodeFactory.createURI("three")));
    assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE + OPEN_CURLY + uri("one") + SPACE + uri("urn:test:two") + "/" + uri("urn:test:dos") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY, builder.buildString());
}
Also used : TriplePath(org.apache.jena.sparql.core.TriplePath) Path(org.apache.jena.sparql.path.Path) PrefixMapping(org.apache.jena.shared.PrefixMapping) TriplePath(org.apache.jena.sparql.core.TriplePath) PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl) ContractTest(org.xenei.junit.contract.ContractTest)

Aggregations

TriplePath (org.apache.jena.sparql.core.TriplePath)33 Triple (org.apache.jena.graph.Triple)22 Test (org.junit.Test)18 Node (org.apache.jena.graph.Node)10 WhereHandler (org.apache.jena.arq.querybuilder.handlers.WhereHandler)4 Query (org.apache.jena.query.Query)4 Path (org.apache.jena.sparql.path.Path)4 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)3 PrefixMapping (org.apache.jena.shared.PrefixMapping)3 PrefixMappingImpl (org.apache.jena.shared.impl.PrefixMappingImpl)3 Var (org.apache.jena.sparql.core.Var)3 HashMap (java.util.HashMap)2 Op (org.apache.jena.sparql.algebra.Op)2 OpPath (org.apache.jena.sparql.algebra.op.OpPath)2 BasicPattern (org.apache.jena.sparql.core.BasicPattern)2 ContractTest (org.xenei.junit.contract.ContractTest)2 FrontsTriple (org.apache.jena.graph.FrontsTriple)1 PathBlock (org.apache.jena.sparql.core.PathBlock)1 ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)1