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