Skip to content

Commit bb159a3

Browse files
authored
Merge pull request #9 from ebremer/develop
Minor fixes
2 parents c6fcf54 + a030465 commit bb159a3

File tree

3 files changed

+56
-56
lines changed

3 files changed

+56
-56
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.ebremer</groupId>
55
<artifactId>BeakGraph</artifactId>
6-
<version>0.3.1</version>
6+
<version>0.3.2</version>
77
<packaging>jar</packaging>
88
<build>
99
<plugins>
@@ -29,7 +29,7 @@
2929
<exec.mainClass>com.ebremer.beakgraph.BeakGraph</exec.mainClass>
3030
<jena.version>4.8.0</jena.version>
3131
<arrow.version>12.0.0</arrow.version>
32-
<rocrate4j.version>0.3.0</rocrate4j.version>
32+
<rocrate4j.version>0.3.1</rocrate4j.version>
3333
</properties>
3434
<dependencies>
3535
<dependency>

src/main/java/com/ebremer/beakgraph/rdf/BeakReader.java

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -50,61 +50,60 @@ public final class BeakReader implements AutoCloseable {
5050
private int numtriples = 0;
5151

5252
public BeakReader(URI uri) throws FileNotFoundException, IOException {
53-
ROCrateReader reader = new ROCrateReader(uri);
54-
byPredicate = new HashMap<>();
55-
root = new RootAllocator();
56-
manifest = reader.getManifest();
57-
ParameterizedSparqlString pss = new ParameterizedSparqlString(
58-
"""
59-
select ?file where {
60-
?s a bg:BeakGraph; so:hasPart ?file .
61-
?file a bg:PredicateVector .
62-
}
63-
""");
64-
pss.setNsPrefix("bg", BG.NS);
65-
pss.setNsPrefix("rdfs", RDFS.uri);
66-
pss.setNsPrefix("so", SchemaDO.NS);
67-
QueryExecution qe = QueryExecutionFactory.create(pss.toString(), manifest);
68-
ResultSet rs = qe.execSelect();
69-
while (rs.hasNext()) {
70-
QuerySolution qs = rs.next();
71-
String x = qs.get("file").asResource().getURI();
72-
try {
73-
SeekableByteChannel xxx = reader.getSeekableByteChannel(x);
74-
ArrowFileReader afr = new ArrowFileReader(xxx, root);
75-
VectorSchemaRoot za = afr.getVectorSchemaRoot();
76-
afr.loadNextBatch();
77-
StructVector v = (StructVector) za.getVector(0);
78-
String p = v.getName();
79-
String dt = p.substring(0, 1);
80-
numtriples = numtriples + v.getValueCount();
81-
p = p.substring(1);
82-
if (!byPredicate.containsKey(p)) {
83-
byPredicate.put(p, new PAR(p));
53+
try (ROCrateReader reader = new ROCrateReader(uri)) {
54+
byPredicate = new HashMap<>();
55+
root = new RootAllocator();
56+
manifest = reader.getManifest();
57+
ParameterizedSparqlString pss = new ParameterizedSparqlString(
58+
"""
59+
select ?file where {
60+
?s a bg:BeakGraph; so:hasPart ?file .
61+
?file a bg:PredicateVector .
62+
}
63+
""");
64+
pss.setNsPrefix("bg", BG.NS);
65+
pss.setNsPrefix("rdfs", RDFS.uri);
66+
pss.setNsPrefix("so", SchemaDO.NS);
67+
QueryExecution qe = QueryExecutionFactory.create(pss.toString(), manifest);
68+
ResultSet rs = qe.execSelect();
69+
while (rs.hasNext()) {
70+
QuerySolution qs = rs.next();
71+
String x = qs.get("file").asResource().getURI();
72+
try {
73+
SeekableByteChannel xxx = reader.getSeekableByteChannel(x);
74+
ArrowFileReader afr = new ArrowFileReader(xxx, root);
75+
VectorSchemaRoot za = afr.getVectorSchemaRoot();
76+
afr.loadNextBatch();
77+
StructVector v = (StructVector) za.getVector(0);
78+
String p = v.getName();
79+
String dt = p.substring(0, 1);
80+
numtriples = numtriples + v.getValueCount();
81+
p = p.substring(1);
82+
if (!byPredicate.containsKey(p)) {
83+
byPredicate.put(p, new PAR(p));
84+
}
85+
PAR par = byPredicate.get(p);
86+
par.put(dt, v);
87+
} catch (FileNotFoundException ex) {
88+
Logger.getLogger(ROCrateReader.class.getName()).log(Level.SEVERE, null, ex);
89+
} catch (IOException ex) {
90+
Logger.getLogger(ROCrateReader.class.getName()).log(Level.SEVERE, null, ex);
8491
}
85-
PAR par = byPredicate.get(p);
86-
par.put(dt, v);
87-
} catch (FileNotFoundException ex) {
88-
Logger.getLogger(ROCrateReader.class.getName()).log(Level.SEVERE, null, ex);
89-
} catch (IOException ex) {
90-
Logger.getLogger(ROCrateReader.class.getName()).log(Level.SEVERE, null, ex);
9192
}
92-
}
93-
DictionaryEncoding dictionaryEncoding = new DictionaryEncoding(0, true, new ArrowType.Int(32, true));
94-
String cha = uri.toString();
95-
if (cha.startsWith("file:/")) {
96-
if (!cha.startsWith("file://")) {
97-
cha = "file:///"+cha.substring("file:/".length());
93+
DictionaryEncoding dictionaryEncoding = new DictionaryEncoding(0, true, new ArrowType.Int(32, true));
94+
String cha = uri.toString();
95+
if (cha.startsWith("file:/")) {
96+
if (!cha.startsWith("file://")) {
97+
cha = "file:///"+cha.substring("file:/".length());
98+
}
9899
}
100+
SeekableByteChannel d = reader.getSeekableByteChannel(cha+"/halcyon/dictionary.arrow");
101+
ArrowFileReader afr = new ArrowFileReader(d, root);
102+
VectorSchemaRoot za = afr.getVectorSchemaRoot();
103+
afr.loadNextBatch();
104+
dictionary = new Dictionary(za.getVector(0), dictionaryEncoding);
105+
nodeTable = new NodeTable(dictionary);
99106
}
100-
SeekableByteChannel d = reader.getSeekableByteChannel(cha+"/halcyon/dictionary");
101-
ArrowFileReader afr = new ArrowFileReader(d, root);
102-
VectorSchemaRoot za = afr.getVectorSchemaRoot();
103-
afr.loadNextBatch();
104-
dictionary = new Dictionary(za.getVector(0), dictionaryEncoding);
105-
nodeTable = new NodeTable(dictionary);
106-
reader.close();
107-
// DisplayAll();
108107
}
109108

110109
public Model getManifest() {
@@ -117,6 +116,7 @@ public void close() {
117116
v.close();
118117
});
119118
nodeTable.close();
119+
dictionary.getVector().close();
120120
root.close();
121121
}
122122

src/main/java/com/ebremer/beakgraph/rdf/BeakWriter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public Resource WriteDictionaryToFile(String base, ROCrate.ROCrateBuilder roc) {
162162
VectorSchemaRoot root = new VectorSchemaRoot(List.of(v.getField()), List.of(v));
163163
) {
164164
try {
165-
OutputStream zos = roc.getDestination().GetOutputStream(base+"/dictionary", CompressionMethod.STORE);
165+
OutputStream zos = roc.getDestination().GetOutputStream(base+"/dictionary.arrow", CompressionMethod.STORE);
166166
CountingOutputStream cos = new CountingOutputStream(zos);
167167
ArrowFileWriter writer = new ArrowFileWriter(root, null, Channels.newChannel(cos));
168168
writer.start();
@@ -174,7 +174,7 @@ public Resource WriteDictionaryToFile(String base, ROCrate.ROCrateBuilder roc) {
174174
fh.setUncompressedSize(numbytes);
175175
}
176176
roc
177-
.Add(target, base, "dictionary", CompressionMethod.STORE, true)
177+
.Add(target, base, "dictionary.arrow", CompressionMethod.STORE, true)
178178
.addProperty(SchemaDO.encodingFormat, "application/vnd.apache.arrow.file")
179179
.addLiteral(SchemaDO.contentSize, numbytes)
180180
.addProperty(RDF.type, SchemaDO.MediaObject)
@@ -207,7 +207,7 @@ public Resource WriteDataToFile(String base, ROCrate.ROCrateBuilder roc) {
207207
fh.setUncompressedSize(numbytes);
208208
}
209209
roc
210-
.Add(target, base, MD5(v.getField().getName().getBytes()), CompressionMethod.STORE, true)
210+
.Add(target, base, MD5(v.getField().getName().getBytes())+".arrow", CompressionMethod.STORE, true)
211211
.addProperty(SchemaDO.name, v.getField().getName().substring(1))
212212
.addProperty(BG.property, ResourceFactory.createResource(v.getName().substring(1,v.getName().length())))
213213
.addProperty(SchemaDO.encodingFormat, "application/vnd.apache.arrow.file")

0 commit comments

Comments
 (0)