diff options
author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-11-05 20:00:34 +0000 |
---|---|---|
committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-11-05 20:00:34 +0000 |
commit | 360675d5b659ba8e9e5fe83dfa038d27f962b4de (patch) | |
tree | 38e21ad6270da7c85f1d0069ced18dd9aea12045 /src | |
parent | 6df3ffe815a5ea65da92e818c1eb48fca13bc5ce (diff) | |
download | RSAComb-360675d5b659ba8e9e5fe83dfa038d27f962b4de.tar.gz RSAComb-360675d5b659ba8e9e5fe83dfa038d27f962b4de.zip |
Update code to RDFox v4.0
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala/rsacomb/CanonicalModel.scala | 73 | ||||
-rw-r--r-- | src/main/scala/rsacomb/FilteringProgram.scala | 214 | ||||
-rw-r--r-- | src/main/scala/rsacomb/RDFTriple.scala | 33 | ||||
-rw-r--r-- | src/main/scala/rsacomb/RDFoxAxiomConverter.scala | 12 | ||||
-rw-r--r-- | src/main/scala/rsacomb/RDFoxClassExprConverter.scala | 25 | ||||
-rw-r--r-- | src/main/scala/rsacomb/RDFoxPropertyExprConverter.scala | 15 | ||||
-rw-r--r-- | src/main/scala/rsacomb/RDFoxRuleShards.scala | 5 | ||||
-rw-r--r-- | src/main/scala/rsacomb/RDFoxUtil.scala | 19 | ||||
-rw-r--r-- | src/main/scala/rsacomb/RSA.scala | 10 | ||||
-rw-r--r-- | src/main/scala/rsacomb/RSAOntology.scala | 11 | ||||
-rw-r--r-- | src/main/scala/rsacomb/SkolemStrategy.scala | 2 |
11 files changed, 247 insertions, 172 deletions
diff --git a/src/main/scala/rsacomb/CanonicalModel.scala b/src/main/scala/rsacomb/CanonicalModel.scala index cc89a85..fcc404a 100644 --- a/src/main/scala/rsacomb/CanonicalModel.scala +++ b/src/main/scala/rsacomb/CanonicalModel.scala | |||
@@ -9,14 +9,14 @@ import org.semanticweb.owlapi.model.{ | |||
9 | OWLObjectPropertyExpression, | 9 | OWLObjectPropertyExpression, |
10 | OWLObjectSomeValuesFrom | 10 | OWLObjectSomeValuesFrom |
11 | } | 11 | } |
12 | import tech.oxfordsemantic.jrdfox.logic.{ | 12 | import tech.oxfordsemantic.jrdfox.logic.Datatype |
13 | IRI, | 13 | import tech.oxfordsemantic.jrdfox.logic.expression.{IRI, Term, Variable} |
14 | import tech.oxfordsemantic.jrdfox.logic.datalog.{ | ||
14 | BodyFormula, | 15 | BodyFormula, |
15 | Atom, | 16 | TupleTableAtom, |
16 | Rule, | 17 | Rule |
17 | Term, | ||
18 | Variable | ||
19 | } | 18 | } |
19 | |||
20 | import scala.collection.JavaConverters._ | 20 | import scala.collection.JavaConverters._ |
21 | import rsacomb.RSA._ | 21 | import rsacomb.RSA._ |
22 | 22 | ||
@@ -36,28 +36,35 @@ object ProgramGenerator { | |||
36 | val varY = Variable.create("Y") | 36 | val varY = Variable.create("Y") |
37 | List( | 37 | List( |
38 | Rule.create( | 38 | Rule.create( |
39 | Atom.rdf(varX, IRI.create(pred), varY), | 39 | TupleTableAtom.rdf(varX, IRI.create(pred), varY), |
40 | Atom.rdf(varX, IRI.create(pred ++ RSASuffix.Forward.getSuffix), varY) | 40 | TupleTableAtom |
41 | .rdf(varX, IRI.create(pred ++ RSASuffix.Forward.getSuffix), varY) | ||
41 | ), | 42 | ), |
42 | Rule.create( | 43 | Rule.create( |
43 | Atom.rdf(varX, IRI.create(pred), varY), | 44 | TupleTableAtom.rdf(varX, IRI.create(pred), varY), |
44 | Atom.rdf(varX, IRI.create(pred ++ RSASuffix.Backward.getSuffix), varY) | 45 | TupleTableAtom |
46 | .rdf(varX, IRI.create(pred ++ RSASuffix.Backward.getSuffix), varY) | ||
45 | ), | 47 | ), |
46 | Rule.create( | 48 | Rule.create( |
47 | Atom.rdf( | 49 | TupleTableAtom.rdf( |
48 | varY, | 50 | varY, |
49 | IRI.create(pred ++ RSASuffix.Backward.getSuffix ++ "_inv"), | 51 | IRI.create(pred ++ RSASuffix.Backward.getSuffix ++ "_inv"), |
50 | varX | 52 | varX |
51 | ), | 53 | ), |
52 | Atom.rdf(varX, IRI.create(pred ++ RSASuffix.Forward.getSuffix), varY) | 54 | TupleTableAtom |
55 | .rdf(varX, IRI.create(pred ++ RSASuffix.Forward.getSuffix), varY) | ||
53 | ), | 56 | ), |
54 | Rule.create( | 57 | Rule.create( |
55 | Atom.rdf( | 58 | TupleTableAtom.rdf( |
56 | varY, | 59 | varY, |
57 | IRI.create(pred ++ RSASuffix.Forward.getSuffix ++ "_inv"), | 60 | IRI.create(pred ++ RSASuffix.Forward.getSuffix ++ "_inv"), |
58 | varX | 61 | varX |
59 | ), | 62 | ), |
60 | Atom.rdf(varX, IRI.create(pred ++ RSASuffix.Backward.getSuffix), varY) | 63 | TupleTableAtom.rdf( |
64 | varX, | ||
65 | IRI.create(pred ++ RSASuffix.Backward.getSuffix), | ||
66 | varY | ||
67 | ) | ||
61 | ) | 68 | ) |
62 | ) | 69 | ) |
63 | } | 70 | } |
@@ -67,8 +74,8 @@ object ProgramGenerator { | |||
67 | .toList | 74 | .toList |
68 | } | 75 | } |
69 | 76 | ||
70 | def NIs(individuals: List[IRI]): List[Atom] = | 77 | def NIs(individuals: List[IRI]): List[TupleTableAtom] = |
71 | individuals.map(Atom.rdf(_, IRI.RDF_TYPE, RSA.internal("NI"))) | 78 | individuals.map(TupleTableAtom.rdf(_, IRI.RDF_TYPE, RSA.internal("NI"))) |
72 | 79 | ||
73 | } | 80 | } |
74 | 81 | ||
@@ -91,18 +98,18 @@ class ProgramGenerator( | |||
91 | val v0 = IRI.create("v0_" ++ axiom.hashCode.toString) | 98 | val v0 = IRI.create("v0_" ++ axiom.hashCode.toString) |
92 | val varX = Variable.create("X") | 99 | val varX = Variable.create("X") |
93 | // Predicates | 100 | // Predicates |
94 | val atomA: Atom = { | 101 | val atomA: TupleTableAtom = { |
95 | val cls = axiom.getSubClass.asInstanceOf[OWLClass].getIRI | 102 | val cls = axiom.getSubClass.asInstanceOf[OWLClass].getIRI |
96 | Atom.rdf(varX, IRI.RDF_TYPE, cls) | 103 | TupleTableAtom.rdf(varX, IRI.RDF_TYPE, cls) |
97 | } | 104 | } |
98 | def notIn(t: Term): Atom = { | 105 | def notIn(t: Term): TupleTableAtom = { |
99 | Atom.rdf( | 106 | TupleTableAtom.rdf( |
100 | t, | 107 | t, |
101 | RSA.internal("notIn"), | 108 | RSA.internal("notIn"), |
102 | RSA.internal(unfold.hashCode.toString) | 109 | RSA.internal(unfold.hashCode.toString) |
103 | ) | 110 | ) |
104 | } | 111 | } |
105 | val roleRf: Atom = { | 112 | val roleRf: TupleTableAtom = { |
106 | val visitor = | 113 | val visitor = |
107 | new RDFoxPropertyExprConverter(varX, v0, RSASuffix.Forward) | 114 | new RDFoxPropertyExprConverter(varX, v0, RSASuffix.Forward) |
108 | axiom.getSuperClass | 115 | axiom.getSuperClass |
@@ -111,13 +118,13 @@ class ProgramGenerator( | |||
111 | .accept(visitor) | 118 | .accept(visitor) |
112 | .head | 119 | .head |
113 | } | 120 | } |
114 | val atomB: Atom = { | 121 | val atomB: TupleTableAtom = { |
115 | val cls = axiom.getSuperClass | 122 | val cls = axiom.getSuperClass |
116 | .asInstanceOf[OWLObjectSomeValuesFrom] | 123 | .asInstanceOf[OWLObjectSomeValuesFrom] |
117 | .getFiller | 124 | .getFiller |
118 | .asInstanceOf[OWLClass] | 125 | .asInstanceOf[OWLClass] |
119 | .getIRI | 126 | .getIRI |
120 | Atom.rdf(v0, IRI.RDF_TYPE, cls) | 127 | TupleTableAtom.rdf(v0, IRI.RDF_TYPE, cls) |
121 | } | 128 | } |
122 | // TODO: To be consistent with the specifics of the visitor we are | 129 | // TODO: To be consistent with the specifics of the visitor we are |
123 | // returning facts as `Rule`s with true body. While this is correct | 130 | // returning facts as `Rule`s with true body. While this is correct |
@@ -142,21 +149,21 @@ class ProgramGenerator( | |||
142 | val v1 = IRI.create("v1_" ++ axiom.hashCode.toString) | 149 | val v1 = IRI.create("v1_" ++ axiom.hashCode.toString) |
143 | val v2 = IRI.create("v2_" ++ axiom.hashCode.toString) | 150 | val v2 = IRI.create("v2_" ++ axiom.hashCode.toString) |
144 | // Predicates | 151 | // Predicates |
145 | def atomA(t: Term): Atom = { | 152 | def atomA(t: Term): TupleTableAtom = { |
146 | val cls = axiom.getSubClass.asInstanceOf[OWLClass].getIRI | 153 | val cls = axiom.getSubClass.asInstanceOf[OWLClass].getIRI |
147 | Atom.rdf(t, IRI.RDF_TYPE, cls) | 154 | TupleTableAtom.rdf(t, IRI.RDF_TYPE, cls) |
148 | } | 155 | } |
149 | def roleRf(t1: Term, t2: Term): Atom = { | 156 | def roleRf(t1: Term, t2: Term): TupleTableAtom = { |
150 | val visitor = new RDFoxPropertyExprConverter(t1, t2, RSASuffix.Forward) | 157 | val visitor = new RDFoxPropertyExprConverter(t1, t2, RSASuffix.Forward) |
151 | roleR.accept(visitor).head | 158 | roleR.accept(visitor).head |
152 | } | 159 | } |
153 | def atomB(t: Term): Atom = { | 160 | def atomB(t: Term): TupleTableAtom = { |
154 | val cls = axiom.getSuperClass | 161 | val cls = axiom.getSuperClass |
155 | .asInstanceOf[OWLObjectSomeValuesFrom] | 162 | .asInstanceOf[OWLObjectSomeValuesFrom] |
156 | .getFiller | 163 | .getFiller |
157 | .asInstanceOf[OWLClass] | 164 | .asInstanceOf[OWLClass] |
158 | .getIRI | 165 | .getIRI |
159 | Atom.rdf(t, IRI.RDF_TYPE, cls) | 166 | TupleTableAtom.rdf(t, IRI.RDF_TYPE, cls) |
160 | } | 167 | } |
161 | //Rules | 168 | //Rules |
162 | List( | 169 | List( |
@@ -179,22 +186,22 @@ class ProgramGenerator( | |||
179 | // Fresh Variables | 186 | // Fresh Variables |
180 | val v1 = IRI.create("v1_" ++ axiom.hashCode.toString) | 187 | val v1 = IRI.create("v1_" ++ axiom.hashCode.toString) |
181 | // Predicates | 188 | // Predicates |
182 | def atomA(t: Term): Atom = { | 189 | def atomA(t: Term): TupleTableAtom = { |
183 | val cls = axiom.getSubClass.asInstanceOf[OWLClass].getIRI | 190 | val cls = axiom.getSubClass.asInstanceOf[OWLClass].getIRI |
184 | Atom.rdf(t, IRI.RDF_TYPE, cls) | 191 | TupleTableAtom.rdf(t, IRI.RDF_TYPE, cls) |
185 | } | 192 | } |
186 | def roleRf(t: Term): Atom = { | 193 | def roleRf(t: Term): TupleTableAtom = { |
187 | val visitor = | 194 | val visitor = |
188 | new RDFoxPropertyExprConverter(t, v1, RSASuffix.Forward) | 195 | new RDFoxPropertyExprConverter(t, v1, RSASuffix.Forward) |
189 | roleR.accept(visitor).head | 196 | roleR.accept(visitor).head |
190 | } | 197 | } |
191 | val atomB: Atom = { | 198 | val atomB: TupleTableAtom = { |
192 | val cls = axiom.getSuperClass | 199 | val cls = axiom.getSuperClass |
193 | .asInstanceOf[OWLObjectSomeValuesFrom] | 200 | .asInstanceOf[OWLObjectSomeValuesFrom] |
194 | .getFiller | 201 | .getFiller |
195 | .asInstanceOf[OWLClass] | 202 | .asInstanceOf[OWLClass] |
196 | .getIRI | 203 | .getIRI |
197 | Atom.rdf(v1, IRI.RDF_TYPE, cls) | 204 | TupleTableAtom.rdf(v1, IRI.RDF_TYPE, cls) |
198 | } | 205 | } |
199 | cycle.flatMap { x => | 206 | cycle.flatMap { x => |
200 | List( | 207 | List( |
diff --git a/src/main/scala/rsacomb/FilteringProgram.scala b/src/main/scala/rsacomb/FilteringProgram.scala index 9c19b7f..dc5e95e 100644 --- a/src/main/scala/rsacomb/FilteringProgram.scala +++ b/src/main/scala/rsacomb/FilteringProgram.scala | |||
@@ -1,93 +1,130 @@ | |||
1 | package rsacomb | 1 | package rsacomb |
2 | 2 | ||
3 | import tech.oxfordsemantic.jrdfox.logic._ | 3 | import tech.oxfordsemantic.jrdfox.logic.Datatype |
4 | import tech.oxfordsemantic.jrdfox.logic.expression.{ | ||
5 | Term, | ||
6 | IRI, | ||
7 | Variable, | ||
8 | Literal, | ||
9 | FunctionCall | ||
10 | } | ||
11 | import tech.oxfordsemantic.jrdfox.logic.datalog.{ | ||
12 | Rule, | ||
13 | TupleTableAtom, | ||
14 | BindAtom, | ||
15 | TupleTableName, | ||
16 | BodyFormula, | ||
17 | Negation | ||
18 | } | ||
19 | import tech.oxfordsemantic.jrdfox.logic.sparql.statement.{SelectQuery} | ||
20 | import tech.oxfordsemantic.jrdfox.logic.sparql.pattern.{ | ||
21 | GroupGraphPattern, | ||
22 | ConjunctionPattern, | ||
23 | TriplePattern, | ||
24 | QueryPattern | ||
25 | } | ||
26 | |||
4 | import scala.collection.JavaConverters._ | 27 | import scala.collection.JavaConverters._ |
5 | 28 | ||
6 | class FilteringProgram(query: Query, constants: List[Term]) extends RDFTriple { | 29 | class FilteringProgram(query: SelectQuery, constants: List[Term]) |
30 | extends RDFTriple { | ||
7 | 31 | ||
8 | /* Makes mplicit conversion OWLAPI IRI <-> RDFox IRI available */ | 32 | /* Makes mplicit conversion OWLAPI IRI <-> RDFox IRI available */ |
9 | import RDFoxUtil._ | 33 | import RDFoxUtil._ |
10 | 34 | ||
11 | val answer: List[Term] = query.getAnswerVariables.asScala.toList | 35 | val answer: List[Term] = query.getSelection.asScala.map(_.getVariable).toList |
12 | val bounded: List[Term] = this.getBoundedVariables | 36 | val bounded: List[Term] = this.getBoundedVariables |
13 | 37 | ||
14 | val facts: List[Atom] = constants.map(named) | 38 | val facts: List[TupleTableAtom] = constants.map(named) |
15 | val rules: List[Rule] = this.generateFilteringProgram().map(reifyRule) | 39 | val rules: List[Rule] = this.generateFilteringProgram().map(reifyRule) |
16 | 40 | ||
17 | private def named(t: Term): Atom = | 41 | private def named(t: Term): TupleTableAtom = |
18 | Atom.rdf(t, IRI.RDF_TYPE, RSA.internal("NAMED")) | 42 | TupleTableAtom.rdf( |
43 | t, | ||
44 | IRI.RDF_TYPE, | ||
45 | RSA.internal("NAMED") | ||
46 | ) | ||
19 | 47 | ||
20 | private def getBoundedVariables: List[Term] = { | 48 | private def getBoundedVariables: List[Term] = { |
21 | def extract(f: Formula): Set[Term] = { | 49 | def extract(body: GroupGraphPattern): Set[Term] = { |
22 | f match { | 50 | body match { |
23 | case b: BodyFormula => | 51 | case b: ConjunctionPattern => { |
24 | b.getArguments() | 52 | b.getConjuncts.asScala.toSet.flatMap { conj: QueryPattern => |
25 | .asScala | 53 | conj match { |
26 | .filter(_.isInstanceOf[Variable]) | 54 | case c: TriplePattern => |
27 | .filterNot(answer.contains(_)) | 55 | Set(c.getSubject, c.getPredicate, c.getObject).filter( |
28 | .toSet | 56 | _.isInstanceOf[Variable] |
29 | case c: Conjunction => | 57 | ) |
30 | c.getConjuncts().asScala.flatMap(extract).toSet | 58 | case _ => Set() |
31 | case d: Disjunction => | 59 | } |
32 | d.getDisjuncts().asScala.flatMap(extract).toSet | 60 | } |
33 | /* Ignoring Minus, Optional, Query, Values cases for now */ | 61 | } |
34 | case _ => Set() | 62 | case _ => Set() |
35 | } | 63 | } |
36 | } | 64 | } |
37 | extract(query.getQueryFormula()).toList | 65 | extract(query.getQueryBody.getWherePattern).toList |
38 | } | 66 | } |
39 | 67 | ||
40 | /* NOTE: we are restricting to queries that contain conjunctions of | 68 | /* NOTE: we are restricting to queries that contain conjunctions of |
41 | * atoms for the time being. This might need to be reviewed in the | 69 | * atoms for the time being. This might need to be reviewed in the |
42 | * future. | 70 | * future. |
43 | */ | 71 | */ |
44 | private def queryToBody(body: Formula): List[Atom] = | 72 | private def queryToBody(body: GroupGraphPattern): List[TupleTableAtom] = |
45 | body match { | 73 | body match { |
46 | case a: Atom => List(a); | 74 | case b: ConjunctionPattern => { |
47 | case a: Conjunction => | 75 | val conjuncts = b.getConjuncts.asScala.toList |
48 | a.getConjuncts.asScala.toList.flatMap(queryToBody); | 76 | conjuncts flatMap { conj => |
77 | conj match { | ||
78 | case c: TriplePattern => | ||
79 | List( | ||
80 | TupleTableAtom.rdf(c.getSubject, c.getPredicate, c.getObject) | ||
81 | ) | ||
82 | case _ => List() | ||
83 | } | ||
84 | } | ||
85 | } | ||
49 | case _ => List() | 86 | case _ => List() |
50 | } | 87 | } |
51 | 88 | ||
52 | private def generateFilteringProgram(): List[Rule] = { | 89 | private def generateFilteringProgram(): List[Rule] = { |
53 | // Query formula as a rule body | 90 | // Query formula as a rule body |
54 | val body = queryToBody(query.getQueryFormula) | 91 | val body = queryToBody(query.getQueryBody.getWherePattern) |
55 | // Auxiliar predicates/helpers | 92 | // Auxiliar predicates/helpers |
56 | def not(atom: Atom): BodyFormula = Negation.create(atom) | 93 | def not(atom: TupleTableAtom): BodyFormula = Negation.create(atom) |
57 | val predQM = | 94 | val predQM = |
58 | Atom.create( | 95 | TupleTableAtom.create( |
59 | TupleTableName.create(RSA.internal("QM").getIRI), | 96 | TupleTableName.create(RSA.internal("QM").getIRI), |
60 | (answer ++ bounded): _* | 97 | (answer ++ bounded): _* |
61 | ) | 98 | ) |
62 | def predID(t1: Term, t2: Term) = | 99 | def predID(t1: Term, t2: Term) = |
63 | Atom.create( | 100 | TupleTableAtom.create( |
64 | TupleTableName.create(RSA.internal("ID").getIRI), | 101 | TupleTableName.create(RSA.internal("ID").getIRI), |
65 | (answer ++ bounded).appended(t1).appended(t2): _* | 102 | (answer ++ bounded).appended(t1).appended(t2): _* |
66 | ) | 103 | ) |
67 | def predNI(t1: Term): Atom = | 104 | def predNI(t1: Term): TupleTableAtom = |
68 | Atom.rdf(t1, IRI.RDF_TYPE, RSA.internal("NI")) | 105 | TupleTableAtom.rdf(t1, IRI.RDF_TYPE, RSA.internal("NI")) |
69 | def predTQ(sx: String, t1: Term, t2: Term) = | 106 | def predTQ(sx: String, t1: Term, t2: Term) = |
70 | Atom.create( | 107 | TupleTableAtom.create( |
71 | TupleTableName.create(RSA.internal(s"TQ_$sx").getIRI), | 108 | TupleTableName.create(RSA.internal(s"TQ_$sx").getIRI), |
72 | (answer ++ bounded).appended(t1).appended(t2): _* | 109 | (answer ++ bounded).appended(t1).appended(t2): _* |
73 | ) | 110 | ) |
74 | def predAQ(sx: String, t1: Term, t2: Term) = | 111 | def predAQ(sx: String, t1: Term, t2: Term) = |
75 | Atom.create( | 112 | TupleTableAtom.create( |
76 | TupleTableName.create(RSA.internal(s"AQ_$sx").getIRI), | 113 | TupleTableName.create(RSA.internal(s"AQ_$sx").getIRI), |
77 | (answer ++ bounded).appended(t1).appended(t2): _* | 114 | (answer ++ bounded).appended(t1).appended(t2): _* |
78 | ) | 115 | ) |
79 | val predFK = | 116 | val predFK = |
80 | Atom.create( | 117 | TupleTableAtom.create( |
81 | TupleTableName.create(RSA.internal("FK").getIRI), | 118 | TupleTableName.create(RSA.internal("FK").getIRI), |
82 | (answer ++ bounded): _* | 119 | (answer ++ bounded): _* |
83 | ) | 120 | ) |
84 | val predSP = | 121 | val predSP = |
85 | Atom.create( | 122 | TupleTableAtom.create( |
86 | TupleTableName.create(RSA.internal("SP").getIRI), | 123 | TupleTableName.create(RSA.internal("SP").getIRI), |
87 | (answer ++ bounded): _* | 124 | (answer ++ bounded): _* |
88 | ) | 125 | ) |
89 | val predANS = | 126 | val predANS = |
90 | Atom.create( | 127 | TupleTableAtom.create( |
91 | TupleTableName.create(RSA.internal("ANS").getIRI), | 128 | TupleTableName.create(RSA.internal("ANS").getIRI), |
92 | answer: _* | 129 | answer: _* |
93 | ) | 130 | ) |
@@ -116,60 +153,78 @@ class FilteringProgram(query: Query, constants: List[Term]) extends RDFTriple { | |||
116 | /* Rules 4x */ | 153 | /* Rules 4x */ |
117 | val r4a = for { | 154 | val r4a = for { |
118 | role1 <- body.filter(_.isRoleAssertion) | 155 | role1 <- body.filter(_.isRoleAssertion) |
119 | if bounded contains (role1 getArgument 2) | 156 | if bounded contains (role1.getArguments.get(2)) |
120 | role2 <- body.filter(_.isRoleAssertion) | 157 | role2 <- body.filter(_.isRoleAssertion) |
121 | if bounded contains (role2 getArgument 2) | 158 | if bounded contains (role2.getArguments.get(2)) |
122 | } yield Rule.create( | 159 | } yield Rule.create( |
123 | predFK, | 160 | predFK, |
124 | role1 suffix "_f", | 161 | role1 suffix "_f", |
125 | role2 suffix "_f", | 162 | role2 suffix "_f", |
126 | predID( | 163 | predID( |
127 | RSA.internal(bounded.indexOf(role1 getArgument 2)), | 164 | RSA.internal(bounded.indexOf(role1.getArguments.get(2))), |
128 | RSA.internal(bounded.indexOf(role2 getArgument 2)) | 165 | RSA.internal(bounded.indexOf(role2.getArguments.get(2))) |
129 | ), | 166 | ), |
130 | not(Atom.rdf(role1 getArgument 0, IRI.SAME_AS, role2 getArgument 0)) | 167 | not( |
168 | TupleTableAtom.rdf( | ||
169 | role1.getArguments.get(0), | ||
170 | IRI.SAME_AS, | ||
171 | role2.getArguments.get(0) | ||
172 | ) | ||
173 | ) | ||
131 | ) | 174 | ) |
132 | val r4b = for { | 175 | val r4b = for { |
133 | role1 <- body.filter(_.isRoleAssertion) | 176 | role1 <- body.filter(_.isRoleAssertion) |
134 | if bounded contains (role1 getArgument 2) | 177 | if bounded contains (role1.getArguments.get(2)) |
135 | role2 <- body.filter(_.isRoleAssertion) | 178 | role2 <- body.filter(_.isRoleAssertion) |
136 | if bounded contains (role2 getArgument 0) | 179 | if bounded contains (role2.getArguments.get(0)) |
137 | } yield Rule.create( | 180 | } yield Rule.create( |
138 | predFK, | 181 | predFK, |
139 | role1 suffix "_f", | 182 | role1 suffix "_f", |
140 | role2 suffix "_b", | 183 | role2 suffix "_b", |
141 | predID( | 184 | predID( |
142 | RSA.internal(bounded.indexOf(role1 getArgument 2)), | 185 | RSA.internal(bounded.indexOf(role1.getArguments.get(2))), |
143 | RSA.internal(bounded.indexOf(role2 getArgument 0)) | 186 | RSA.internal(bounded.indexOf(role2.getArguments.get(0))) |
144 | ), | 187 | ), |
145 | not(Atom.rdf(role1 getArgument 0, IRI.SAME_AS, role2 getArgument 2)) | 188 | not( |
189 | TupleTableAtom.rdf( | ||
190 | role1.getArguments.get(0), | ||
191 | IRI.SAME_AS, | ||
192 | role2.getArguments.get(2) | ||
193 | ) | ||
194 | ) | ||
146 | ) | 195 | ) |
147 | val r4c = for { | 196 | val r4c = for { |
148 | role1 <- body.filter(_.isRoleAssertion) | 197 | role1 <- body.filter(_.isRoleAssertion) |
149 | if bounded contains (role1 getArgument 0) | 198 | if bounded contains (role1.getArguments.get(0)) |
150 | role2 <- body.filter(_.isRoleAssertion) | 199 | role2 <- body.filter(_.isRoleAssertion) |
151 | if bounded contains (role2 getArgument 0) | 200 | if bounded contains (role2.getArguments.get(0)) |
152 | } yield Rule.create( | 201 | } yield Rule.create( |
153 | predFK, | 202 | predFK, |
154 | role1 suffix "_b", | 203 | role1 suffix "_b", |
155 | role2 suffix "_b", | 204 | role2 suffix "_b", |
156 | predID( | 205 | predID( |
157 | RSA.internal(bounded.indexOf(role1 getArgument 0)), | 206 | RSA.internal(bounded.indexOf(role1.getArguments.get(0))), |
158 | RSA.internal(bounded.indexOf(role2 getArgument 0)) | 207 | RSA.internal(bounded.indexOf(role2.getArguments.get(0))) |
159 | ), | 208 | ), |
160 | not(Atom.rdf(role1 getArgument 2, IRI.SAME_AS, role2 getArgument 2)) | 209 | not( |
210 | TupleTableAtom.rdf( | ||
211 | role1.getArguments.get(2), | ||
212 | IRI.SAME_AS, | ||
213 | role2.getArguments.get(2) | ||
214 | ) | ||
215 | ) | ||
161 | ) | 216 | ) |
162 | 217 | ||
163 | /* Rules 5x */ | 218 | /* Rules 5x */ |
164 | val r5a = for { | 219 | val r5a = for { |
165 | role1 <- body.filter(_.isRoleAssertion) | 220 | role1 <- body.filter(_.isRoleAssertion) |
166 | role1arg0 = role1 getArgument 0 | 221 | role1arg0 = role1.getArguments.get(0) |
167 | role1arg2 = role1 getArgument 2 | 222 | role1arg2 = role1.getArguments.get(2) |
168 | if bounded contains role1arg0 | 223 | if bounded contains role1arg0 |
169 | if bounded contains role1arg2 | 224 | if bounded contains role1arg2 |
170 | role2 <- body.filter(_.isRoleAssertion) | 225 | role2 <- body.filter(_.isRoleAssertion) |
171 | role2arg0 = role2 getArgument 0 | 226 | role2arg0 = role2.getArguments.get(0) |
172 | role2arg2 = role2 getArgument 2 | 227 | role2arg2 = role2.getArguments.get(2) |
173 | if bounded contains role2arg0 | 228 | if bounded contains role2arg0 |
174 | if bounded contains role2arg2 | 229 | if bounded contains role2arg2 |
175 | } yield Rule.create( | 230 | } yield Rule.create( |
@@ -183,18 +238,18 @@ class FilteringProgram(query: Query, constants: List[Term]) extends RDFTriple { | |||
183 | RSA.internal(bounded indexOf role1arg2), | 238 | RSA.internal(bounded indexOf role1arg2), |
184 | RSA.internal(bounded indexOf role2arg2) | 239 | RSA.internal(bounded indexOf role2arg2) |
185 | ), | 240 | ), |
186 | Atom.rdf(role1arg0, IRI.SAME_AS, role2arg0), | 241 | TupleTableAtom.rdf(role1arg0, IRI.SAME_AS, role2arg0), |
187 | not(predNI(role1arg0)) | 242 | not(predNI(role1arg0)) |
188 | ) | 243 | ) |
189 | val r5b = for { | 244 | val r5b = for { |
190 | role1 <- body.filter(_.isRoleAssertion) | 245 | role1 <- body.filter(_.isRoleAssertion) |
191 | role1arg0 = role1 getArgument 0 | 246 | role1arg0 = role1.getArguments.get(0) |
192 | role1arg2 = role1 getArgument 2 | 247 | role1arg2 = role1.getArguments.get(2) |
193 | if bounded contains role1arg0 | 248 | if bounded contains role1arg0 |
194 | if bounded contains role1arg2 | 249 | if bounded contains role1arg2 |
195 | role2 <- body.filter(_.isRoleAssertion) | 250 | role2 <- body.filter(_.isRoleAssertion) |
196 | role2arg0 = role2 getArgument 0 | 251 | role2arg0 = role2.getArguments.get(0) |
197 | role2arg2 = role2 getArgument 2 | 252 | role2arg2 = role2.getArguments.get(2) |
198 | if bounded contains role2arg0 | 253 | if bounded contains role2arg0 |
199 | if bounded contains role2arg2 | 254 | if bounded contains role2arg2 |
200 | } yield Rule.create( | 255 | } yield Rule.create( |
@@ -208,18 +263,18 @@ class FilteringProgram(query: Query, constants: List[Term]) extends RDFTriple { | |||
208 | RSA.internal(bounded indexOf role1arg2), | 263 | RSA.internal(bounded indexOf role1arg2), |
209 | RSA.internal(bounded indexOf role2arg0) | 264 | RSA.internal(bounded indexOf role2arg0) |
210 | ), | 265 | ), |
211 | Atom.rdf(role1arg0, IRI.SAME_AS, role2arg2), | 266 | TupleTableAtom.rdf(role1arg0, IRI.SAME_AS, role2arg2), |
212 | not(predNI(role1arg0)) | 267 | not(predNI(role1arg0)) |
213 | ) | 268 | ) |
214 | val r5c = for { | 269 | val r5c = for { |
215 | role1 <- body.filter(_.isRoleAssertion) | 270 | role1 <- body.filter(_.isRoleAssertion) |
216 | role1arg0 = role1 getArgument 0 | 271 | role1arg0 = role1.getArguments.get(0) |
217 | role1arg2 = role1 getArgument 2 | 272 | role1arg2 = role1.getArguments.get(2) |
218 | if bounded contains role1arg0 | 273 | if bounded contains role1arg0 |
219 | if bounded contains role1arg2 | 274 | if bounded contains role1arg2 |
220 | role2 <- body.filter(_.isRoleAssertion) | 275 | role2 <- body.filter(_.isRoleAssertion) |
221 | role2arg0 = role2 getArgument 0 | 276 | role2arg0 = role2.getArguments.get(0) |
222 | role2arg2 = role2 getArgument 2 | 277 | role2arg2 = role2.getArguments.get(2) |
223 | if bounded contains role2arg0 | 278 | if bounded contains role2arg0 |
224 | if bounded contains role2arg2 | 279 | if bounded contains role2arg2 |
225 | } yield Rule.create( | 280 | } yield Rule.create( |
@@ -233,15 +288,15 @@ class FilteringProgram(query: Query, constants: List[Term]) extends RDFTriple { | |||
233 | RSA.internal(bounded indexOf role1arg0), | 288 | RSA.internal(bounded indexOf role1arg0), |
234 | RSA.internal(bounded indexOf role2arg0) | 289 | RSA.internal(bounded indexOf role2arg0) |
235 | ), | 290 | ), |
236 | Atom.rdf(role1arg2, IRI.SAME_AS, role2arg2), | 291 | TupleTableAtom.rdf(role1arg2, IRI.SAME_AS, role2arg2), |
237 | not(predNI(role1arg2)) | 292 | not(predNI(role1arg2)) |
238 | ) | 293 | ) |
239 | 294 | ||
240 | /* Rules 6 */ | 295 | /* Rules 6 */ |
241 | val r6 = for { | 296 | val r6 = for { |
242 | role <- body.filter(_.isRoleAssertion) | 297 | role <- body.filter(_.isRoleAssertion) |
243 | arg0 = role getArgument 0 | 298 | arg0 = role.getArguments.get(0) |
244 | arg2 = role getArgument 2 | 299 | arg2 = role.getArguments.get(2) |
245 | if bounded contains arg0 | 300 | if bounded contains arg0 |
246 | if bounded contains arg2 | 301 | if bounded contains arg2 |
247 | sx <- List("_f", "_b") | 302 | sx <- List("_f", "_b") |
@@ -309,34 +364,37 @@ class FilteringProgram(query: Query, constants: List[Term]) extends RDFTriple { | |||
309 | } | 364 | } |
310 | 365 | ||
311 | private sealed trait Reified; | 366 | private sealed trait Reified; |
312 | private case class ReifiedHead(bind: BindAtom, atoms: List[Atom]) | 367 | private case class ReifiedHead(bind: BindAtom, atoms: List[TupleTableAtom]) |
313 | extends Reified | 368 | extends Reified |
314 | private case class ReifiedBody(atoms: List[Atom]) extends Reified | 369 | private case class ReifiedBody(atoms: List[TupleTableAtom]) extends Reified |
315 | private case class Unaltered(formula: BodyFormula) extends Reified | 370 | private case class Unaltered(formula: BodyFormula) extends Reified |
316 | 371 | ||
317 | private def getBindAtom(atom: Atom): BindAtom = { | 372 | private def getBindAtom(atom: TupleTableAtom): BindAtom = { |
318 | val newvar = RSA.getFreshVariable() | 373 | val newvar = RSA.getFreshVariable() |
319 | val name = | 374 | val name = |
320 | Literal.create(atom.getTupleTableName.getIRI, Datatype.XSD_STRING) | 375 | Literal.create(atom.getTupleTableName.toString(), Datatype.XSD_STRING) |
321 | val args = atom | 376 | val args = atom |
322 | .getArguments() | 377 | .getArguments() |
323 | .asScala | 378 | .asScala |
324 | .toSeq | 379 | .toSeq |
325 | .prepended(name) /* Unclear requirement for SKOLEM func calls */ | 380 | .prepended(name) /* Unclear requirement for SKOLEM func calls */ |
326 | BindAtom.create( | 381 | BindAtom.create( |
327 | BuiltinFunctionCall | 382 | FunctionCall |
328 | .create("SKOLEM", args: _*), | 383 | .create("SKOLEM", args: _*), |
329 | newvar | 384 | newvar |
330 | ) | 385 | ) |
331 | } | 386 | } |
332 | 387 | ||
333 | private def reifyAtom(atom: Atom, variable: Variable): List[Atom] = { | 388 | private def reifyAtom( |
334 | def iri(i: Int) = atom.getTupleTableName().getIRI() ++ s"_$i" | 389 | atom: TupleTableAtom, |
390 | variable: Variable | ||
391 | ): List[TupleTableAtom] = { | ||
392 | def iri(i: Int) = atom.getTupleTableName.getName ++ s"_$i" | ||
335 | atom | 393 | atom |
336 | .getArguments() | 394 | .getArguments() |
337 | .asScala | 395 | .asScala |
338 | .zipWithIndex | 396 | .zipWithIndex |
339 | .map { case (t, i) => Atom.rdf(variable, iri(i), t) } | 397 | .map { case (t, i) => TupleTableAtom.rdf(variable, iri(i), t) } |
340 | .toList | 398 | .toList |
341 | } | 399 | } |
342 | 400 | ||
@@ -345,7 +403,7 @@ class FilteringProgram(query: Query, constants: List[Term]) extends RDFTriple { | |||
345 | head: Boolean | 403 | head: Boolean |
346 | ): Reified = { | 404 | ): Reified = { |
347 | formula match { | 405 | formula match { |
348 | case a: Atom => { | 406 | case a: TupleTableAtom => { |
349 | if (!a.isRdfTriple) { | 407 | if (!a.isRdfTriple) { |
350 | if (head) { | 408 | if (head) { |
351 | val b = getBindAtom(a) | 409 | val b = getBindAtom(a) |
@@ -380,7 +438,7 @@ class FilteringProgram(query: Query, constants: List[Term]) extends RDFTriple { | |||
380 | case ReifiedHead(_, x) => x; | 438 | case ReifiedHead(_, x) => x; |
381 | case ReifiedBody(_) => List(); /* handle impossible case */ | 439 | case ReifiedBody(_) => List(); /* handle impossible case */ |
382 | case Unaltered(x) => | 440 | case Unaltered(x) => |
383 | List(x.asInstanceOf[Atom]) /* Can we do better that a cast? */ | 441 | List(x.asInstanceOf[TupleTableAtom]) /* Can we do better that a cast? */ |
384 | } | 442 | } |
385 | Rule.create(head.asJava, (skols ++ body).asJava) | 443 | Rule.create(head.asJava, (skols ++ body).asJava) |
386 | } | 444 | } |
@@ -388,6 +446,6 @@ class FilteringProgram(query: Query, constants: List[Term]) extends RDFTriple { | |||
388 | } // class FilteringProgram | 446 | } // class FilteringProgram |
389 | 447 | ||
390 | object FilteringProgram { | 448 | object FilteringProgram { |
391 | def apply(query: Query, constants: List[Term]): FilteringProgram = | 449 | def apply(query: SelectQuery, constants: List[Term]): FilteringProgram = |
392 | new FilteringProgram(query, constants) | 450 | new FilteringProgram(query, constants) |
393 | } // object FilteringProgram | 451 | } // object FilteringProgram |
diff --git a/src/main/scala/rsacomb/RDFTriple.scala b/src/main/scala/rsacomb/RDFTriple.scala index 11ad6d4..9e593df 100644 --- a/src/main/scala/rsacomb/RDFTriple.scala +++ b/src/main/scala/rsacomb/RDFTriple.scala | |||
@@ -1,10 +1,11 @@ | |||
1 | package rsacomb | 1 | package rsacomb |
2 | 2 | ||
3 | import tech.oxfordsemantic.jrdfox.logic.{Atom, IRI, TupleTableName} | 3 | import tech.oxfordsemantic.jrdfox.logic.datalog.{TupleTableAtom, TupleTableName} |
4 | import tech.oxfordsemantic.jrdfox.logic.expression.{IRI} | ||
4 | 5 | ||
5 | trait RDFTriple { | 6 | trait RDFTriple { |
6 | 7 | ||
7 | implicit class RDFTriple(atom: Atom) { | 8 | implicit class RDFTriple(atom: TupleTableAtom) { |
8 | 9 | ||
9 | /* Is this the best way to determine if an atom is an RDF triple? | 10 | /* Is this the best way to determine if an atom is an RDF triple? |
10 | * Note that we can't use `getNumberOfArguments()` because is not | 11 | * Note that we can't use `getNumberOfArguments()` because is not |
@@ -21,39 +22,39 @@ trait RDFTriple { | |||
21 | * ``` | 22 | * ``` |
22 | */ | 23 | */ |
23 | def isRdfTriple: Boolean = | 24 | def isRdfTriple: Boolean = |
24 | atom.getTupleTableName.getIRI.equals("internal:triple") | 25 | atom.getTupleTableName.getName.equals("internal:triple") |
25 | 26 | ||
26 | def isClassAssertion: Boolean = | 27 | def isClassAssertion: Boolean = |
27 | atom.isRdfTriple && atom.getArgument(1).equals(IRI.RDF_TYPE) | 28 | atom.isRdfTriple && atom.getArguments.get(1).equals(IRI.RDF_TYPE) |
28 | 29 | ||
29 | def isRoleAssertion: Boolean = | 30 | def isRoleAssertion: Boolean = |
30 | atom.isRdfTriple && !atom.getArgument(1).equals(IRI.RDF_TYPE) | 31 | atom.isRdfTriple && !atom.getArguments.get(1).equals(IRI.RDF_TYPE) |
31 | 32 | ||
32 | def suffix(sx: String): Atom = | 33 | def suffix(sx: String): TupleTableAtom = |
33 | if (this.isClassAssertion) { | 34 | if (this.isClassAssertion) { |
34 | val newclass = atom.getArgument(2) match { | 35 | val newclass = atom.getArguments.get(2) match { |
35 | case iri: IRI => IRI.create(iri.getIRI.appendedAll(sx)) | 36 | case iri: IRI => IRI.create(iri.getIRI.appendedAll(sx)) |
36 | case other => other | 37 | case other => other |
37 | } | 38 | } |
38 | Atom.rdf( | 39 | TupleTableAtom.rdf( |
39 | atom getArgument 0, | 40 | atom.getArguments.get(0), |
40 | atom getArgument 1, | 41 | atom.getArguments.get(1), |
41 | newclass | 42 | newclass |
42 | ) | 43 | ) |
43 | } else if (this.isRoleAssertion) { | 44 | } else if (this.isRoleAssertion) { |
44 | val newrole = atom.getArgument(1) match { | 45 | val newrole = atom.getArguments.get(1) match { |
45 | case iri: IRI => IRI.create(iri.getIRI.appendedAll(sx)) | 46 | case iri: IRI => IRI.create(iri.getIRI.appendedAll(sx)) |
46 | case other => other | 47 | case other => other |
47 | } | 48 | } |
48 | Atom.rdf( | 49 | TupleTableAtom.rdf( |
49 | atom getArgument 0, | 50 | atom.getArguments.get(0), |
50 | newrole, | 51 | newrole, |
51 | atom getArgument 2 | 52 | atom.getArguments.get(2) |
52 | ) | 53 | ) |
53 | } else { | 54 | } else { |
54 | val newname = | 55 | val newname = |
55 | TupleTableName.create(atom.getTupleTableName.getIRI.appendedAll(sx)) | 56 | TupleTableName.create(atom.getTupleTableName.getName.appendedAll(sx)) |
56 | Atom.create(newname, atom.getArguments()) | 57 | TupleTableAtom.create(newname, atom.getArguments()) |
57 | } | 58 | } |
58 | } | 59 | } |
59 | 60 | ||
diff --git a/src/main/scala/rsacomb/RDFoxAxiomConverter.scala b/src/main/scala/rsacomb/RDFoxAxiomConverter.scala index dab6765..2d04c56 100644 --- a/src/main/scala/rsacomb/RDFoxAxiomConverter.scala +++ b/src/main/scala/rsacomb/RDFoxAxiomConverter.scala | |||
@@ -8,9 +8,13 @@ import org.semanticweb.owlapi.model.{ | |||
8 | } | 8 | } |
9 | import org.semanticweb.owlapi.model.OWLAxiomVisitorEx | 9 | import org.semanticweb.owlapi.model.OWLAxiomVisitorEx |
10 | 10 | ||
11 | import tech.oxfordsemantic.jrdfox.logic.{Rule, BodyFormula} | 11 | import tech.oxfordsemantic.jrdfox.logic.datalog.{ |
12 | import tech.oxfordsemantic.jrdfox.logic.{Atom, Term, Variable, Literal} | 12 | Rule, |
13 | import tech.oxfordsemantic.jrdfox.logic.{TupleTableName} | 13 | BodyFormula, |
14 | TupleTableAtom, | ||
15 | TupleTableName | ||
16 | } | ||
17 | import tech.oxfordsemantic.jrdfox.logic.expression.{Term, Variable, Literal} | ||
14 | 18 | ||
15 | import scala.collection.JavaConverters._ | 19 | import scala.collection.JavaConverters._ |
16 | 20 | ||
@@ -71,7 +75,7 @@ class RDFoxAxiomConverter( | |||
71 | new RDFoxPropertyExprConverter(term, term1, suffix) | 75 | new RDFoxPropertyExprConverter(term, term1, suffix) |
72 | val superVisitor = new RDFoxPropertyExprConverter(term, term1, suffix) | 76 | val superVisitor = new RDFoxPropertyExprConverter(term, term1, suffix) |
73 | val body: List[BodyFormula] = axiom.getSubProperty.accept(subVisitor) | 77 | val body: List[BodyFormula] = axiom.getSubProperty.accept(subVisitor) |
74 | val head: List[Atom] = axiom.getSuperProperty.accept(superVisitor) | 78 | val head: List[TupleTableAtom] = axiom.getSuperProperty.accept(superVisitor) |
75 | List(Rule.create(head.asJava, body.asJava)) | 79 | List(Rule.create(head.asJava, body.asJava)) |
76 | } | 80 | } |
77 | 81 | ||
diff --git a/src/main/scala/rsacomb/RDFoxClassExprConverter.scala b/src/main/scala/rsacomb/RDFoxClassExprConverter.scala index f07e3c6..de0f623 100644 --- a/src/main/scala/rsacomb/RDFoxClassExprConverter.scala +++ b/src/main/scala/rsacomb/RDFoxClassExprConverter.scala | |||
@@ -12,17 +12,16 @@ import org.semanticweb.owlapi.model.{ | |||
12 | OWLObjectMaxCardinality | 12 | OWLObjectMaxCardinality |
13 | } | 13 | } |
14 | import org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx | 14 | import org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx |
15 | import tech.oxfordsemantic.jrdfox.logic.{ | 15 | import tech.oxfordsemantic.jrdfox.logic.Datatype |
16 | import tech.oxfordsemantic.jrdfox.logic.datalog.{ | ||
16 | BindAtom, | 17 | BindAtom, |
17 | BuiltinFunctionCall, | 18 | TupleTableName, |
18 | TupleTableName | 19 | TupleTableAtom |
19 | } | 20 | } |
20 | import tech.oxfordsemantic.jrdfox.logic.{ | 21 | import tech.oxfordsemantic.jrdfox.logic.expression.{ |
21 | Atom, | ||
22 | Term, | 22 | Term, |
23 | Variable, | 23 | Variable, |
24 | Literal, | 24 | FunctionCall, |
25 | Datatype, | ||
26 | IRI | 25 | IRI |
27 | } | 26 | } |
28 | 27 | ||
@@ -64,7 +63,7 @@ class RDFoxClassExprConverter( | |||
64 | // OWLClass | 63 | // OWLClass |
65 | override def visit(expr: OWLClass): RDFoxRuleShards = { | 64 | override def visit(expr: OWLClass): RDFoxRuleShards = { |
66 | val iri: IRI = if (expr.isTopEntity()) IRI.THING else expr.getIRI() | 65 | val iri: IRI = if (expr.isTopEntity()) IRI.THING else expr.getIRI() |
67 | val atom = List(Atom.rdf(term, IRI.RDF_TYPE, iri)) | 66 | val atom = List(TupleTableAtom.rdf(term, IRI.RDF_TYPE, iri)) |
68 | RDFoxRuleShards(atom, List()) | 67 | RDFoxRuleShards(atom, List()) |
69 | } | 68 | } |
70 | 69 | ||
@@ -90,7 +89,7 @@ class RDFoxClassExprConverter( | |||
90 | .asOWLNamedIndividual | 89 | .asOWLNamedIndividual |
91 | .getIRI | 90 | .getIRI |
92 | val atom = List( | 91 | val atom = List( |
93 | Atom.sameAs(term, ind) | 92 | TupleTableAtom.rdf(term, IRI.SAME_AS, ind) |
94 | ) | 93 | ) |
95 | RDFoxRuleShards(atom, List()) | 94 | RDFoxRuleShards(atom, List()) |
96 | } | 95 | } |
@@ -110,8 +109,8 @@ class RDFoxClassExprConverter( | |||
110 | if (unsafe.contains(prop)) | 109 | if (unsafe.contains(prop)) |
111 | ( | 110 | ( |
112 | List( | 111 | List( |
113 | Atom.rdf(term, RSA.internal("PE"), c), | 112 | TupleTableAtom.rdf(term, RSA.internal("PE"), c), |
114 | Atom.rdf(c, IRI.RDF_TYPE, RSA.internal("U")) | 113 | TupleTableAtom.rdf(c, IRI.RDF_TYPE, RSA.internal("U")) |
115 | ), | 114 | ), |
116 | List(), | 115 | List(), |
117 | c | 116 | c |
@@ -124,7 +123,7 @@ class RDFoxClassExprConverter( | |||
124 | // a simple builtin function with a "special" name. | 123 | // a simple builtin function with a "special" name. |
125 | ( | 124 | ( |
126 | List(), | 125 | List(), |
127 | List(BindAtom.create(BuiltinFunctionCall.create("SKOLEM", term), y)), | 126 | List(BindAtom.create(FunctionCall.create("SKOLEM", term), y)), |
128 | y | 127 | y |
129 | ) | 128 | ) |
130 | } | 129 | } |
@@ -154,7 +153,7 @@ class RDFoxClassExprConverter( | |||
154 | .map(expr.getProperty.accept(_)) | 153 | .map(expr.getProperty.accept(_)) |
155 | .flatten | 154 | .flatten |
156 | RDFoxRuleShards( | 155 | RDFoxRuleShards( |
157 | List(Atom.sameAs(vars(0), vars(1))), | 156 | List(TupleTableAtom.rdf(vars(0), IRI.SAME_AS, vars(1))), |
158 | classResult.res ++ propertyResult | 157 | classResult.res ++ propertyResult |
159 | ) | 158 | ) |
160 | } | 159 | } |
diff --git a/src/main/scala/rsacomb/RDFoxPropertyExprConverter.scala b/src/main/scala/rsacomb/RDFoxPropertyExprConverter.scala index ba151d0..11d6d86 100644 --- a/src/main/scala/rsacomb/RDFoxPropertyExprConverter.scala +++ b/src/main/scala/rsacomb/RDFoxPropertyExprConverter.scala | |||
@@ -3,7 +3,8 @@ package rsacomb | |||
3 | import org.semanticweb.owlapi.model.{OWLPropertyExpression, OWLObjectProperty} | 3 | import org.semanticweb.owlapi.model.{OWLPropertyExpression, OWLObjectProperty} |
4 | import org.semanticweb.owlapi.model.OWLPropertyExpressionVisitorEx | 4 | import org.semanticweb.owlapi.model.OWLPropertyExpressionVisitorEx |
5 | 5 | ||
6 | import tech.oxfordsemantic.jrdfox.logic.{Atom, Term, IRI, Literal} | 6 | import tech.oxfordsemantic.jrdfox.logic.datalog.TupleTableAtom |
7 | import tech.oxfordsemantic.jrdfox.logic.expression.{Term, IRI, Literal} | ||
7 | 8 | ||
8 | import org.semanticweb.owlapi.model.OWLObjectInverseOf | 9 | import org.semanticweb.owlapi.model.OWLObjectInverseOf |
9 | 10 | ||
@@ -11,23 +12,23 @@ class RDFoxPropertyExprConverter( | |||
11 | term1: Term, | 12 | term1: Term, |
12 | term2: Term, | 13 | term2: Term, |
13 | suffix: RSASuffix | 14 | suffix: RSASuffix |
14 | ) extends OWLPropertyExpressionVisitorEx[List[Atom]] { | 15 | ) extends OWLPropertyExpressionVisitorEx[List[TupleTableAtom]] { |
15 | 16 | ||
16 | // Automatically converts OWLAPI types into RDFox equivalent types. | 17 | // Automatically converts OWLAPI types into RDFox equivalent types. |
17 | import RDFoxUtil.owlapi2rdfox; | 18 | import RDFoxUtil.owlapi2rdfox; |
18 | 19 | ||
19 | override def visit(expr: OWLObjectProperty): List[Atom] = { | 20 | override def visit(expr: OWLObjectProperty): List[TupleTableAtom] = { |
20 | val pred = IRI.create(expr.getIRI.getIRIString ++ suffix.getSuffix) | 21 | val pred = IRI.create(expr.getIRI.getIRIString ++ suffix.getSuffix) |
21 | List(Atom.rdf(term1, pred, term2)) | 22 | List(TupleTableAtom.rdf(term1, pred, term2)) |
22 | } | 23 | } |
23 | 24 | ||
24 | override def visit(expr: OWLObjectInverseOf): List[Atom] = { | 25 | override def visit(expr: OWLObjectInverseOf): List[TupleTableAtom] = { |
25 | val pred = IRI.create( | 26 | val pred = IRI.create( |
26 | expr.getInverse.getNamedProperty.getIRI.getIRIString ++ suffix.getSuffix ++ "_inv" | 27 | expr.getInverse.getNamedProperty.getIRI.getIRIString ++ suffix.getSuffix ++ "_inv" |
27 | ) | 28 | ) |
28 | List(Atom.rdf(term1, pred, term2)) | 29 | List(TupleTableAtom.rdf(term1, pred, term2)) |
29 | } | 30 | } |
30 | 31 | ||
31 | def doDefault(expr: OWLPropertyExpression): List[Atom] = List() | 32 | def doDefault(expr: OWLPropertyExpression): List[TupleTableAtom] = List() |
32 | 33 | ||
33 | } // class RDFoxPropertyExprConverter | 34 | } // class RDFoxPropertyExprConverter |
diff --git a/src/main/scala/rsacomb/RDFoxRuleShards.scala b/src/main/scala/rsacomb/RDFoxRuleShards.scala index 8f72983..b61cc38 100644 --- a/src/main/scala/rsacomb/RDFoxRuleShards.scala +++ b/src/main/scala/rsacomb/RDFoxRuleShards.scala | |||
@@ -1,6 +1,5 @@ | |||
1 | package rsacomb | 1 | package rsacomb |
2 | 2 | ||
3 | import tech.oxfordsemantic.jrdfox.logic.{Atom, BodyFormula} | 3 | import tech.oxfordsemantic.jrdfox.logic.datalog.{TupleTableAtom, BodyFormula} |
4 | |||
5 | case class RDFoxRuleShards(res : List[Atom], ext : List[BodyFormula]) | ||
6 | 4 | ||
5 | case class RDFoxRuleShards(res: List[TupleTableAtom], ext: List[BodyFormula]) | ||
diff --git a/src/main/scala/rsacomb/RDFoxUtil.scala b/src/main/scala/rsacomb/RDFoxUtil.scala index 4e0a118..748c72f 100644 --- a/src/main/scala/rsacomb/RDFoxUtil.scala +++ b/src/main/scala/rsacomb/RDFoxUtil.scala | |||
@@ -2,9 +2,9 @@ package rsacomb | |||
2 | 2 | ||
3 | /* Java imports */ | 3 | /* Java imports */ |
4 | import java.util.HashMap | 4 | import java.util.HashMap |
5 | import java.io.ByteArrayInputStream | 5 | import java.io.StringReader |
6 | import tech.oxfordsemantic.jrdfox.Prefixes | 6 | import tech.oxfordsemantic.jrdfox.Prefixes |
7 | import tech.oxfordsemantic.jrdfox.logic.{IRI, Query} | 7 | import tech.oxfordsemantic.jrdfox.logic.sparql.statement.{Query, SelectQuery} |
8 | import tech.oxfordsemantic.jrdfox.client.{ | 8 | import tech.oxfordsemantic.jrdfox.client.{ |
9 | ConnectionFactory, | 9 | ConnectionFactory, |
10 | ServerConnection, | 10 | ServerConnection, |
@@ -12,7 +12,7 @@ import tech.oxfordsemantic.jrdfox.client.{ | |||
12 | } | 12 | } |
13 | import tech.oxfordsemantic.jrdfox.formats.SPARQLParser | 13 | import tech.oxfordsemantic.jrdfox.formats.SPARQLParser |
14 | 14 | ||
15 | import tech.oxfordsemantic.jrdfox.logic.{IRI => RDFox_IRI} | 15 | import tech.oxfordsemantic.jrdfox.logic.expression.{IRI => RDFox_IRI} |
16 | import org.semanticweb.owlapi.model.{IRI => OWL_IRI} | 16 | import org.semanticweb.owlapi.model.{IRI => OWL_IRI} |
17 | 17 | ||
18 | object RDFoxUtil { | 18 | object RDFoxUtil { |
@@ -51,12 +51,19 @@ object RDFoxUtil { | |||
51 | (server, data) | 51 | (server, data) |
52 | } | 52 | } |
53 | 53 | ||
54 | def parseQuery(query: String, prefixes: Prefixes = RSA.Prefixes): Query = { | 54 | def parseQuery( |
55 | query: String, | ||
56 | prefixes: Prefixes = RSA.Prefixes | ||
57 | ): Option[SelectQuery] = { | ||
55 | val parser = new SPARQLParser( | 58 | val parser = new SPARQLParser( |
56 | prefixes, | 59 | prefixes, |
57 | new ByteArrayInputStream(query.getBytes()) | 60 | new StringReader(query) |
58 | ) | 61 | ) |
59 | parser.parseSingleQuery() | 62 | // NOTE: return only conjunctive queries for now (SelectQuery) |
63 | parser.parseSingleQuery() match { | ||
64 | case q: SelectQuery => Some(q) | ||
65 | case _ => None | ||
66 | } | ||
60 | } | 67 | } |
61 | 68 | ||
62 | def submitQuery( | 69 | def submitQuery( |
diff --git a/src/main/scala/rsacomb/RSA.scala b/src/main/scala/rsacomb/RSA.scala index 01982fc..a6f4b88 100644 --- a/src/main/scala/rsacomb/RSA.scala +++ b/src/main/scala/rsacomb/RSA.scala | |||
@@ -6,20 +6,12 @@ import java.util.Map | |||
6 | 6 | ||
7 | import tech.oxfordsemantic.jrdfox.formats.SPARQLParser | 7 | import tech.oxfordsemantic.jrdfox.formats.SPARQLParser |
8 | import tech.oxfordsemantic.jrdfox.Prefixes | 8 | import tech.oxfordsemantic.jrdfox.Prefixes |
9 | import tech.oxfordsemantic.jrdfox.logic.IRI | 9 | import tech.oxfordsemantic.jrdfox.logic.expression.{Variable, IRI} |
10 | import org.semanticweb.owlapi.apibinding.OWLManager | 10 | import org.semanticweb.owlapi.apibinding.OWLManager |
11 | import org.semanticweb.owlapi.model.OWLOntology | 11 | import org.semanticweb.owlapi.model.OWLOntology |
12 | import rsacomb.RSAOntology | 12 | import rsacomb.RSAOntology |
13 | 13 | ||
14 | // Debug only | 14 | // Debug only |
15 | import tech.oxfordsemantic.jrdfox.logic.{ | ||
16 | Formula, | ||
17 | Atom, | ||
18 | Variable, | ||
19 | Query, | ||
20 | QueryType, | ||
21 | Conjunction | ||
22 | } | ||
23 | import scala.collection.JavaConverters._ | 15 | import scala.collection.JavaConverters._ |
24 | 16 | ||
25 | object RSA extends RSAOntology { | 17 | object RSA extends RSAOntology { |
diff --git a/src/main/scala/rsacomb/RSAOntology.scala b/src/main/scala/rsacomb/RSAOntology.scala index b81a8f5..ef1885b 100644 --- a/src/main/scala/rsacomb/RSAOntology.scala +++ b/src/main/scala/rsacomb/RSAOntology.scala | |||
@@ -17,7 +17,14 @@ import org.semanticweb.owlapi.model.{IRI => OWLIRI} | |||
17 | import uk.ac.manchester.cs.owl.owlapi.OWLObjectPropertyImpl | 17 | import uk.ac.manchester.cs.owl.owlapi.OWLObjectPropertyImpl |
18 | 18 | ||
19 | import tech.oxfordsemantic.jrdfox.client.{UpdateType, DataStoreConnection} | 19 | import tech.oxfordsemantic.jrdfox.client.{UpdateType, DataStoreConnection} |
20 | import tech.oxfordsemantic.jrdfox.logic.{Resource, Rule, Atom, Variable, IRI} | 20 | import tech.oxfordsemantic.jrdfox.logic.datalog.{Rule, TupleTableAtom} |
21 | import tech.oxfordsemantic.jrdfox.logic.expression.{ | ||
22 | Term, | ||
23 | Variable, | ||
24 | IRI, | ||
25 | Resource | ||
26 | } | ||
27 | import tech.oxfordsemantic.jrdfox.logic.sparql.statement.SelectQuery | ||
21 | 28 | ||
22 | /* Scala imports */ | 29 | /* Scala imports */ |
23 | import scala.collection.JavaConverters._ | 30 | import scala.collection.JavaConverters._ |
@@ -249,7 +256,7 @@ trait RSAOntology { | |||
249 | Graph(edges: _*) | 256 | Graph(edges: _*) |
250 | } | 257 | } |
251 | 258 | ||
252 | def filteringProgram(query: Query): List[Rule] = | 259 | def filteringProgram(query: SelectQuery): List[Rule] = |
253 | FilteringProgram(query, individuals).rules | 260 | FilteringProgram(query, individuals).rules |
254 | 261 | ||
255 | // TODO: the following functions needs testing | 262 | // TODO: the following functions needs testing |
diff --git a/src/main/scala/rsacomb/SkolemStrategy.scala b/src/main/scala/rsacomb/SkolemStrategy.scala index 9d45b4c..b05cd17 100644 --- a/src/main/scala/rsacomb/SkolemStrategy.scala +++ b/src/main/scala/rsacomb/SkolemStrategy.scala | |||
@@ -1,6 +1,6 @@ | |||
1 | package rsacomb | 1 | package rsacomb |
2 | 2 | ||
3 | import tech.oxfordsemantic.jrdfox.logic.IRI | 3 | import tech.oxfordsemantic.jrdfox.logic.expression.IRI |
4 | 4 | ||
5 | sealed trait SkolemStrategy | 5 | sealed trait SkolemStrategy |
6 | 6 | ||