@Override public boolean test(TripleID t) { if(varIsSO[0] && t.getSubject()>numSharedSO) { return false; } if(varIsSO[2] && t.getObject()>numSharedSO) { return false; } return true; } });
@Override public Integer next() { switch (position) { case SUBJECT: return iterator.next().getSubject(); case PREDICATE: return iterator.next().getPredicate(); case OBJECT: return iterator.next().getObject(); default: // Never reached return 0; } }
public void assign(TripleID replacement) { subject = replacement.getSubject(); object = replacement.getObject(); predicate = replacement.getPredicate(); }
@Override public int compare(TripleID o1, TripleID o2) { int result = o1.getSubject() - o2.getSubject(); if (result == 0) { result = o1.getPredicate() - o2.getPredicate(); if (result == 0) { // The third component is different? return o1.getObject() - o2.getObject(); } else { // the second component is different return result; } } else { // the first component is different return result; } }
@Override public TripleString next() { if(!child.hasNext()) { fetchBlock(); } TripleID triple = child.next(); if(s.length()!=0) { lastSstr = s; } else if(triple.getSubject()!=lastSid) { lastSid = triple.getSubject(); lastSstr = mapSubject.get(lastSid); } if(p.length()!=0) { lastPstr = p; } else if(triple.getPredicate()!=lastPid) { lastPid = triple.getPredicate(); lastPstr = mapPredicate.get(lastPid); } if(o.length()!=0) { lastOstr = o; } else if(triple.getObject()!=lastOid) { lastOid = triple.getObject(); lastOstr = mapObject.get(lastOid); } return new TripleString(lastSstr, lastPstr, lastOstr); }
/** * Check whether this triple matches a pattern of TripleID. 0 acts as a wildcard * * @param pattern * The pattern to match against * @return boolean */ public boolean match(TripleID pattern) { // get the components of the pattern int subjectPattern = pattern.getSubject(); int predicatePattern = pattern.getPredicate(); int objectPattern = pattern.getObject(); /* Remember that 0 acts as a wildcard */ if (subjectPattern == 0 || this.subject == subjectPattern) { if (predicatePattern == 0 || this.predicate == predicatePattern) { if (objectPattern == 0 || this.object == objectPattern) { return true; } } } return false; }
BitmapTriplesIteratorZ(BitmapTriples triples, TripleID pattern) { this.triples = triples; this.pattern = new TripleID(pattern); this.returnTriple = new TripleID(); TripleOrderConvert.swapComponentOrder(this.pattern, TripleComponentOrder.SPO, triples.order); patZ = this.pattern.getObject(); if(patZ==0) { throw new IllegalArgumentException("This structure is not meant to process this pattern"); } adjY = triples.adjY; adjZ = triples.adjZ; goToStart(); }
/** * Converts a TripleID to a TripleString using a dictionary. * * @param tripleID * The Triple to convert from * @return TripleString */ public static TripleString tripleIDtoTripleString(Dictionary dict, TripleID tripleID) { return new TripleString( dict.idToString(tripleID.getSubject(), TripleComponentRole.SUBJECT).toString(), dict.idToString(tripleID.getPredicate(), TripleComponentRole.PREDICATE).toString(), dict.idToString(tripleID.getObject(), TripleComponentRole.OBJECT).toString() ); }
private void fetchBlock() { reset(); int [] arrSubjects = new int[blockSize]; int [] arrPredicates = new int[blockSize]; int [] arrObjects = new int[blockSize]; int count=0; for(int i=0;i<blockSize && iterator.hasNext();i++) { TripleID t = new TripleID(iterator.next()); triples.add(t); if(s.length()==0) arrSubjects[count] = t.getSubject(); if(p.length()==0) arrPredicates[count] = t.getPredicate(); if(o.length()==0) arrObjects[count] = t.getObject(); count++; } if(s.length()==0) fill(arrSubjects, count, mapSubject, TripleComponentRole.SUBJECT); if(p.length()==0) fill(arrPredicates, count, mapPredicate, TripleComponentRole.PREDICATE); if(o.length()==0) fill(arrObjects, count, mapObject, TripleComponentRole.OBJECT); this.child = triples.iterator(); }
@Override public TripleString next() { TripleID triple = iterator.next(); // convert the tripleID to TripleString if(s.length()!=0) { lastSstr = s; } else if(triple.getSubject()!=lastSid) { lastSid = triple.getSubject(); lastSstr = dictionary.idToString(lastSid, TripleComponentRole.SUBJECT); } if(p.length()!=0) { lastPstr = p; } else if(triple.getPredicate()!=lastPid) { lastPstr = dictionary.idToString(triple.getPredicate(), TripleComponentRole.PREDICATE); lastPid = triple.getPredicate(); } if(o.length()!=0) { lastOstr = o; } else if(triple.getObject()!=lastOid) { lastOstr = dictionary.idToString(triple.getObject(), TripleComponentRole.OBJECT); lastOid = triple.getObject(); } return new TripleString(lastSstr, lastPstr, lastOstr); // return DictionaryUtil.tripleIDtoTripleString(dictionary, triple); }
@Override public void save(OutputStream output, ControlInfo controlInformation, ProgressListener listener) throws IOException { controlInformation.clear(); controlInformation.setInt("numTriples", numValidTriples); controlInformation.setFormat(HDTVocabulary.TRIPLES_TYPE_TRIPLESLIST); controlInformation.setInt("order", order.ordinal()); controlInformation.save(output); DataOutputStream dout = new DataOutputStream(output); int count = 0; for (TripleID triple : arrayOfTriples) { if(triple.isValid()) { dout.writeInt(triple.getSubject()); dout.writeInt(triple.getPredicate()); dout.writeInt(triple.getObject()); ListenerUtil.notifyCond(listener, "Saving TriplesList", count, arrayOfTriples.size()); } count++; } }
y2 = o2.getPredicate(); z1 = o1.getObject(); z2 = o2.getObject(); break; case SOP: x2 = o2.getSubject(); y1 = o1.getObject(); y2 = o2.getObject(); y2 = o2.getSubject(); z1 = o1.getObject(); z2 = o2.getObject(); break; case POS: y1 = o1.getObject(); y2 = o2.getObject(); x1 = o1.getObject(); x2 = o2.getObject(); x1 = o1.getObject(); x2 = o2.getObject();
public BitmapTriplesIteratorZFOQ(BitmapTriples triples, TripleID pattern) { this.triples = triples; this.pattern = new TripleID(pattern); this.returnTriple = new TripleID(); TripleOrderConvert.swapComponentOrder(this.pattern, TripleComponentOrder.SPO, triples.order); patZ = this.pattern.getObject(); if(patZ==0 && (patY!=0 || this.pattern.getSubject()!=0)) { throw new IllegalArgumentException("This structure is not meant to process this pattern"); } patY = this.pattern.getPredicate(); adjY = triples.adjY; adjIndex = triples.adjIndex; calculateRange(); goToStart(); }
public void newSearch(TripleID pattern) { this.pattern.assign(pattern); TripleOrderConvert.swapComponentOrder(this.pattern, TripleComponentOrder.SPO, triples.order); patX = this.pattern.getSubject(); patY = this.pattern.getPredicate(); patZ = this.pattern.getObject(); adjY = triples.adjY; adjZ = triples.adjZ; // ((BitSequence375)triples.bitmapZ).dump(); findRange(); goToStart(); }
@Override public void load(Triples triples, ProgressListener listener) { this.clear(); IteratorTripleID it = triples.searchAll(); while(it.hasNext()) { TripleID triple = it.next(); this.insert(triple.getSubject(), triple.getPredicate(), triple.getObject()); } sorted = false; }
@Override public Triple next() { TripleID triple = iterator.next(); Triple t = new Triple( nodeDictionary.getNode(triple.getSubject(), TripleComponentRole.SUBJECT), nodeDictionary.getNode(triple.getPredicate(), TripleComponentRole.PREDICATE), nodeDictionary.getNode(triple.getObject(), TripleComponentRole.OBJECT) ); return t; }
@Override public BindingHDTId apply(TripleID triple) { BindingHDTId output = new BindingHDTId(input) ; if (var[0] != null && !insert(var[0], new HDTId(triple.getSubject(), TripleComponentRole.SUBJECT, dictionary), output)) { return null; } if (var[1] != null && !insert(var[1], new HDTId(triple.getPredicate(), TripleComponentRole.PREDICATE, dictionary), output)) { return null; } if (var[2] != null && !insert(var[2], new HDTId(triple.getObject(), TripleComponentRole.OBJECT, dictionary), output)) { return null; } return output; } };
public static void swapComponentOrder(TripleID triple, TripleComponentOrder from, TripleComponentOrder to) { if(from==to) { return; } if(from==TripleComponentOrder.Unknown || to==TripleComponentOrder.Unknown) { throw new IllegalArgumentException("Cannot swap Unknown Orders"); } boolean swap1 = swap1tab[from.ordinal() - 1][to.ordinal() - 1]; boolean swap2 = swap2tab[from.ordinal() - 1][to.ordinal() - 1]; boolean swap3 = swap3tab[from.ordinal() - 1][to.ordinal() - 1]; if(swap1){ int tmp = triple.getSubject(); triple.setSubject(triple.getPredicate()); triple.setPredicate(tmp); } if(swap2){ int tmp = triple.getSubject(); triple.setSubject(triple.getObject()); triple.setObject(tmp); } if(swap3){ int tmp = triple.getPredicate(); triple.setPredicate(triple.getObject()); triple.setObject(tmp); } } }
mapSubj.getNewID(triple.getSubject()-1), mapPred.getNewID(triple.getPredicate()-1), mapObj.getNewID(triple.getObject()-1) );
z = triple.getObject(); if(x==0 || y==0 || z==0) { throw new IllegalFormatException("None of the components of a triple can be null");