From ec429f152cf1d32a86f5783ed87453b42f7ef190 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 20 Aug 2018 23:28:00 +0200 Subject: o Better STM32 setup. --- rules/.gitignore | 2 + rules/pom.xml | 72 +++++++++++++++++++ rules/src/main/java/io/trygvis/semantic/Main.java | 88 +++++++++++++++++++++++ rules/src/main/resources/log4j2.xml | 26 +++++++ 4 files changed, 188 insertions(+) create mode 100644 rules/.gitignore create mode 100644 rules/pom.xml create mode 100644 rules/src/main/java/io/trygvis/semantic/Main.java create mode 100644 rules/src/main/resources/log4j2.xml (limited to 'rules') diff --git a/rules/.gitignore b/rules/.gitignore new file mode 100644 index 0000000..3a247a3 --- /dev/null +++ b/rules/.gitignore @@ -0,0 +1,2 @@ +logs +target diff --git a/rules/pom.xml b/rules/pom.xml new file mode 100644 index 0000000..ff7b8b3 --- /dev/null +++ b/rules/pom.xml @@ -0,0 +1,72 @@ + + 4.0.0 + + io.trygvis.semantic + semantic-sandbox + 0.0.1-SNAPSHOT + + + UTF-8 + 1.8 + 1.8 + + + + + org.apache.logging.log4j + log4j-api + 2.6.2 + + + org.apache.logging.log4j + log4j-core + 2.6.2 + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.6.2 + + + junit + junit + 4.12 + test + + + + org.apache.jena + apache-jena-libs + 3.8.0 + pom + + + + + + + org.codehaus.mojo + appassembler-maven-plugin + 1.10 + + + assemble + package + + assemble + + + + + + + io.trygvis.semantic.Main + rules + + + + + + + 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 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); + } + } +} diff --git a/rules/src/main/resources/log4j2.xml b/rules/src/main/resources/log4j2.xml new file mode 100644 index 0000000..e4f29d0 --- /dev/null +++ b/rules/src/main/resources/log4j2.xml @@ -0,0 +1,26 @@ + + + + + + + + + %markerSimpleName %-5p %C.%M():%L - %msg %ex{full}%n + + + + + + + + + + + -- cgit v1.2.3