Skip to content

Commit 9faaf3c

Browse files
committed
Refactor code for consistency by removing unnecessary whitespace and improving readability in Query, Validate, KgramQuery, CoreseGraph, and SparqlHttpClient classes.
1 parent d221c88 commit 9faaf3c

6 files changed

Lines changed: 57 additions & 37 deletions

File tree

src/main/java/fr/inria/corese/command/programs/Query.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public Integer call() {
4444
String query = queryLoader.load(this.queryUrlOrFile);
4545

4646
// Execute the query
47-
Mappings mappings = this.execute( graph, query);
47+
Mappings mappings = this.execute(graph, query);
4848

4949
// Export the result
5050
SparqlResultExporter exporter = new SparqlResultExporter(this.spec, this.verbose, this.output);

src/main/java/fr/inria/corese/command/programs/Validate.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import fr.inria.corese.command.utils.exporter.rdf.EnumRdfOutputFormat;
66
import fr.inria.corese.command.utils.exporter.rdf.RdfDataExporter;
77
import fr.inria.corese.command.utils.loader.rdf.EnumRdfInputFormat;
8+
import fr.inria.corese.core.shacl.Shacl;
89
import picocli.CommandLine.Command;
910
import picocli.CommandLine.Option;
1011

@@ -73,9 +74,9 @@ private CoreseGraph evaluateSHACLShapes(CoreseGraph dataGraph, CoreseGraph shape
7374
this.spec.commandLine().getErr().println("Evaluating SHACL shapes...");
7475
}
7576

76-
fr.inria.corese.core.shacl.Shacl shacl = new fr.inria.corese.core.shacl.Shacl(dataGraph.getGraph(), shapesGraph.getGraph());
77+
Shacl shacl = new fr.inria.corese.core.shacl.Shacl(dataGraph.getGraph(), shapesGraph.getGraph());
7778
try {
78-
return new CoreseGraph( shacl.eval());
79+
return new CoreseGraph(shacl.eval());
7980
} catch (Exception e) {
8081
throw new Exception("Error while evaluating SHACL shapes: " + e.getMessage(), e);
8182
}

src/main/java/fr/inria/corese/command/utils/coreseCoreWrapper/CoreseGraph.java

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
package 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+
312
import fr.inria.corese.command.utils.ConvertString;
413
import fr.inria.corese.command.utils.InputTypeDetector;
514
import fr.inria.corese.command.utils.InputTypeDetector.InputType;
@@ -12,25 +21,16 @@
1221
import fr.inria.corese.core.print.CanonicalRdf10Format;
1322
import 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) {

src/main/java/fr/inria/corese/command/utils/coreseCoreWrapper/KgramQuery.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,23 @@ public KgramQuery(String query) throws EngineException {
2727
CoreseGraph graph = new CoreseGraph();
2828
QueryProcess exec = QueryProcess.create(graph.getGraph());
2929

30-
this.query = exec.compile( query);
30+
this.query = exec.compile(query);
3131
}
3232

3333
/**
3434
* Executes the stringQuery on the graph
35+
*
36+
* @param graph The graph to execute the query on
37+
* @param stringQuery The SPARQL query string
38+
* @return The mappings resulting from the query execution
39+
* @throws EngineException If an error occurs during query execution
3540
*/
3641
public static Mappings execute(CoreseGraph graph, String stringQuery) throws EngineException {
3742
QueryProcess exec = QueryProcess.create(graph.getGraph());
3843

3944
return exec.query(stringQuery);
4045
}
4146

42-
public List<Node> getFrom() {
43-
return query.getFrom();
44-
}
45-
4647
/**
4748
* Checks if the query contains FROM clause.
4849
*
@@ -57,11 +58,11 @@ public boolean containsFromClause() {
5758
*
5859
* @return true if the query is an update, false otherwise
5960
*/
60-
public boolean isSPARQLUpdate() {
61+
public boolean isSPARQLUpdate() {
6162
return query.getAST().isSPARQLUpdate();
6263
}
6364

64-
public ASTUpdate getUpdate() {
65+
public ASTUpdate getAstUpdate() {
6566
return query.getAST().getUpdate();
6667
}
6768

src/main/java/fr/inria/corese/command/utils/http/SparqlHttpClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private void validateQuery(String queryString, List<String> defaultGraphUris, Li
205205
// Try to build a SPARQL query from the queryString
206206
KgramQuery query = null;
207207
try {
208-
query = new KgramQuery( queryString);
208+
query = new KgramQuery(queryString);
209209
} catch (EngineException e) {
210210
throw new IllegalArgumentException("Invalid SPARQL query", e);
211211
}
@@ -242,7 +242,7 @@ private void validateQuery(String queryString, List<String> defaultGraphUris, Li
242242
// which is not allowed by the SPARQL specification
243243
// (see https://www.w3.org/TR/sparql11-protocol/#update-operation)
244244
List<String> sparqlConstants = new ArrayList<>();
245-
ASTUpdate astUpdate = query.getUpdate();
245+
ASTUpdate astUpdate = query.getAstUpdate();
246246
if (astUpdate != null) {
247247
for (Update update : astUpdate.getUpdates()) {
248248
Composite composite = update.getComposite();

src/test/java/fr/inria/corese/command/programs/ConvertTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
import org.junit.jupiter.api.BeforeEach;
1515
import org.junit.jupiter.api.Test;
1616

17-
import fr.inria.corese.command.utils.loader.rdf.EnumRdfInputFormat;
1817
import fr.inria.corese.command.utils.coreseCoreWrapper.CoreseGraph;
18+
import fr.inria.corese.command.utils.loader.rdf.EnumRdfInputFormat;
1919
import fr.inria.corese.core.load.Load;
2020
import picocli.CommandLine;
2121

0 commit comments

Comments
 (0)