Search in sources :

Example 26 with TriplePath

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

the class BuilderPath method buildTriplePath.

public static TriplePath buildTriplePath(ItemList list) {
    if (list.size() != 3 && list.size() != 4)
        BuilderLib.broken(list, "Not a triple path", list);
    if (list.size() == 4) {
        if (!list.get(0).isSymbol(Tags.tagTriplePath))
            BuilderLib.broken(list, "Not a triple path");
        list = list.cdr();
    }
    Node s = BuilderNode.buildNode(list.get(0));
    Path p = BuilderPath.buildPath(list.get(1));
    Node o = BuilderNode.buildNode(list.get(2));
    return new TriplePath(s, p, o);
}
Also used : TriplePath(org.apache.jena.sparql.core.TriplePath) Node(org.apache.jena.graph.Node) TriplePath(org.apache.jena.sparql.core.TriplePath)

Example 27 with TriplePath

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

the class NodeTransformOp method transform.

@Override
public Op transform(OpPath opPath) {
    TriplePath tp = opPath.getTriplePath();
    Node s = tp.getSubject();
    Node s1 = transform.apply(s);
    Node o = tp.getObject();
    Node o1 = transform.apply(o);
    if (s1 == s && o1 == o)
        // No change.
        return super.transform(opPath);
    Path path = tp.getPath();
    TriplePath tp2;
    if (path != null)
        tp2 = new TriplePath(s1, path, o1);
    else {
        Triple t = new Triple(s1, tp.getPredicate(), o1);
        tp2 = new TriplePath(t);
    }
    return new OpPath(tp2);
}
Also used : TriplePath(org.apache.jena.sparql.core.TriplePath) Path(org.apache.jena.sparql.path.Path) Triple(org.apache.jena.graph.Triple) Node(org.apache.jena.graph.Node) TriplePath(org.apache.jena.sparql.core.TriplePath)

Example 28 with TriplePath

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

the class WhereClauseTest method testAddUnion.

@ContractTest
public void testAddUnion() {
    SelectBuilder sb = new SelectBuilder();
    sb.addPrefix("pfx", "uri").addVar("?x").addWhere("<one>", "<two>", "three");
    WhereClause<?> whereClause = getProducer().newInstance();
    whereClause.getWhereHandler().addWhere(new TriplePath(Triple.ANY));
    AbstractQueryBuilder<?> builder = whereClause.addUnion(sb);
    String str = builder.buildString();
    assertContainsRegex(PREFIX + "pfx:" + SPACE + uri("uri") + SPACE, str);
    assertContainsRegex(WHERE + OPEN_CURLY + OPEN_CURLY + "ANY" + SPACE + "ANY" + SPACE + "ANY" + CLOSE_CURLY + SPACE + UNION + OPEN_CURLY + SELECT + var("x") + SPACE + WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + quote("three") + presentStringType() + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, str);
}
Also used : TriplePath(org.apache.jena.sparql.core.TriplePath) SelectBuilder(org.apache.jena.arq.querybuilder.SelectBuilder) ContractTest(org.xenei.junit.contract.ContractTest)

Example 29 with TriplePath

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

the class TransformPathFlatternStd method transform.

@Override
public Op transform(OpPath opPath) {
    TriplePath tp = opPath.getTriplePath();
    Op op = transformPath(opPath, tp.getSubject(), tp.getPath(), tp.getObject());
    // And combine adjacent triple patterns.
    return op;
}
Also used : Op(org.apache.jena.sparql.algebra.Op) TriplePath(org.apache.jena.sparql.core.TriplePath)

Example 30 with TriplePath

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

the class WhereHandler 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], query.getPrefixMapping());
        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)

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