logger.debug("Dataset {} is being parsed. Estimate number of triples {}", datasetLocation, iter.estimatedNumResults()); while (iter.hasNext()) { TripleString triple = iter.next(); totalQuadsProcessed++;
public void execute() throws Exception { PrintStream out = null; if (rdfOutput.equals("stdout")){ out = System.out; } else { out = new PrintStream(rdfOutput, "UTF-8"); } HDT hdt=HDTManager.mapHDT(hdtInput, this); try { IteratorTripleString it = hdt.search("","",""); StringBuilder build = new StringBuilder(1024); while(it.hasNext()) { TripleString triple = it.next(); build.delete(0, build.length()); triple.dumpNtriple(build); out.print(build); } if(!rdfOutput.equals("stdout")) { out.close(); } } finally { if(hdt!=null) hdt.close(); } }
protected static void iterate(HDT hdt, CharSequence subject, CharSequence predicate, CharSequence object) throws NotFoundException { StopWatch iterateTime = new StopWatch(); int count = 0; subject = subject.length()==1 && subject.charAt(0)=='?' ? "" : subject; predicate = predicate.length()==1 && predicate.charAt(0)=='?' ? "" : predicate; object = object.length()==1 && object.charAt(0)=='?' ? "" : object; // Iterate over triples as Strings IteratorTripleString it = hdt.search(subject,predicate,object); count = 0; while(it.hasNext()) { TripleString triple = it.next(); System.out.println(triple); count++; } // Iterate over triples only as IDs // TripleID patternID = DictionaryUtil.tripleStringtoTripleID(hdt.getDictionary(), new TripleString(subject, predicate, object)); // IteratorTripleID it2 = hdt.getTriples().search(patternID); // while(it2.hasNext()) { // TripleID triple = it2.next(); // System.out.println(triple); // count++; // } System.out.println("Iterated "+ count + " triples in "+iterateTime.stopAndShow()); }
public static String getProperty(Header header, String subject, String predicate) throws NotFoundException { IteratorTripleString it = header.search(cleanURI(subject), cleanURI(predicate), ""); if(it.hasNext()) { TripleString ts = it.next(); return ts.getObject().toString(); } throw new NotFoundException(); }
@Override public void save(OutputStream output, ControlInfo ci, ProgressListener listener) throws IOException { // Dump header into an array to calculate size and have it prepared. ByteArrayOutputStream headerData = new ByteArrayOutputStream(); IteratorTripleString iterator = this.search("", "", ""); while(iterator.hasNext()) { TripleString next = iterator.next(); IOUtil.writeString(headerData, next.asNtriple().toString()); } // Create ControlInfo ci.clear(); ci.setType(ControlInfo.Type.HEADER); ci.setFormat(HDTVocabulary.HEADER_NTRIPLES); ci.setInt("length",headerData.size()); ci.save(output); // Save Data output.write(headerData.toByteArray()); }