summaryrefslogtreecommitdiff
path: root/rules
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
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')
-rw-r--r--rules/.gitignore2
-rw-r--r--rules/pom.xml72
-rw-r--r--rules/src/main/java/io/trygvis/semantic/Main.java88
-rw-r--r--rules/src/main/resources/log4j2.xml26
4 files changed, 188 insertions, 0 deletions
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 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>io.trygvis.semantic</groupId>
+ <artifactId>semantic-sandbox</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <maven.compiler.source>1.8</maven.compiler.source>
+ <maven.compiler.target>1.8</maven.compiler.target>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <version>2.6.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <version>2.6.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <version>2.6.2</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.12</version>
+ <scope>test</scope>
+ </dependency>
+ <!-- https://mvnrepository.com/artifact/org.apache.jena/apache-jena-libs -->
+ <dependency>
+ <groupId>org.apache.jena</groupId>
+ <artifactId>apache-jena-libs</artifactId>
+ <version>3.8.0</version>
+ <type>pom</type>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>appassembler-maven-plugin</artifactId>
+ <version>1.10</version>
+ <executions>
+ <execution>
+ <id>assemble</id>
+ <phase>package</phase>
+ <goals>
+ <goal>assemble</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <programs>
+ <program>
+ <mainClass>io.trygvis.semantic.Main</mainClass>
+ <id>rules</id>
+ </program>
+ </programs>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
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>