summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2015-07-07 16:42:20 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2015-07-07 16:42:20 +0100
commitb30492792e87532c7ba45766cdb79e4d00c61822 (patch)
tree2bfb83b42b40f895966ba15f9139b4716044c46c
parent092d1eee88f7b1c0e083a0a4b9b5039d67e2ebfc (diff)
downloaddefinitions-b30492792e87532c7ba45766cdb79e4d00c61822.tar.gz
schema: Add tool to validate data against schema
This is a Java program that uses Apache Jena to do the validation. I've not yet found a Python tool which provides equivalent functionality. Change-Id: I2556387ae41f1c3f2160668eb14702df6016e729
-rw-r--r--schema/validate-jena/README17
-rw-r--r--schema/validate-jena/ValidateTool.java43
2 files changed, 60 insertions, 0 deletions
diff --git a/schema/validate-jena/README b/schema/validate-jena/README
new file mode 100644
index 00000000..dddfe013
--- /dev/null
+++ b/schema/validate-jena/README
@@ -0,0 +1,17 @@
+Validate RDF data according to a schema using Apache Jena
+---------------------------------------------------------
+
+To compile this you will need Apache Jena available, and a Java compiler.
+
+You can download a binary distribution of Apache Jena from
+<https://jena.apache.org/download/index.html>.
+
+Here is an example of fetching a version of Apache Jena, compiling the
+validation tool to a .class file with `javac` and running it with `java`:
+
+ wget http://mirrors.ukfast.co.uk/sites/ftp.apache.org/jena/binaries/apache-jena-2.13.0.tar.gz
+ tar xf apache-jena-2.13.0.tar.gz
+ javac -classpath ./apache-jena-2.13.0/lib/jena-core-2.13.0.jar \
+ ValidateTool.java
+ java -classpath ./apache-jena-2.13.0/lib/jena-core-2.13.0.jar:./apache-jena-2.13.0/lib/slf4j-api-1.7.6.jar:./apache-jena-2.13.0/lib/slf4j-log4j12-1.7.6.jar:./apache-jena-2.13.0/lib/log4j-1.2.17.jar:./apache-jena-2.13.0/lib/xercesImpl-2.11.0.jar:./apache-jena-2.13.0/lib/xml-apis-1.4.01.jar:./apache-jena-2.13.0/lib/jena-iri-1.1.2.jar:. \
+ ValidateTool
diff --git a/schema/validate-jena/ValidateTool.java b/schema/validate-jena/ValidateTool.java
new file mode 100644
index 00000000..274cf632
--- /dev/null
+++ b/schema/validate-jena/ValidateTool.java
@@ -0,0 +1,43 @@
+/* Tool to validate Baserock definitions data against the OWL schema.
+ *
+ * Based in part on:
+ *
+ * https://github.com/castagna/jena-examples/blob/master/src/main/java/org/apache/jena/examples/ExampleONT_02.java
+ */
+
+
+import java.util.Iterator;
+
+import com.hp.hpl.jena.rdf.model.InfModel;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.reasoner.Reasoner;
+import com.hp.hpl.jena.reasoner.ReasonerRegistry;
+import com.hp.hpl.jena.reasoner.ValidityReport;
+import com.hp.hpl.jena.util.FileManager;
+
+
+public class ValidateTool {
+ public static void main(String[] args) {
+ Model data = FileManager.get().loadModel(
+ "../definitions.rdfxml", null, "RDF/XML");
+ Model schema = FileManager.get().loadModel(
+ "../baserock-example.schema", null, "Turtle");
+
+ Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
+ reasoner = reasoner.bindSchema(schema.getGraph());
+
+ InfModel infmodel = ModelFactory.createInfModel(reasoner, data);
+
+ ValidityReport validity = infmodel.validate();
+
+ if (validity.isValid()) {
+ System.out.println("OK");
+ } else {
+ System.out.println("Conflicts");
+ for (Iterator i = validity.getReports(); i.hasNext(); ) {
+ System.out.println(" - " + i.next());
+ }
+ }
+ }
+}