public boolean equiv(PathBlock other, NodeIsomorphismMap isoMap) { if ( this.triplePaths.size() != other.triplePaths.size() ) return false ; for ( int i = 0 ; i < this.triplePaths.size() ; i++ ) { TriplePath tp1 = get(i) ; TriplePath tp2 = other.get(i) ; if ( ! Iso.triplePathIso(tp1, tp2, isoMap) ) return false ; } return true ; }
@Override public int mark() { return pattern.size() ; }
@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"); }
public Element transform(ElementPathBlock el) { PathBlock before = el.getPattern(); PathBlock after = TransformDeduplicatePatterns.deduplicate(before); Element result; if(after.equals(before)) { result = el; } else { ElementPathBlock tmp = new ElementPathBlock(); tmp.getPattern().addAll(after); result = tmp; } return result; } }
public PathBlock reduce(Node start, Path path, Node finish) { PathBlock x = new PathBlock() ; reduce(x, varAlloc, start, path, finish) ; return x ; }
/** Insert into a group, skip initial empty subgroups; recombining ElementPathBlock */ private static void insertIntoGroup(ElementGroup eg, Element e) { // Skip initial empty subgroup. if ( emptyGroup(e) && eg.isEmpty() ) return ; // Empty group. if ( eg.isEmpty() ) { eg.addElement(e); return ; } Element eltTop = eg.getLast() ; if ( ! ( eltTop instanceof ElementPathBlock ) ) { // Not working on a ElementPathBlock - no need to group-of-one // when inserting ElementPathBlock. e = unwrapGroupOfOnePathBlock(e) ; eg.addElement(e); return ; } if ( ! ( e instanceof ElementPathBlock ) ) { eg.addElement(e); return ; } // Combine. ElementPathBlock currentPathBlock = (ElementPathBlock)eltTop ; ElementPathBlock newPathBlock = (ElementPathBlock)e ; currentPathBlock.getPattern().addAll(newPathBlock.getPattern()); }
@Override public void addTriplePath(TriplePath tPath) { pattern.add(tPath) ; }
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); } }
public Element transform(ElementPathBlock el) { PathBlock before = el.getPattern(); PathBlock after = TransformDeduplicatePatterns.deduplicate(before); Element result; if(after.equals(before)) { result = el; } else { ElementPathBlock tmp = new ElementPathBlock(); tmp.getPattern().addAll(after); result = tmp; } return result; } }
/** Simplify : turns constructs in simple triples and simpler TriplePaths where possible */ public PathBlock reduce(PathBlock pathBlock) { PathBlock x = new PathBlock() ; // No context during algebra generation time. // VarAlloc varAlloc = VarAlloc.get(context, ARQConstants.sysVarAllocNamed) ; // if ( varAlloc == null ) // // Panic // throw new ARQInternalErrorException("No execution-scope allocator for variables") ; // Translate one into another. reduce(x, pathBlock, varAlloc) ; return x ; }
@Override public void addTriplePath(int index, TriplePath tPath) { pattern.add(index, tPath) ; }
/** * 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); }
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); } }
protected Op compilePathBlock(PathBlock pathBlock) { // Empty path block : the parser does not generate this case. if ( pathBlock.size() == 0 ) return OpTable.unit() ; // Always turns the most basic paths to triples. return PathLib.pathToTriples(pathBlock) ; }
public PathBlock reduce(TriplePath triplePath) { PathBlock x = new PathBlock() ; reduce(x, varAlloc, triplePath.getSubject(), triplePath.getPath(), triplePath.getObject()) ; return x ; }
public void addTriple(TriplePath tp) { pattern.add(tp) ; }