public static boolean triplePathIso(TriplePath tp1, TriplePath tp2, NodeIsomorphismMap isoMap) { if ( tp1.isTriple() ^ tp2.isTriple() ) return false ; if ( tp1.isTriple() ) return Iso.tripleIso(tp1.asTriple(), tp2.asTriple(), isoMap) ; else return Iso.nodeIso(tp1.getSubject(), tp2.getSubject(), isoMap) && Iso.nodeIso(tp1.getObject(), tp2.getObject(), isoMap) && tp1.getPath().equalTo(tp2.getPath(), isoMap) ; }
/** * Adds a triple to the where clause. * * @param t * The triple path to add * @return The Builder for chaining. */ public UpdateBuilder addWhere(Triple t) { return addWhere(new TriplePath(t)); }
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) ; }
public PathBlock reduce(TriplePath triplePath) { PathBlock x = new PathBlock() ; reduce(x, varAlloc, triplePath.getSubject(), triplePath.getPath(), triplePath.getObject()) ; return x ; }
@Override public void visit(final ElementPathBlock el) { for (Iterator<TriplePath> iterator = el.patternElts(); iterator.hasNext();) { TriplePath tp = iterator.next(); if (inOptionalClause) { optionalTriplePattern.add(tp.asTriple()); } else { if (tp.isTriple()) { triplePattern.add(tp.asTriple()); } } } }
@Override public void visit(ElementPathBlock el) { // TODO Paths not handled yet List<TriplePath> triplePaths = el.getPattern().getList(); for(TriplePath triplePath : triplePaths) { Triple triple = triplePath.asTriple(); Quad quad = new Quad(defaultGraphName, triple); quads.add(quad); } //throw new RuntimeException("Not implemented"); }
for (Iterator<TriplePath> iterator = el.patternElts(); iterator.hasNext();) { TriplePath t = iterator.next(); if (t.isTriple() && t.getPredicate().matches(RDF.type.asNode())) { subject2TypeTriples.put(t.getSubject(), t.asTriple()); if (t.isTriple() && redundantTriples.contains(t.asTriple())) { iterator.remove();
public static Element applyTransform(ElementPathBlock el, Map<Node, BinaryRelation> virtualPredicates, Generator<Var> rootVarGen) { PathBlock bgp = el.getPattern(); ElementPathBlock newPattern = new ElementPathBlock(); List<Element> elements = new ArrayList<Element>(bgp.size()); for(TriplePath tp : bgp) { if(tp.isTriple()) { Triple triple = tp.asTriple(); Generator<Var> varGen = rootVarGen.clone(); Element e = applyTransform(triple, virtualPredicates, varGen); if(e == null) { newPattern.addTriple(new TriplePath(triple)); } else { elements.add(e); } } else { logger.warn("Triple path expressions not supported"); newPattern.addTriple(tp); } } Iterable<Element> items = newPattern.isEmpty() ? elements : Iterables.concat(Collections.singleton(newPattern), elements) ; Element result = ElementUtils.createElementGroup(items); return result; }
public static void addVarsFromTriplePath(Collection<Var> acc, TriplePath tpath) { addVar(acc, tpath.getSubject()); addVar(acc, tpath.getObject()); }
final TriplePath tp = it.next(); final Var d = Var.alloc( "d" ); if ( tp.getSubject().equals( d )) { it.add( new TriplePath( new Triple( d, d, d )));
/** * Attempts to parse a given string into a Jena Path. * Throws an Exception if the string cannot be parsed. * @param string the string to parse * @param model the Model to operate on (for prefixes) * @return a Path or a Resource if this is a URI */ public static Object getJenaPath(String string, Model model) throws QueryParseException { Query query = ARQFactory.get().createQuery(model, "ASK { ?a \n" + string + "\n ?b }"); Element element = query.getQueryPattern(); if(element instanceof ElementGroup) { Element e = ((ElementGroup)element).getElements().get(0); if(e instanceof ElementPathBlock) { Path path = ((ElementPathBlock) e).getPattern().get(0).getPath(); if(path instanceof P_Link && ((P_Link)path).isForward()) { return model.asRDFNode(((P_Link)path).getNode()); } else { return path; } } else if(e instanceof ElementTriplesBlock) { return model.asRDFNode(((ElementTriplesBlock) e).getPattern().get(0).getPredicate()); } } throw new QueryParseException("Not a SPARQL 1.1 Path expression", 2, 1); }
@Override public void visit(ElementPathBlock el) { Iterator<TriplePath> triples = el.patternElts(); while (triples.hasNext()) { TriplePath triple = triples.next(); if(triple.getSubject().isVariable()) { vars.add(Var.alloc(triples.next().getSubject())); } } } });
@Override public void add(TriplePath triplePath, V targetState, V sourceState) { Multimap<Node, TriplePath> nodeToPath = getOrCreateStateInfo(targetState); Node node = triplePath.getObject(); nodeToPath.put(node, triplePath); }
public static void collectQuads(ElementPathBlock element, Context context, List<Quad> result) { Node graphNode = context.getGraphNode(); for(TriplePath triplePath : element.getPattern().getList()) { Triple triple = triplePath.asTriple(); if(triple == null) { logger.warn("Omitted non-simple triple"); } Quad quad = new Quad(graphNode, triple); result.add(quad); } }
@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 ; }
@Override public void visit(OpPath opPath) { addVar(subjAcc, opPath.getTriplePath().getSubject()) ; addVar(objAcc, opPath.getTriplePath().getObject()) ; }
/** * Attempts to parse a given string into a Jena Path. * Throws an Exception if the string cannot be parsed. * @param string the string to parse * @param model the Model to operate on (for prefixes) * @return a Path or a Resource if this is a URI */ public static Object getJenaPath(String string, Model model) throws QueryParseException { Query query = ARQFactory.get().createQuery(model, "ASK { ?a \n" + string + "\n ?b }"); Element element = query.getQueryPattern(); if(element instanceof ElementGroup) { Element e = ((ElementGroup)element).getElements().get(0); if(e instanceof ElementPathBlock) { Path path = ((ElementPathBlock) e).getPattern().get(0).getPath(); if(path instanceof P_Link && ((P_Link)path).isForward()) { return model.asRDFNode(((P_Link)path).getNode()); } else { return path; } } else if(e instanceof ElementTriplesBlock) { return model.asRDFNode(((ElementTriplesBlock) e).getPattern().get(0).getPredicate()); } } throw new QueryParseException("Not a SPARQL 1.1 Path expression", 2, 1); }
@Override public boolean equals(Object other) { if ( this == other) return true ; if ( ! ( other instanceof TriplePath) ) return false ; TriplePath tp = (TriplePath)other ; // True if one is true and one is false if ( tp.isTriple() ^ this.isTriple() ) return false ; if ( isTriple() ) return asTriple().equals(tp.asTriple()) ; else return subject.equals(tp.subject) && object.equals(tp.object) && path.equals(tp.path) ; }
public static void collectQuads(ElementPathBlock element, Context context, List<Quad> result) { Node graphNode = context.getGraphNode(); for(TriplePath triplePath : element.getPattern().getList()) { Triple triple = triplePath.asTriple(); if(triple == null) { logger.warn("Omitted non-simple triple"); } Quad quad = new Quad(graphNode, triple); result.add(quad); } }