attach-javadocs
diff --git a/src/main/java/org/topbraid/shacl/tools/AbstractTool.java b/src/main/java/org/topbraid/shacl/tools/AbstractTool.java
index c0753086..02004c91 100644
--- a/src/main/java/org/topbraid/shacl/tools/AbstractTool.java
+++ b/src/main/java/org/topbraid/shacl/tools/AbstractTool.java
@@ -16,11 +16,6 @@
*/
package org.topbraid.shacl.tools;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-
import org.apache.jena.ontology.OntDocumentManager;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.ontology.OntModelSpec;
@@ -34,78 +29,78 @@
import org.topbraid.shacl.vocabulary.SH;
import org.topbraid.shacl.vocabulary.TOSH;
+import java.io.*;
+
class AbstractTool {
- private final static String DATA_FILE = "-datafile";
-
- private final static String SHAPES_FILE = "-shapesfile";
-
- private final static String MAX_ITERATIONS = "-maxiterations";
-
-
- private OntDocumentManager dm = new OntDocumentManager();
-
- private OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
-
-
- AbstractTool() {
-
- InputStream shaclTTL = SHACLSystemModel.class.getResourceAsStream("/rdf/shacl.ttl");
- Model shacl = JenaUtil.createMemoryModel();
- shacl.read(shaclTTL, SH.BASE_URI, FileUtils.langTurtle);
- shacl.add(SystemTriples.getVocabularyModel());
- dm.addModel(SH.BASE_URI, shacl);
-
- InputStream dashTTL = SHACLSystemModel.class.getResourceAsStream("/rdf/dash.ttl");
- Model dash = JenaUtil.createMemoryModel();
- dash.read(dashTTL, SH.BASE_URI, FileUtils.langTurtle);
- dm.addModel(DASH.BASE_URI, dash);
-
- InputStream toshTTL = SHACLSystemModel.class.getResourceAsStream("/rdf/tosh.ttl");
- Model tosh = JenaUtil.createMemoryModel();
- tosh.read(toshTTL, SH.BASE_URI, FileUtils.langTurtle);
- dm.addModel(TOSH.BASE_URI, tosh);
-
- spec.setDocumentManager(dm);
- }
-
- protected int getMaxIterations(String[] args) {
- for(int i = 0; i < args.length - 1; i++) {
- if(MAX_ITERATIONS.equals(args[i])) {
- return Integer.parseInt(args[i + 1]);
- }
- }
- return 1;
- }
-
- protected Model getDataModel(String[] args) throws IOException {
- for(int i = 0; i < args.length - 1; i++) {
- if(DATA_FILE.equals(args[i])) {
- String dataFileName = args[i + 1];
- OntModel dataModel = ModelFactory.createOntologyModel(spec);
- File file = new File(dataFileName);
- String lang = FileUtils.langTurtle;
- dataModel.read(new FileInputStream(file), "urn:x:base", lang);
- return dataModel;
- }
- }
- System.err.println("Missing -datafile, e.g.: -datafile myfile.ttl");
- System.exit(0);
- return null;
- }
-
-
- protected Model getShapesModel(String[] args) throws IOException {
- for(int i = 0; i < args.length - 1; i++) {
- if(SHAPES_FILE.equals(args[i])) {
- String fileName = args[i + 1];
- OntModel model = ModelFactory.createOntologyModel(spec);
- File file = new File(fileName);
- String lang = FileUtils.langTurtle;
- model.read(new FileInputStream(file), "urn:x:base", lang);
- return model;
- }
- }
- return null;
- }
-}
+ private final static String DATA_FILE = "-datafile";
+
+ private final static String SHAPES_FILE = "-shapesfile";
+
+ private final static String MAX_ITERATIONS = "-maxiterations";
+
+ protected final OntDocumentManager dm = new OntDocumentManager();
+
+ private OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
+
+
+ AbstractTool() {
+
+ InputStream shaclTTL = SHACLSystemModel.class.getResourceAsStream("/rdf/shacl.ttl");
+ Model shacl = JenaUtil.createMemoryModel();
+ shacl.read(shaclTTL, SH.BASE_URI, FileUtils.langTurtle);
+ shacl.add(SystemTriples.getVocabularyModel());
+ dm.addModel(SH.BASE_URI, shacl);
+
+ InputStream dashTTL = SHACLSystemModel.class.getResourceAsStream("/rdf/dash.ttl");
+ Model dash = JenaUtil.createMemoryModel();
+ dash.read(dashTTL, SH.BASE_URI, FileUtils.langTurtle);
+ dm.addModel(DASH.BASE_URI, dash);
+
+ InputStream toshTTL = SHACLSystemModel.class.getResourceAsStream("/rdf/tosh.ttl");
+ Model tosh = JenaUtil.createMemoryModel();
+ tosh.read(toshTTL, SH.BASE_URI, FileUtils.langTurtle);
+ dm.addModel(TOSH.BASE_URI, tosh);
+
+ spec.setDocumentManager(dm);
+ }
+
+ protected int getMaxIterations(String[] args) {
+ for (int i = 0; i < args.length - 1; i++) {
+ if (MAX_ITERATIONS.equals(args[i])) {
+ return Integer.parseInt(args[i + 1]);
+ }
+ }
+ return 1;
+ }
+
+ protected Model getDataModel(String[] args) throws IOException {
+ for (int i = 0; i < args.length - 1; i++) {
+ if (DATA_FILE.equals(args[i])) {
+ return getModel(args, i);
+ }
+ }
+ System.err.println("Missing -datafile, e.g.: -datafile myfile.ttl");
+ System.exit(0);
+ return null;
+ }
+
+ protected Model getShapesModel(String[] args) throws IOException {
+ for (int i = 0; i < args.length - 1; i++) {
+ if (SHAPES_FILE.equals(args[i])) {
+ return getModel(args, i);
+ }
+ }
+ return null;
+ }
+
+ private Model getModel(String[] args, int i) throws FileNotFoundException {
+ String fileName = args[i + 1];
+ OntModel dataModel = ModelFactory.createOntologyModel(spec);
+ File file = new File(fileName);
+ String lang = FileUtils.langTurtle;
+ dataModel.read(new FileInputStream(file), "urn:x:base", lang);
+ return dataModel;
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/topbraid/shacl/tools/Validate.java b/src/main/java/org/topbraid/shacl/tools/Validate.java
index 93943aa3..b60e2250 100644
--- a/src/main/java/org/topbraid/shacl/tools/Validate.java
+++ b/src/main/java/org/topbraid/shacl/tools/Validate.java
@@ -16,11 +16,6 @@
*/
package org.topbraid.shacl.tools;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.util.Arrays;
-
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.util.FileUtils;
@@ -28,48 +23,61 @@
import org.topbraid.shacl.validation.ValidationUtil;
import org.topbraid.shacl.vocabulary.SH;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.Arrays;
+
/**
* Stand-alone utility to perform constraint validation of a given file.
- *
+ *
* Example arguments:
- *
- * -datafile my.ttl
- *
+ *
+ * -datafile my.ttl
+ *
* @author Holger Knublauch
*/
public class Validate extends AbstractTool {
-
- public static void main(String[] args) throws IOException {
- // Temporarily redirect system.err to avoid SLF4J warning
- PrintStream oldPS = System.err;
- System.setErr(new PrintStream(new ByteArrayOutputStream()));
- Validate validate = new Validate();
- System.setErr(oldPS);
- validate.run(args);
- }
-
-
- private void run(String[] args) throws IOException {
- Model dataModel = getDataModel(args);
- Model shapesModel = getShapesModel(args);
- if(shapesModel == null) {
- shapesModel = dataModel;
- }
- boolean validateShapes = Arrays.asList(args).contains("-validateShapes");
- boolean addBlankNodes = Arrays.asList(args).contains("-addBlankNodes");
- Resource report = ValidationUtil.validateModel(dataModel, shapesModel, validateShapes);
- // If addBlankNodes is true, then the code will walk through the report and add the blank nodes to the report
- if(addBlankNodes) {
- Model referencedNodes = BlankNodeFinder.findBlankNodes(report.getModel(),shapesModel);
- report.getModel().add(referencedNodes);
- }
+ private final static String VALIDATE_SHAPES = "-validateShapes";
+ private final static String ADD_BLANK_NODES = "-addBlankNodes";
+ private final static String NO_IMPORTS = "-noImports";
+
+ public static void main(String[] args) throws IOException {
+ // Temporarily redirect system.err to avoid SLF4J warning
+ PrintStream oldPS = System.err;
+ System.setErr(new PrintStream(new ByteArrayOutputStream()));
+ Validate validate = new Validate();
+ System.setErr(oldPS);
+ validate.run(args);
+ }
+
+ private void run(String[] args) throws IOException {
+ Model dataModel = getDataModel(args);
+ Model shapesModel = getShapesModel(args);
+ if (shapesModel == null) {
+ shapesModel = dataModel;
+ }
+ boolean validateShapes = Arrays.asList(args).contains(VALIDATE_SHAPES);
+ boolean addBlankNodes = Arrays.asList(args).contains(ADD_BLANK_NODES);
+ boolean noImports = Arrays.asList(args).contains(NO_IMPORTS);
+ if (noImports) {
+ dm.setProcessImports(false);
+ }
+ Resource report = ValidationUtil.validateModel(dataModel, shapesModel, validateShapes);
+
+ if (addBlankNodes) {
+ // If addBlankNodes is true, then the code will walk through the report and add the blank nodes to the report
+ Model referencedNodes = BlankNodeFinder.findBlankNodes(report.getModel(), shapesModel);
+ report.getModel().add(referencedNodes);
+ }
+
+ report.getModel().write(System.out, FileUtils.langTurtle);
- report.getModel().write(System.out, FileUtils.langTurtle);
+ if (report.hasProperty(SH.conforms, JenaDatatypes.FALSE)) {
+ // See https://github.com/TopQuadrant/shacl/issues/56
+ System.exit(1);
+ }
+ }
- if(report.hasProperty(SH.conforms, JenaDatatypes.FALSE)) {
- // See https://github.com/TopQuadrant/shacl/issues/56
- System.exit(1);
- }
- }
-}
+}
\ No newline at end of file
diff --git a/src/test/java/org/topbraid/shacl/ValidationExample.java b/src/test/java/org/topbraid/shacl/ValidationExample.java
index e1b9ddf6..83f79bb5 100644
--- a/src/test/java/org/topbraid/shacl/ValidationExample.java
+++ b/src/test/java/org/topbraid/shacl/ValidationExample.java
@@ -25,20 +25,20 @@
public class ValidationExample {
- /**
- * Loads an example SHACL file and validates all focus nodes against all shapes.
- */
- public static void main(String[] args) throws Exception {
-
- // Load the main data model
- Model dataModel = JenaUtil.createMemoryModel();
- dataModel.read(ValidationExample.class.getResourceAsStream("/sh/tests/core/property/class-001.test.ttl"), "urn:dummy", FileUtils.langTurtle);
-
- // Perform the validation of everything, using the data model
- // also as the shapes model - you may have them separated
- Resource report = ValidationUtil.validateModel(dataModel, dataModel, true);
-
- // Print violations
- System.out.println(ModelPrinter.get().print(report.getModel()));
- }
+ /**
+ * Loads an example SHACL file and validates all focus nodes against all shapes.
+ */
+ public static void main(String[] args) {
+
+ // Load the main data model
+ Model dataModel = JenaUtil.createMemoryModel();
+ dataModel.read(ValidationExample.class.getResourceAsStream("/sh/tests/core/property/class-001.test.ttl"), "urn:dummy", FileUtils.langTurtle);
+
+ // Perform the validation of everything, using the data model
+ // also as the shapes model - you may have them separated
+ Resource report = ValidationUtil.validateModel(dataModel, dataModel, true);
+
+ // Print violations
+ System.out.println(ModelPrinter.get().print(report.getModel()));
+ }
}
\ No newline at end of file