11package fr .inria .corese .command .utils .coreseCoreWrapper ;
22
3+ import java .io .File ;
4+ import java .io .FileInputStream ;
5+ import java .io .FileNotFoundException ;
6+ import java .io .IOException ;
7+ import java .io .InputStream ;
8+ import java .net .URL ;
9+ import java .nio .file .Path ;
10+ import java .util .Optional ;
11+
312import fr .inria .corese .command .utils .ConvertString ;
413import fr .inria .corese .command .utils .InputTypeDetector ;
514import fr .inria .corese .command .utils .InputTypeDetector .InputType ;
1221import fr .inria .corese .core .print .CanonicalRdf10Format ;
1322import picocli .CommandLine .Model .CommandSpec ;
1423
15- import java .io .File ;
16- import java .io .FileInputStream ;
17- import java .io .FileNotFoundException ;
18- import java .io .IOException ;
19- import java .io .InputStream ;
20- import java .net .URL ;
21- import java .nio .file .Path ;
22- import java .util .Optional ;
23-
2424/**
2525 * Wrapper class for corese.core.Graph
2626 * All interactions with corese.core.Graph should be done through this class
2727 */
28- public class CoreseGraph {
28+ public class CoreseGraph {
2929 private Graph graph ;
3030
3131 // Command specification
32- private CommandSpec spec = null ; // Command specification
33- private boolean verbose = false ; // If set to true, print information about the loaded files
32+ private CommandSpec spec = null ; // Command specification
33+ private boolean verbose = false ; // If set to true, print information about the loaded files
3434
3535 //////////////////
3636 // Constructors //
@@ -47,24 +47,27 @@ public CoreseGraph() {
4747 /**
4848 * Constructor.
4949 * Empty graph
50+ *
5051 * @param spec Command specification.
5152 * @param verbose If true, print information about the loaded files.
52- */
53- public CoreseGraph (CommandSpec spec , boolean verbose ) {
53+ */
54+ public CoreseGraph (CommandSpec spec , boolean verbose ) {
5455 this (Graph .create (), spec , verbose );
5556 }
5657
5758 /**
5859 * Constructor.
5960 * Empty command specification, verbose is false
60- * @param graph A given corese Graph
61+ *
62+ * @param graph A given corese Graph
6163 */
6264 public CoreseGraph (Graph graph ) {
6365 this (graph , null , false );
6466 }
6567
6668 /**
6769 * Constructor.
70+ *
6871 * @param graph A given corese Graph
6972 * @param spec Command specification.
7073 * @param verbose If true, print information about the loaded files.
@@ -85,11 +88,11 @@ public Graph getGraph() {
8588
8689 public int size () {
8790 return graph .size ();
88- }
91+ }
8992
90- public void init () {
93+ public void init () {
9194 graph .init ();
92- }
95+ }
9396
9497 /**
9598 * Load RDF data into a Corese Graph.
@@ -105,7 +108,7 @@ public void init() {
105108 public void load (String [] inputs , EnumRdfInputFormat inputFormat , boolean recursive )
106109 throws IllegalArgumentException {
107110
108- Graph otherGraph = null ; // used to merge another graph into the final result
111+ Graph otherGraph = null ; // used to merge another graph into the final result
109112
110113 // If no input is provided, load from standard input
111114 if (inputs == null || inputs .length == 0 ) {
@@ -143,11 +146,25 @@ public void load(String[] inputs, EnumRdfInputFormat inputFormat, boolean recurs
143146
144147 }
145148
149+ /**
150+ * Returns a Canonical RDF 1.0 representation of the graph.
151+ *
152+ * @return A Canonical RDF 1.0 representation of the graph.
153+ */
146154 public CanonicalRdf10Format canonicalRdf10Format () {
147155 return CanonicalRdf10Format .create (graph );
148156 }
149157
150- public Iterable <Edge > getEdgesRDF4J ( Node s , Node p , Node o , Node ... from ) {
158+ /**
159+ * Get edges in RDF4J format.
160+ *
161+ * @param s Subject node (can be null for wildcard)
162+ * @param p Predicate node (can be null for wildcard)
163+ * @param o Object node (can be null for wildcard)
164+ * @param from Named graph nodes (can be null for wildcard)
165+ * @return An iterable of edges in RDF4J format.
166+ */
167+ public Iterable <Edge > getEdgesRDF4J (Node s , Node p , Node o , Node ... from ) {
151168 return graph .getEdgesRDF4J (s , p , o , from );
152169 }
153170
@@ -244,7 +261,8 @@ private Graph loadFromFile(Path path, EnumRdfInputFormat inputFormat) {
244261 * @param recursive If true, load RDF data from subdirectories.
245262 * @return The Corese Graph containing the RDF data.
246263 */
247- private void loadFromDirectoryRecursive (Path path , EnumRdfInputFormat inputFormat , boolean recursive , Graph loadedGraph ) {
264+ private void loadFromDirectoryRecursive (Path path , EnumRdfInputFormat inputFormat , boolean recursive ,
265+ Graph loadedGraph ) {
248266
249267 File [] files = path .toFile ().listFiles ();
250268
@@ -255,7 +273,7 @@ private void loadFromDirectoryRecursive(Path path, EnumRdfInputFormat inputForma
255273 this .loadFromDirectoryRecursive (childFile .toPath (), inputFormat , recursive , loadedGraph );
256274 } else if (childFile .isFile ()) {
257275 Graph otherGraph = this .loadFromFile (childFile .toPath (), inputFormat );
258- loadedGraph .merge ( otherGraph );
276+ loadedGraph .merge (otherGraph );
259277 }
260278 }
261279 }
@@ -298,7 +316,7 @@ private Graph loadFromInputStream(InputStream inputStream, EnumRdfInputFormat in
298316 Load load = Load .create (loadedGraph );
299317
300318 try {
301- load .parse ( inputStream , inputFormat .getCoreseFormat ());
319+ load .parse (inputStream , inputFormat .getCoreseFormat ());
302320 return loadedGraph ;
303321 } catch (Exception e ) {
304322 throw new IllegalArgumentException ("Failed to parse RDF file. Check if file is well-formed and that "
@@ -314,7 +332,7 @@ private Graph loadFromInputStream(InputStream inputStream, EnumRdfInputFormat in
314332 */
315333 private Optional <EnumRdfInputFormat > guessInputFormat (String input ) {
316334
317- EnumRdfInputFormat inputFormat = EnumRdfInputFormat .create ( LoadFormat .getFormat (input ));
335+ EnumRdfInputFormat inputFormat = EnumRdfInputFormat .create (LoadFormat .getFormat (input ));
318336
319337 if (inputFormat == null ) {
320338 if (this .verbose ) {
0 commit comments