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(); } }
public static void main(String[] args) throws Throwable { if(args.length<1) { System.out.println("hdtVerify <file.hdt>"); System.exit(-1); } HDT hdt = HDTManager.mapHDT(args[0], null); checkDictionarySectionOrder(hdt.getDictionary().getSubjects().getSortedEntries()); checkDictionarySectionOrder(hdt.getDictionary().getPredicates().getSortedEntries()); checkDictionarySectionOrder(hdt.getDictionary().getObjects().getSortedEntries()); checkDictionarySectionOrder(hdt.getDictionary().getShared().getSortedEntries()); } }
@Override protected int graphBaseSize() { return (int)hdt.getTriples().getNumberOfElements(); }
System.out.println("Total Triples: "+hdt.getTriples().getNumberOfElements()); System.out.println("Different subjects: "+hdt.getDictionary().getNsubjects()); System.out.println("Different predicates: "+hdt.getDictionary().getNpredicates()); System.out.println("Different objects: "+hdt.getDictionary().getNobjects()); System.out.println("Common Subject/Object:"+hdt.getDictionary().getNshared()); hdt.saveToHDT(hdtOutput, this); System.out.println("HDT saved to file in: "+sw.stopAndShow()); if(hdt!=null) hdt.close();
this.triples = graph.getHDT().getTriples(); this.prefixMap = NodeDictionary.getMapping(execCxt); this.numSharedSO = graph.getHDT().getDictionary().getNshared();
@Override public void close() { super.close(); if(closeAfter) { try { hdt.close(); } catch (IOException e) { log.error("Unexpected exception.", e); } } } }
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()); }
@Override public long getStatistic(Node subject, Node predicate, Node object) { try { final BitmapTriples triples = (BitmapTriples) hdt.getTriples(); } else { long pred = hdt.getDictionary().getNpredicates(); if(pred>0) { return triples.getNumberOfElements()/pred;
public static void main(String[] args) { try { if(args.length!=1) { System.out.println("HDTGenerateIndex <hdtFile>"); System.exit(-1); } String hdtFileName = args[0]; HDT hdt = HDTManager.mapHDT(hdtFileName, null); if(hdtFileName.endsWith(".gz")) { hdtFileName = hdtFileName.substring(0, hdtFileName.length()-3); } System.out.println("Generating "+hdtFileName+".index"); HDTManager.indexedHDT(hdt, new ProgressListener() { @Override public void notifyProgress(float level, String message) { // System.out.println(message + "\t"+ Float.toString(level)); } }).close(); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } } }
iter = this.processor.search("", "", ""); } catch (NotFoundException e) { ExceptionOutput.output(e, "HDT iterator error", logger);
Dictionary dictionary = hdtg.getHDT().getDictionary(); if(countVar.equals(triple.getSubject())) { count = dictionary.getNsubjects(); if(patternID.isEmpty()) { count = hdtg.getHDT().getTriples().getNumberOfElements(); } else if(!patternID.isNoMatch()) { IteratorTripleID it = hdtg.getHDT().getTriples().search(patternID); if(it.numResultEstimation()==ResultEstimationType.EXACT) { count = it.estimatedNumResults();
public HDTGraph(HDT hdt, boolean close) { this.hdt = hdt; this.nodeDictionary = new NodeDictionary(hdt.getDictionary()); this.hdtStatistics = new HDTStatistics(this); // Must go after NodeDictionary created. this.reorderTransform=new ReorderTransformationHDT(this); // Must go after Dict and Stats this.closeAfter = close; }
if(hdt!=null) hdt.close(); in.close();
@Override protected ExtendedIterator<Triple> graphBaseFind(Triple jenaTriple) { TripleID triplePatID = nodeDictionary.getTriplePatID(jenaTriple); // System.out.println("Triple Pattern: "+jenaTriple+" as IDs: "+triplePatID); IteratorTripleID hdtIterator = hdt.getTriples().search( triplePatID ); numSearches++; return new HDTJenaIterator(nodeDictionary, hdtIterator); }
public ReorderTransformationHDT(HDTGraph graph) { this.stats = graph.getStatisticsHandler(); numTriples = graph.size(); initializeMatcher(); // FIXME: Compute exactly for using the HDT Dictionary dict = graph.getHDT().getDictionary(); TERM_S = dict.getNsubjects()/Math.max(numTriples, 1); TERM_P = dict.getNpredicates()/Math.max(numTriples, 1); TERM_O = dict.getNobjects()/Math.max(numTriples, 1); }
hdt.close();
@Override public void setUpProcess() throws LuzzuIOException { try { this.processor = HDTManager.loadIndexedHDT(datasetLocation); this.hdtDictionary = this.processor.getDictionary(); this.nodeDictionary = new NodeDictionary(this.hdtDictionary); logger.debug("Dataset {} is loaded into HDT processor.", datasetLocation); } catch (IOException e) { ExceptionOutput.output(e, "Error loading HDT File", logger); throw new LuzzuIOException(e.getMessage()); } try { loadMetrics(); this.executor = Executors.newSingleThreadExecutor(); this.isInitalised = true; } catch (ExternalMetricLoaderException e) { ExceptionOutput.output(e, "Error loading metrics", logger); } }