summaryrefslogtreecommitdiff
path: root/rules/src/main/java
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2018-08-20 23:28:00 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2018-08-20 23:28:00 +0200
commitec429f152cf1d32a86f5783ed87453b42f7ef190 (patch)
treee872b07b9c59fc911dff06c0fe9abcc69f763405 /rules/src/main/java
parent61bbddad93ada8f877c26b8d748c8326085d3e3a (diff)
downloadsemantic-sandbox-master.tar.gz
semantic-sandbox-master.tar.bz2
semantic-sandbox-master.tar.xz
semantic-sandbox-master.zip
o Better STM32 setup.HEADmaster
Diffstat (limited to 'rules/src/main/java')
-rw-r--r--rules/src/main/java/io/trygvis/semantic/Main.java88
1 files changed, 88 insertions, 0 deletions
diff --git a/rules/src/main/java/io/trygvis/semantic/Main.java b/rules/src/main/java/io/trygvis/semantic/Main.java
new file mode 100644
index 0000000..9c8e9c6
--- /dev/null
+++ b/rules/src/main/java/io/trygvis/semantic/Main.java
@@ -0,0 +1,88 @@
+package io.trygvis.semantic;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Iterator;
+
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.query.Dataset;
+import org.apache.jena.query.QueryExecution;
+import org.apache.jena.query.QueryExecutionFactory;
+import org.apache.jena.query.QuerySolution;
+import org.apache.jena.query.ReadWrite;
+import org.apache.jena.query.ResultSet;
+import org.apache.jena.rdf.model.InfModel;
+import org.apache.jena.rdf.model.Model;
+import org.apache.jena.rdf.model.ModelFactory;
+import org.apache.jena.rdf.model.Property;
+import org.apache.jena.rdf.model.RDFNode;
+import org.apache.jena.rdf.model.Resource;
+import org.apache.jena.rdf.model.Statement;
+import org.apache.jena.rdf.model.StmtIterator;
+import org.apache.jena.reasoner.Derivation;
+import org.apache.jena.reasoner.Reasoner;
+import org.apache.jena.reasoner.rulesys.Builtin;
+import org.apache.jena.reasoner.rulesys.BuiltinRegistry;
+import org.apache.jena.reasoner.rulesys.GenericRuleReasoner;
+import org.apache.jena.reasoner.rulesys.MapBuiltinRegistry;
+import org.apache.jena.reasoner.rulesys.Rule;
+import org.apache.jena.riot.RDFDataMgr;
+import org.apache.jena.riot.RDFFormat;
+import org.apache.jena.tdb2.TDB2Factory;
+import org.apache.jena.update.UpdateExecutionFactory;
+import org.apache.jena.update.UpdateFactory;
+import org.apache.jena.update.UpdateProcessor;
+import org.apache.jena.update.UpdateRequest;
+import org.apache.jena.util.PrintUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+
+public class Main {
+ private static Logger logger = LoggerFactory.getLogger(Main.class);
+ // Why This Failure marker
+ private static final Marker WTF_MARKER = MarkerFactory.getMarker("WTF");
+
+ public static void main(String[] args) {
+ try {
+ Path path = Paths.get(".").toAbsolutePath().normalize();
+
+ // Load RDF data
+ String data = Paths.get(args[0]).toUri().toString(); // path.toFile().getAbsolutePath() + "/src/main/resources/data1.ttl";
+ Model model = ModelFactory.createDefaultModel();
+ model.read(data);
+
+ // Load rules
+ String rules = args[1]; // path.toFile().getAbsolutePath() + "/src/main/resources/student1.rules";
+ Reasoner reasoner = new GenericRuleReasoner(Rule.rulesFromURL(rules));
+
+ InfModel infModel = ModelFactory.createInfModel(reasoner, model);
+ infModel.setDerivationLogging(true);
+ infModel.validate();
+ List<Statement> stmts = infModel.listStatements().toList();
+
+ Model dm = infModel.getDeductionsModel();
+
+ /*
+ if (true) {
+ logger.info("# statements = " + stmts.size());
+ logger.info("dm.size() = " + dm.size());
+ } else {
+ for (StmtIterator i = infModel.listStatements(); i.hasNext(); ) {
+ Statement stmt = i.nextStatement();
+ logger.trace("Statememt = " + PrintUtil.print(stmt));
+ }
+ }
+ */
+ logger.info("Inferred data");
+ for (StmtIterator i = dm.listStatements(); i.hasNext(); ) {
+ Statement stmt = i.nextStatement();
+ logger.trace("Statememt = " + PrintUtil.print(stmt));
+ }
+ } catch (Throwable t) {
+ logger.error(WTF_MARKER, t.getMessage(), t);
+ }
+ }
+}