/** Do a node->node conversion of a BGP - return original BGP for "no change" */ public static BasicPattern transform(NodeTransform nodeTransform, BasicPattern pattern) { BasicPattern bgp2 = new BasicPattern() ; boolean changed = false ; for ( Triple triple : pattern ) { Triple t2 = transform(nodeTransform, triple) ; bgp2.add(t2) ; if ( t2 != triple ) changed = true ; } if ( ! changed ) return pattern ; return bgp2 ; }
/** 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 equalIso(Object temp2, NodeIsomorphismMap labelMap) { if ( ! ( temp2 instanceof Template) ) return false ; Template tg2 = (Template)temp2 ; List<Triple> list1 = this.bgp.getList() ; List<Triple> list2 = tg2.bgp.getList() ; if ( list1.size() != list2.size() ) return false ; for ( int i = 0 ; i < list1.size() ; i++ ) { Triple t1 = list1.get(i) ; Triple t2 = list2.get(i) ; Utils.tripleIso(t1, t2, labelMap) ; } return true ; }
private static BasicPattern merge(BasicPattern p1, BasicPattern p2) { if ( p1 == null || p2 == null ) return null ; BasicPattern p = new BasicPattern() ; p.addAll(p1) ; p.addAll(p2) ; return p ; }
for (Triple triple : opBGP.getPattern().getList()) { OpTriple opTriple = new OpTriple(triple); List<Op> alternatives = new LinkedList<Op>(); BasicPattern p = new BasicPattern(); Op union = null; if (tripleToOp.values().size() == 1) { for (Triple t : opBGP.getPattern().getList()) { // deal with untransformed triples, adding them to a basic pattern if (!tripleToOp.containsKey(t)) { p.add(t); if (p.isEmpty()) { return union;
@Override public Op transform(OpBGP opBGP) { BasicPattern oldBasicPattern = opBGP.getPattern(); BasicPattern newBasicPattern = new BasicPattern(); Iterator<Triple> it = oldBasicPattern.iterator(); Triple triple; newBasicPattern.add(Triple.create( replaceVarByBindingValue( triple.getSubject(), binding),
@Override public int mark() { return pattern.size() ; }
@Override public void addTriple(Triple t) { pattern.add(t) ; }
public final ReorderProc reorderIndexes(BasicPattern pattern) { if (pattern.size() <= 1 ) return ReorderLib.identityProc() ; List<Triple> triples = pattern.getList() ; // Could merge into the conversion step to do the rewrite WRT a Binding. // Or done here as a second pass mutate of PatternTriples // Convert to a mutable form (that allows things like "TERM") List<PatternTriple> components = Iter.toList(Iter.map(triples, convert)) ; // Allow subclasses to get in (e.g. static reordering). components = modifyComponents(components) ; ReorderProc proc = reorder(triples, components) ; return proc ; }
/** Wrap a list of triples up as a BasicPattern. Chnaging the list, changes the BasicPattern */ public static BasicPattern wrap(List<Triple> triples) { return new BasicPattern(triples) ; }
public boolean isEmpty() { return pattern.isEmpty() ; }
public Iterator<Triple> patternElts() { return pattern.iterator(); }
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 ( ! Iso.tripleIso(t1, t2, isoMap) ) return false ; } return true ; }
@Override public int hashCode() { int calcHashCode = OpBase.HashBasicGraphPattern ; calcHashCode ^= pattern.hashCode() ; return calcHashCode ; }
@Override public boolean equalTo(Element el2, NodeIsomorphismMap isoMap) { if ( ! ( el2 instanceof ElementTriplesBlock) ) return false ; ElementTriplesBlock eg2 = (ElementTriplesBlock)el2 ; return this.pattern.equiv(eg2.pattern, isoMap) ; }
@Override public Op transform(OpBGP opBGP) { BasicPattern oldBasicPattern = opBGP.getPattern(); BasicPattern newBasicPattern = new BasicPattern(); Iterator<Triple> it = oldBasicPattern.iterator(); Triple triple; newBasicPattern.add(Triple.create( replaceVarByQuadrupleValue( triple.getSubject(), vars,
public boolean isEmpty() { return triples.size() == 0 ; }