Skip to content

Commit 01ed659

Browse files
authored
Merge pull request #7 from corese-stack/new-wrapper
New core.Graph wrapper
2 parents bfa9451 + e0db815 commit 01ed659

26 files changed

+665
-348
lines changed

src/main/java/fr/inria/corese/command/VersionProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package fr.inria.corese.command;
22

3-
import fr.inria.corese.core.util.CoreseInfo;
3+
import fr.inria.corese.command.utils.coreseCoreWrapper.CoreseUtils;
44
import picocli.CommandLine;
55

66
/**
@@ -15,7 +15,7 @@ public class VersionProvider implements CommandLine.IVersionProvider {
1515
public String[] getVersion() {
1616
return new String[] {
1717
commandVersion,
18-
"Based on Corese-Core Version: " + CoreseInfo.getVersion()
18+
"Based on Corese-Core Version: " + CoreseUtils.getCoreseVersion()
1919
};
2020
}
2121

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
import fr.inria.corese.command.VersionProvider;
88
import fr.inria.corese.command.utils.ConfigManager;
9+
import fr.inria.corese.command.utils.coreseCoreWrapper.CoreseUtils;
910
import fr.inria.corese.command.utils.exporter.rdf.RdfDataExporter;
1011
import fr.inria.corese.core.util.Property;
11-
import fr.inria.corese.core.util.Property.Value;
1212
import picocli.CommandLine.Command;
1313
import picocli.CommandLine.Model.CommandSpec;
1414
import picocli.CommandLine.Option;
@@ -77,7 +77,7 @@ public Integer call() {
7777
}
7878

7979
// Set owl import
80-
Property.set(Value.OWL_AUTO_IMPORT, this.owlImport);
80+
CoreseUtils.setProperty(Property.Value.OWL_AUTO_IMPORT, this.owlImport);
8181

8282
return 0;
8383
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package fr.inria.corese.command.programs;
22

3+
import fr.inria.corese.command.utils.coreseCoreWrapper.CoreseRdfGraph;
34
import fr.inria.corese.command.utils.exporter.rdf.EnumCanonicAlgo;
45
import fr.inria.corese.command.utils.exporter.rdf.RdfDataCanonicalizer;
56
import fr.inria.corese.command.utils.loader.rdf.EnumRdfInputFormat;
6-
import fr.inria.corese.command.utils.loader.rdf.RdfDataLoader;
7-
import fr.inria.corese.core.Graph;
87
import picocli.CommandLine.Command;
98
import picocli.CommandLine.Option;
109

@@ -29,8 +28,8 @@ public Integer call() {
2928

3029
try {
3130
// Load the input file(s)
32-
RdfDataLoader loader = new RdfDataLoader(this.spec, this.verbose);
33-
Graph graph = loader.load(this.inputsRdfData, this.inputFormat, this.recursive);
31+
CoreseRdfGraph graph = new CoreseRdfGraph(this.spec, this.verbose);
32+
graph.load(this.inputsRdfData, this.inputFormat, this.recursive);
3433

3534
// Canonicalize and export the graph
3635
RdfDataCanonicalizer rdfCanonicalizer = new RdfDataCanonicalizer(this.spec, this.verbose, this.output);

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package fr.inria.corese.command.programs;
22

3+
import fr.inria.corese.command.utils.coreseCoreWrapper.CoreseRdfGraph;
34
import fr.inria.corese.command.utils.exporter.rdf.EnumRdfOutputFormat;
45
import fr.inria.corese.command.utils.exporter.rdf.RdfDataExporter;
56
import fr.inria.corese.command.utils.loader.rdf.EnumRdfInputFormat;
6-
import fr.inria.corese.command.utils.loader.rdf.RdfDataLoader;
7-
import fr.inria.corese.core.Graph;
87
import picocli.CommandLine.Command;
98
import picocli.CommandLine.Option;
109

@@ -29,8 +28,8 @@ public Integer call() {
2928

3029
try {
3130
// Load the input file(s)
32-
RdfDataLoader loader = new RdfDataLoader(this.spec, this.verbose);
33-
Graph graph = loader.load(this.inputsRdfData, this.inputFormat, this.recursive);
31+
CoreseRdfGraph graph = new CoreseRdfGraph(this.spec, this.verbose);
32+
graph.load(this.inputsRdfData, this.inputFormat, this.recursive);
3433

3534
// Export the graph
3635
RdfDataExporter rdfExporter = new RdfDataExporter(this.spec, this.verbose, this.output);

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package fr.inria.corese.command.programs;
22

3+
import fr.inria.corese.command.utils.coreseCoreWrapper.CoreseRdfGraph;
4+
import fr.inria.corese.command.utils.coreseCoreWrapper.CoreseSparqlQuery;
35
import fr.inria.corese.command.utils.exporter.sparql.EnumResultFormat;
46
import fr.inria.corese.command.utils.exporter.sparql.SparqlResultExporter;
57
import fr.inria.corese.command.utils.loader.rdf.EnumRdfInputFormat;
6-
import fr.inria.corese.command.utils.loader.rdf.RdfDataLoader;
78
import fr.inria.corese.command.utils.loader.sparql.SparqlQueryLoader;
8-
import fr.inria.corese.core.Graph;
99
import fr.inria.corese.core.kgram.core.Mappings;
10-
import fr.inria.corese.core.query.QueryProcess;
1110
import picocli.CommandLine.Command;
1211
import picocli.CommandLine.Option;
1312

@@ -37,8 +36,8 @@ public Integer call() {
3736
try {
3837

3938
// Load the input file(s)
40-
RdfDataLoader loader = new RdfDataLoader(this.spec, this.verbose);
41-
Graph graph = loader.load(this.inputsRdfData, this.inputFormat, this.recursive);
39+
CoreseRdfGraph graph = new CoreseRdfGraph(this.spec, this.verbose);
40+
graph.load(this.inputsRdfData, this.inputFormat, this.recursive);
4241

4342
// Load the query
4443
SparqlQueryLoader queryLoader = new SparqlQueryLoader(this.spec, this.verbose);
@@ -58,18 +57,15 @@ public Integer call() {
5857
}
5958
}
6059

61-
private Mappings execute(Graph graph, String query) throws Exception {
62-
QueryProcess exec = QueryProcess.create(graph);
60+
private Mappings execute(CoreseRdfGraph graph, String query) throws Exception {
6361

64-
// Execute query
65-
try {
66-
67-
if (this.verbose) {
68-
this.spec.commandLine().getErr().println("Query: " + query);
69-
this.spec.commandLine().getErr().println("Executing query...");
70-
}
62+
if (this.verbose) {
63+
this.spec.commandLine().getErr().println("Query: " + query);
64+
this.spec.commandLine().getErr().println("Executing query...");
65+
}
7166

72-
return exec.query(query);
67+
try {
68+
return CoreseSparqlQuery.execute(graph, query);
7369
} catch (Exception e) {
7470
throw new Exception("Error when executing SPARQL query : " + e.getMessage(), e);
7571
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package fr.inria.corese.command.programs;
22

3-
import fr.inria.corese.command.utils.ContentValidator;
3+
import fr.inria.corese.command.utils.coreseCoreWrapper.CoreseRdfGraph;
4+
import fr.inria.corese.command.utils.coreseCoreWrapper.CoreseShacl;
45
import fr.inria.corese.command.utils.exporter.rdf.EnumRdfOutputFormat;
56
import fr.inria.corese.command.utils.exporter.rdf.RdfDataExporter;
67
import fr.inria.corese.command.utils.loader.rdf.EnumRdfInputFormat;
7-
import fr.inria.corese.command.utils.loader.rdf.RdfDataLoader;
8-
import fr.inria.corese.core.Graph;
98
import picocli.CommandLine.Command;
109
import picocli.CommandLine.Option;
1110

@@ -34,19 +33,20 @@ public Integer call() {
3433

3534
try {
3635
// Load input file(s)
37-
RdfDataLoader loader = new RdfDataLoader(this.spec, this.verbose);
38-
Graph dataGraph = loader.load(this.inputsRdfData, this.inputFormat, this.recursive);
36+
CoreseRdfGraph dataGraph = new CoreseRdfGraph(this.spec, this.verbose);
37+
dataGraph.load(this.inputsRdfData, this.inputFormat, this.recursive);
3938

4039
// Load shapes file(s)
41-
Graph shapesGraph = loader.load(this.shaclShapes, this.reportFormat, this.recursive);
40+
CoreseRdfGraph shapesGraph = new CoreseRdfGraph(this.spec, this.verbose);
41+
shapesGraph.load(this.shaclShapes, this.reportFormat, this.recursive);
4242

4343
// Check if shapes graph contains SHACL shapes
44-
if (!ContentValidator.containsShaclShapes(shapesGraph)) {
44+
if (! shapesGraph.containsShaclShapes()) {
4545
throw new IllegalArgumentException("No SHACL shapes found in the input file(s).");
4646
}
4747

4848
// Evaluation of SHACL shapes
49-
Graph reportGraph = this.evaluateSHACLShapes(dataGraph, shapesGraph);
49+
CoreseRdfGraph reportGraph = this.evaluateSHACLShapes(dataGraph, shapesGraph);
5050

5151
// Export the report graph
5252
RdfDataExporter rdfExporter = new RdfDataExporter(this.spec, this.verbose, this.output);
@@ -67,15 +67,15 @@ public Integer call() {
6767
* @return The report graph.
6868
* @throws Exception If an error occurs while evaluating SHACL shapes.
6969
*/
70-
private Graph evaluateSHACLShapes(Graph dataGraph, Graph shapesGraph) throws Exception {
70+
private CoreseRdfGraph evaluateSHACLShapes(CoreseRdfGraph dataGraph, CoreseRdfGraph shapesGraph) throws Exception {
7171

7272
if (this.verbose) {
7373
this.spec.commandLine().getErr().println("Evaluating SHACL shapes...");
7474
}
7575

76-
fr.inria.corese.core.shacl.Shacl shacl = new fr.inria.corese.core.shacl.Shacl(dataGraph, shapesGraph);
76+
CoreseShacl shacl = new CoreseShacl(dataGraph.getGraph(), shapesGraph.getGraph());
7777
try {
78-
return shacl.eval();
78+
return new CoreseRdfGraph(shacl.eval());
7979
} catch (Exception e) {
8080
throw new Exception("Error while evaluating SHACL shapes: " + e.getMessage(), e);
8181
}

src/main/java/fr/inria/corese/command/utils/ConfigManager.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.nio.file.Path;
44

5-
import fr.inria.corese.core.util.Property;
5+
import fr.inria.corese.command.utils.coreseCoreWrapper.CoreseUtils;
66
import picocli.CommandLine.Model.CommandSpec;
77

88
/**
@@ -19,11 +19,7 @@ public class ConfigManager {
1919
*/
2020
public static void loadFromFile(Path path, CommandSpec spec, boolean verbose) {
2121

22-
try {
23-
Property.load(path.toString());
24-
} catch (Exception e) {
25-
throw new IllegalArgumentException("Failed to open config file: " + path.toString(), e);
26-
}
22+
CoreseUtils.loadProperty(path.toString());
2723

2824
if (verbose) {
2925
spec.commandLine().getErr().println("Loaded config file: " + path.toString());

src/main/java/fr/inria/corese/command/utils/ContentValidator.java

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package fr.inria.corese.command.utils.coreseCoreWrapper;
2+
3+
import fr.inria.corese.core.kgram.core.Mappings;
4+
import fr.inria.corese.core.sparql.triple.parser.ASTQuery;
5+
6+
/**
7+
* Wrapper class for corese.core.kgram.core.Mappings
8+
*/
9+
public class CoreseMappingType {
10+
11+
/**
12+
* AST of the Mapping wrapped
13+
*/
14+
private ASTQuery mappingAST;
15+
16+
public CoreseMappingType(Mappings map) {
17+
mappingAST = map.getAST();
18+
}
19+
20+
public boolean isUpdate() {
21+
return mappingAST.isUpdate();
22+
}
23+
24+
public boolean isConstruct() {
25+
return mappingAST.isConstruct();
26+
}
27+
28+
public boolean isAsk() {
29+
return mappingAST.isAsk();
30+
}
31+
32+
public boolean isSelect() {
33+
return mappingAST.isSelect();
34+
}
35+
36+
public boolean isDescribe() {
37+
return mappingAST.isDescribe();
38+
}
39+
40+
}

0 commit comments

Comments
 (0)