summaryrefslogtreecommitdiff
path: root/rules/src
diff options
context:
space:
mode:
Diffstat (limited to 'rules/src')
-rw-r--r--rules/src/main/java/io/trygvis/semantic/Main.java88
-rw-r--r--rules/src/main/resources/log4j2.xml26
2 files changed, 114 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);
+ }
+ }
+}
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Configuration package="log4j.test" status="WARN">
+<Appenders>
+ <Console name="Console" target="SYSTEM_OUT">
+ <PatternLayout pattern="%markerSimpleName %-5p %C.%M():%L - %msg %ex{full}%n"/>
+ </Console>
+ <File name="Log" fileName="./logs/App.log">
+ <PatternLayout>
+ <Pattern>%markerSimpleName %-5p %C.%M():%L - %msg %ex{full}%n</Pattern>
+ </PatternLayout>
+ </File>
+</Appenders>
+<Loggers>
+ <Root level="trace">
+ <AppenderRef ref="Console"/>
+ <AppenderRef ref="Log"/>
+ </Root>
+ <!--<Logger name="root" level="trace" additivity="false">
+ <AppenderRef ref="Console"/>
+ </Logger>
+ <Logger name="root" level="trace" additivity="false">
+ <AppenderRef ref="Console"/>
+ <AppenderRef ref="Log"/>
+ </Logger>-->
+</Loggers>
+</Configuration>