Skip to content

Commit

Permalink
add HDTGenerateDisk method with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ate47 committed Sep 16, 2022
1 parent 238c544 commit 14eddff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 8 additions & 2 deletions hdt-api/src/main/java/org/rdfhdt/hdt/hdt/HDTSupplier.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.rdfhdt.hdt.triples.TripleString;

import java.io.IOException;
import java.nio.file.Path;
import java.util.Iterator;

/**
Expand All @@ -19,7 +20,11 @@ public interface HDTSupplier {
* @return implementation using in-memory hdt
*/
static HDTSupplier memory() {
return HDTManager::generateHDT;
return (iterator, baseURI, hdtFormat, listener, location) -> {
try (HDT hdt = HDTManager.generateHDT(iterator, baseURI, hdtFormat, listener)) {
hdt.saveToHDT(location.toAbsolutePath().toString(), listener);
}
};
}

/**
Expand All @@ -29,8 +34,9 @@ static HDTSupplier memory() {
* @param baseURI the base URI (useless, but asked by some methods)
* @param hdtFormat the HDT options to create the HDT
* @param listener listener
* @param location where to write the HDT
* @throws IOException io exception while creating the HDT
* @throws ParserException parser exception while retrieving the triples
*/
HDT doGenerateHDT(Iterator<TripleString> iterator, String baseURI, HDTOptions hdtFormat, ProgressListener listener) throws IOException, ParserException;
void doGenerateHDT(Iterator<TripleString> iterator, String baseURI, HDTOptions hdtFormat, ProgressListener listener, Path location) throws IOException, ParserException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,7 @@ protected HDT doHDTCatTree(RDFFluxStop fluxStop, HDTSupplier supplier, Iterator<
gen++;
ProgressListener il = PrefixListener.of("gen#" + gen, listener);
Path hdtLocation = hdtStore.resolve("hdt-" + gen + ".hdt");
try (HDT hdt = supplier.doGenerateHDT(it, baseURI, hdtFormat, il)) {
hdt.saveToHDT(hdtLocation.toAbsolutePath().toString(), il);
}
supplier.doGenerateHDT(it, baseURI, hdtFormat, il, hdtLocation);

nextFile = it.hasNextFlux();
HDTFile hdtFile = new HDTFile(hdtLocation, 1);
Expand Down

0 comments on commit 14eddff

Please sign in to comment.