@@ -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
0 commit comments