// @SuppressWarnings("null") // @Override @Override protected ExtendedIterator<Triple> graphBaseFind(TripleMatch m) { Node s = m.getMatchSubject(); Var sVar = null; if (s == null) { sVar = Var.alloc("s"); s = sVar; } Node p = m.getMatchPredicate(); Var pVar = null; if (p == null) { pVar = Var.alloc("p"); p = pVar; } Node o = m.getMatchObject(); Var oVar = null; if (o == null) { oVar = Var.alloc("o"); o = oVar; } Triple triple = new Triple(s, p, o); // Evaluate as an algebra expression BasicPattern pattern = new BasicPattern(); pattern.add(triple); Op op = new OpBGP(pattern); // // Make remote execution object. // System.err.println("GraphSPARQLService.graphBaseFind: Unimplemented : remote service // execution") ; // //Plan plan = factory.create(op, getDataset(), BindingRoot.create(), null) ; // // QueryIterator qIter = plan.iterator() ; // List<Triple> triples = new ArrayList<Triple>() ; // // // for (; qIter.hasNext() ; ) // { // Binding b = qIter.nextBinding() ; // Node sResult = s ; // Node pResult = p ; // Node oResult = o ; // if ( sVar != null ) // sResult = b.get(sVar) ; // if ( pVar != null ) // pResult = b.get(pVar) ; // if ( oVar != null ) // oResult = b.get(oVar) ; // Triple resultTriple = new Triple(sResult, pResult, oResult) ; // if ( log.isDebugEnabled() ) // log.debug(" "+resultTriple) ; // triples.add(resultTriple) ; // } // qIter.close() ; // return WrappedIterator.createNoRemove(triples.iterator()) ; return null; }
/** * Takes a concept and adds * * @return */ public static Concept createPropertyQuery(Concept concept) { Collection<Var> vars = PatternVars.vars(concept.getElement()); List<String> varNames = VarUtils.getVarNames(vars); Var s = concept.getVar(); Generator gen = GeneratorBlacklist.create("v", varNames); Var p = Var.alloc(gen.next()); Var o = Var.alloc(gen.next()); Triple triple = new Triple(s, p, o); BasicPattern bp = new BasicPattern(); bp.add(triple); List<Element> elements; if (concept.isSubjectConcept()) { elements = new ArrayList<Element>(); } else { elements = concept.getElements(); } elements.add(new ElementTriplesBlock(bp)); Concept result = new Concept(elements, p); return result; }
@Override public Op transform(OpQuadPattern quadPattern) { Node gNode = quadPattern.getGraphNode(); Node g = substitute(gNode, binding); BasicPattern triples = new BasicPattern(); for (Triple triple : quadPattern.getBasicPattern()) { Node s = substitute(triple.getSubject(), binding); Node p = substitute(triple.getPredicate(), binding); Node o = substitute(triple.getObject(), binding); Triple t = new Triple(s, p, o); triples.add(t); } // Pure quading. // for ( Iterator iter = quadPattern.getQuads().iterator() ; // iter.hasNext() ; ) // { // Quad quad = (Quad)iter.next() ; // if ( ! quad.getGraph().equals(gNode) ) // throw new // ARQInternalErrorException("Internal error: quads block is not uniform over the graph node") // ; // Node s = substitute(quad.getSubject(), binding) ; // Node p = substitute(quad.getPredicate(), binding) ; // Node o = substitute(quad.getObject(), binding) ; // Triple t = new Triple(s, p, o) ; // triples.add(t) ; // } return new OpQuadPattern(g, triples); }
/** * Puts binding values to the appripriate places in the given BGP, and also adds indexes to * variable names. * * @param bgp * @param binding * @param index * @return */ public static BasicPattern substitute(BasicPattern bgp, Binding binding, int index) { if (isNotNeeded(binding)) return bgp; BasicPattern bgp2 = new BasicPattern(); // BGP deki tüm triple lar dolaşılıyor yerine koymak adına for (Triple triple : bgp) { // Binding listteki bindingler de UNION lanmak için dolaşılıyor. Triple t = substitute(triple, binding, index); bgp2.add(t); } return bgp2; }
@Override public boolean equalTo(Op op2, NodeIsomorphismMap labelMap) { if (!(op2 instanceof OpBGP)) return false; OpBGP bgp2 = (OpBGP) op2; return pattern.equiv(bgp2.pattern, labelMap); }
/** * Return a new basic pattern with the same triples as the input, but ordered as per the index * list of this reorder processor. */ @Override public BasicPattern reorder(BasicPattern bgp) { if (indexes.length != bgp.size()) { String str = String.format( "Expected size = %d : actual basic pattern size = %d", indexes.length, bgp.size()); Log.fatal(this, str); throw new ARQException(str); } BasicPattern bgp2 = new BasicPattern(); for (int j = 0; j < indexes.length; j++) { int idx = indexes[j]; Triple t = bgp.get(idx); bgp2.add(t); } return bgp2; }
public boolean equiv(BasicPattern other, NodeIsomorphismMap isoMap) { if (this.triples.size() != other.triples.size()) return false; for (int i = 0; i < this.triples.size(); i++) { Triple t1 = get(i); Triple t2 = other.get(i); if (!Utils.tripleIso(t1, t2, isoMap)) return false; } return true; }
@Override public int hashCode() { int calcHashCode = OpBase.HashBasicGraphPattern; calcHashCode ^= pattern.hashCode(); return calcHashCode; }
public static void addVars(Collection<Var> acc, BasicPattern pattern) { addVars(acc, pattern.getList()); }