aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/rsacomb/RSAOntology.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/rsacomb/RSAOntology.scala')
-rw-r--r--src/main/scala/rsacomb/RSAOntology.scala40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/main/scala/rsacomb/RSAOntology.scala b/src/main/scala/rsacomb/RSAOntology.scala
index ebe1591..92be118 100644
--- a/src/main/scala/rsacomb/RSAOntology.scala
+++ b/src/main/scala/rsacomb/RSAOntology.scala
@@ -1,6 +1,7 @@
1package rsacomb 1package rsacomb
2 2
3/* Java imports */ 3/* Java imports */
4import java.util.HashMap
4import java.util.stream.{Collectors,Stream} 5import java.util.stream.{Collectors,Stream}
5 6
6import org.semanticweb.owlapi.model.OWLOntology 7import org.semanticweb.owlapi.model.OWLOntology
@@ -8,13 +9,17 @@ import org.semanticweb.owlapi.model.OWLObjectPropertyExpression
8import org.semanticweb.owlapi.model.parameters.Imports 9import org.semanticweb.owlapi.model.parameters.Imports
9import org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory 10import org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory
10 11
12import tech.oxfordsemantic.jrdfox.Prefixes
11import tech.oxfordsemantic.jrdfox.logic.Variable 13import tech.oxfordsemantic.jrdfox.logic.Variable
14import tech.oxfordsemantic.jrdfox.client.UpdateType
15
12 16
13/* Scala imports */ 17/* Scala imports */
14import scala.collection.JavaConverters._ 18import scala.collection.JavaConverters._
15 19
16/* Debug only */ 20/* Debug only */
17import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer 21import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer
22import java.io.OutputStream
18 23
19/* Wrapper trait for the implicit class `RSAOntology`. 24/* Wrapper trait for the implicit class `RSAOntology`.
20 */ 25 */
@@ -48,12 +53,41 @@ trait RSAOntology {
48 tbox.foreach(x => println(renderer.render(x))) 53 tbox.foreach(x => println(renderer.render(x)))
49 54
50 /* Ontology convertion into LP rules */ 55 /* Ontology convertion into LP rules */
51 println("\nLP rules:") 56 val datalog = for {
52 for {
53 axiom <- tbox 57 axiom <- tbox
54 visitor = new RDFoxAxiomConverter(Variable.create("x"), SkolemStrategy.ConstantRSA(axiom.toString), unsafe) 58 visitor = new RDFoxAxiomConverter(Variable.create("x"), SkolemStrategy.ConstantRSA(axiom.toString), unsafe)
55 rule <- axiom.accept(visitor) 59 rule <- axiom.accept(visitor)
56 } yield println(rule) 60 } yield rule
61
62 val prefixes = new Prefixes()
63 prefixes.declarePrefix(":", "http://example.com/rsa_example.owl#")
64
65 // Open connection with RDFox
66 val (server,data) = RDFox.openConnection("RSACheck")
67 // Add Data (hardcoded for now)
68 data.importData(UpdateType.ADDITION, prefixes,":a a :A .")
69 /* Add Datalog rules
70 *
71 * NOTE:
72 * - using the `addRules(...)` method in `DataStoreConnection` is not working as expected, complaining
73 * about missing TupleTable entries;
74 * - weirdly enough, the same error is returned when trying to pass the rules to the `importData` method,
75 * simply turning them into strings. It seems like the `toString` implementation of `Rule` uses parenthesis
76 * for predicate arguments (e.g., `<predicate>(?X,?Y)`) while the specification for the proprietary RDFox
77 * syntax uses squared brackets (e.g., `<preditate>[?X,?Y]`).
78 */
79 data.importData(
80 UpdateType.ADDITION,
81 prefixes,
82 datalog.foldLeft("")((str,rule) => str ++ "\n" ++ rule.toString().replace("(", "[").replace(")","]"))
83 )
84
85 // Retrieve all instances of PE
86 println("\nQuery results:")
87 data.evaluateQuery(prefixes,"SELECT ?X ?Y WHERE { ?X <internal:PE> ?Y }", new HashMap[String,String](), System.out, "text/csv");
88
89 // Close connection to RDFox
90 RDFox.closeConnection(server,data)
57 91
58 /* DEBUG */ 92 /* DEBUG */
59 true 93 true