@Override public void visit(ElementPathBlock e) { for (TriplePath t:e.getPattern().getList()) { addVars(t); } } @Override
protected void add(ElementPathBlock targetPathBlock, ElementPathBlock newPaths) { for (TriplePath tp:newPaths.getPattern().getList()) { targetPathBlock.addTriple(tp); } } protected void add(ElementPathBlock targetPathBlock, ElementTriplesBlock newTriples) {
public static ElementTriplesBlock toTriples(ElementPathBlock pb) { ElementTriplesBlock ret = new ElementTriplesBlock(); for (TriplePath tp :pb.getPattern().getList()) { if (tp.isTriple()) { ret.addTriple(tp.asTriple()); } else { throw new RuntimeException("Path query not supported"); } } return ret; } public static Set<String> getVars(Set<Var> vars) {
public void setQueryPattern(Element graphPattern) { if (graphPattern instanceof ElementTriplesBlock) { query.setQueryPattern((ElementTriplesBlock)graphPattern); } else if (graphPattern instanceof ElementGroup) { ElementGroup group = (ElementGroup) graphPattern; for (Element e: flatten(group)) { if (e instanceof ElementPathBlock) { ElementPathBlock epb = (ElementPathBlock) e; for (TriplePath p:epb.getPattern().getList()) { if (!p.isTriple()) { throw new IllegalArgumentException("Conjunctive query only accepts a basic graph patterns. No triple path: "+ p+"\n"+graphPattern ); } } } else if (!(e instanceof ElementTriplesBlock) && !(e instanceof ElementFilter)) { throw new IllegalArgumentException("Conjunctive query only accepts a basic graph patterns: "+ e+"\n"+graphPattern ); } } query.setQueryPattern(graphPattern); } else { throw new IllegalArgumentException("Conjunctive query only accepts a basic graph patterns: "+ graphPattern); } } public void addTriple(Triple t) {
public List<Triple> getTriples() { if (query.getQueryPattern() instanceof ElementTriplesBlock) { ElementTriplesBlock sp = (ElementTriplesBlock) query.getQueryPattern(); return sp.getPattern().getList(); } else { assert query.getQueryPattern() instanceof ElementGroup : query.getQueryPattern() ; List<Element> es = flatten(query.getQueryPattern()); List<Triple> ret = new ArrayList<Triple>(); for (Element e: es) { if (e instanceof ElementTriplesBlock) { ret.addAll(((ElementTriplesBlock) e).getPattern().getList()); } else if (e instanceof ElementPathBlock ) { ElementPathBlock epb = (ElementPathBlock) e; for (TriplePath tp: epb.getPattern().getList()) { assert tp.isTriple() : tp; ret.add(tp.asTriple()); } } } return ret; } }
ElementTriplesBlock etb = null; ElementGroup g = new ElementGroup(); for (TriplePath tp : e.getPattern().getList()) { boolean[] hasPropPaths = new boolean[]{false}; Element tpres =transform(tp, bestEffort, vargen, hasPropPaths); for (TriplePath t: ((ElementPathBlock) tpres).getPattern().getList()) { if (epb == null) { epb = new ElementPathBlock();
ElementGroup group = (ElementGroup) query.getQueryPattern(); ElementPathBlock p = (ElementPathBlock) group.getElements().get(0); for (TriplePath path : p.getPattern().getList()) { System.out.println("Path: "+path); RuleSystem rs = toRules.toRules(path, true, "Triple", "NegatedPropertySetTriple");
public void visit(ElementPathBlock arg0) { log(arg0); List<TriplePath> list = arg0.getPattern().getList(); ind.increase(); for(TriplePath path:list) {