aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/rsacomb/RSAComb.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/rsacomb/RSAComb.scala')
-rw-r--r--src/main/scala/rsacomb/RSAComb.scala138
1 files changed, 138 insertions, 0 deletions
diff --git a/src/main/scala/rsacomb/RSAComb.scala b/src/main/scala/rsacomb/RSAComb.scala
new file mode 100644
index 0000000..bc94a8d
--- /dev/null
+++ b/src/main/scala/rsacomb/RSAComb.scala
@@ -0,0 +1,138 @@
1package rsacomb
2
3import java.io.File
4import java.util.HashMap
5import java.util.stream.{Stream,Collectors}
6
7import org.semanticweb.owlapi.apibinding.OWLManager
8import org.semanticweb.owlapi.model.{AxiomType, ClassExpressionType, OWLObjectSomeValuesFrom}
9import org.semanticweb.owlapi.model.{OWLAxiom, OWLSubClassOfAxiom, OWLEquivalentClassesAxiom}
10import org.semanticweb.owlapi.model.OWLClassExpression
11import org.semanticweb.owlapi.model.OWLOntology
12import org.semanticweb.owlapi.model.OWLOntologyManager
13import org.semanticweb.owlapi.model.parameters.Imports
14
15import tech.oxfordsemantic.jrdfox.Prefixes
16import tech.oxfordsemantic.jrdfox.client.{ConnectionFactory, ServerConnection, DataStoreConnection}
17import tech.oxfordsemantic.jrdfox.client.UpdateType
18import tech.oxfordsemantic.jrdfox.logic.{Rule, Atom, Literal, Predicate, Term, Variable}
19import tech.oxfordsemantic.jrdfox.logic.{Bind, BuiltinFunctionCall}
20
21import scala.collection.JavaConverters._
22
23import rsacomb.SkolemStrategy
24
25class RSA(ontology : OWLOntology) {
26
27 /* Alternative constructor(s) */
28 def this(file : File) = this(RSA.loadOntology(file))
29
30 def getOntology : OWLOntology = ontology
31
32} // class RSA
33
34object RSA {
35
36 def loadOntology( onto : File ) : OWLOntology = {
37 /* Retrieve ontology manager */
38 val manager : OWLOntologyManager = OWLManager.createOWLOntologyManager()
39 /* Retrieve ontology */
40 manager.loadOntologyFromOntologyDocument(onto)
41 }
42
43 def isRSA( onto : OWLOntology ) : Boolean = {
44 /* TODO: Steps for RSA check
45 * 1) convert ontology axioms into LP rules
46 * 2) call RDFox on the onto and compute materialization
47 * 3) build graph from E(x,y) facts
48 * 4) check if the graph is tree-like
49 */
50
51 /* Ontology axiom convertion into LP rules */
52 for {
53 axiom <- onto.tboxAxioms(Imports.EXCLUDED).collect(Collectors.toList()).asScala
54 visitor = new RDFoxAxiomConverter(Variable.create("x"), SkolemStrategy.Constant(axiom.toString))
55 rule <- axiom.accept(visitor)
56 } yield println(rule)
57
58 /* Return true for now... */
59 true
60 }
61
62} // object RSA
63
64object RSAComb {
65
66 val help : String = """
67 rsacomb - combined approach for CQ answering for RSA ontologies.
68
69 USAGE
70 rsacomb <path/to/ontology.owl> <path/to/query.sparql>
71
72 where
73 the ontology is expected to be an OWL file and the (single)
74 query a SPARQL query file.
75 """
76
77 def main( args : Array[String] ) : Unit = {
78
79 /* Simple arguments handling
80 *
81 * TODO: use something better later on
82 */
83
84 if (args.length < 2) {
85 println(help)
86 return ()
87 }
88
89 val ontologyPath = new File(args(0))
90 val queryPath = new File(args(1))
91
92 if (!ontologyPath.isFile || !queryPath.isFile) {
93 println("The provided arguments are not regular files.\n\n")
94 println(help)
95 return ()
96 }
97
98 /* Create RSA object from generic OWLOntology
99 *
100 * TODO: It might be required to check if the ontology in input is
101 * Horn-ALCHOIQ. At the moment we are assuming this is always the
102 * case.
103 */
104 val rsa = new RSA(ontologyPath)
105 RSA.isRSA(rsa.getOntology)
106
107 /* Build canonical model */
108 //val tboxCanon = rsa.canonicalModel()
109
110 /* Load query */
111 //val query = ...
112
113 /* Compute the filtering program from the given query */
114 //val tboxFilter = rsa.filteringProgram(query)
115
116 /* ... */
117
118 /* DEBUG ONLY */
119 println("Ok!")
120 }
121}
122
123/* Notes:
124 *
125 * To establish a connection with a local RDFox instance, do the
126 * following:
127 *
128 * ```
129 * val serverConnection : ServerConnection = ConnectionFactory.newServerConnection("rdfox:local", "", "")
130 * serverConnection.createDataStore("test","seq",new HashMap())
131 * val dataStoreConnection : DataStoreConnection = serverConnection.newDataStoreConnection("test")
132 * dataStoreConnection.importData(
133 * UpdateType.ADDITION,
134 * Prefixes.s_emptyPrefixes,
135 * new File("./path/to/file")
136 * )
137 * ```
138 */