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);
}
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);
}
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;
}
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()));
}
}
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());
}
Aggregations