diff options
Diffstat (limited to 'src/main/scala/rsacomb/CanonicalModel.scala')
| -rw-r--r-- | src/main/scala/rsacomb/CanonicalModel.scala | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/src/main/scala/rsacomb/CanonicalModel.scala b/src/main/scala/rsacomb/CanonicalModel.scala index c957940..95eb556 100644 --- a/src/main/scala/rsacomb/CanonicalModel.scala +++ b/src/main/scala/rsacomb/CanonicalModel.scala | |||
| @@ -29,12 +29,12 @@ object ProgramGenerator { | |||
| 29 | new ProgramGenerator(ontology, term, unsafe) | 29 | new ProgramGenerator(ontology, term, unsafe) |
| 30 | 30 | ||
| 31 | def generateRoleRules( | 31 | def generateRoleRules( |
| 32 | roles: List[OWLObjectPropertyExpression] | 32 | roles: Set[OWLObjectProperty] |
| 33 | ): List[Rule] = { | 33 | ): List[Rule] = { |
| 34 | def additional(pred: String): Seq[Rule] = { | 34 | def additional(pred: String): Seq[Rule] = { |
| 35 | val varX = Variable.create("X") | 35 | val varX = Variable.create("X") |
| 36 | val varY = Variable.create("Y") | 36 | val varY = Variable.create("Y") |
| 37 | Seq( | 37 | List( |
| 38 | Rule.create( | 38 | Rule.create( |
| 39 | Atom.rdf(varX, IRI.create(pred), varY), | 39 | Atom.rdf(varX, IRI.create(pred), varY), |
| 40 | Atom.rdf(varX, IRI.create(pred ++ RSASuffix.Forward.getSuffix), varY) | 40 | Atom.rdf(varX, IRI.create(pred ++ RSASuffix.Forward.getSuffix), varY) |
| @@ -62,10 +62,14 @@ object ProgramGenerator { | |||
| 62 | ) | 62 | ) |
| 63 | } | 63 | } |
| 64 | roles | 64 | roles |
| 65 | .filter(_.isInstanceOf[OWLObjectProperty]) // Can we avoid this? | 65 | .map(_.getIRI.getIRIString) |
| 66 | .map(_.asInstanceOf[OWLObjectProperty].getIRI.getIRIString) | ||
| 67 | .flatMap(additional) | 66 | .flatMap(additional) |
| 67 | .toList | ||
| 68 | } | 68 | } |
| 69 | |||
| 70 | def NIs(individuals: List[IRI]): List[Atom] = | ||
| 71 | individuals.map(Atom.rdf(_, IRI.RDF_TYPE, RSA.internal("NI"))) | ||
| 72 | |||
| 69 | } | 73 | } |
| 70 | 74 | ||
| 71 | class ProgramGenerator( | 75 | class ProgramGenerator( |
| @@ -78,7 +82,7 @@ class ProgramGenerator( | |||
| 78 | 82 | ||
| 79 | import RDFoxUtil._ | 83 | import RDFoxUtil._ |
| 80 | 84 | ||
| 81 | def rules1(axiom: OWLSubClassOfAxiom): (List[Rule], List[Atom]) = { | 85 | def rules1(axiom: OWLSubClassOfAxiom): List[Rule] = { |
| 82 | val unfold = ontology.cycle(axiom).toList | 86 | val unfold = ontology.cycle(axiom).toList |
| 83 | // Fresh Variables | 87 | // Fresh Variables |
| 84 | val v0 = IRI.create("v0_" ++ axiom.hashCode.toString) | 88 | val v0 = IRI.create("v0_" ++ axiom.hashCode.toString) |
| @@ -112,13 +116,16 @@ class ProgramGenerator( | |||
| 112 | .getIRI | 116 | .getIRI |
| 113 | Atom.rdf(v0, IRI.RDF_TYPE, cls) | 117 | Atom.rdf(v0, IRI.RDF_TYPE, cls) |
| 114 | } | 118 | } |
| 115 | ( | 119 | // TODO: To be consistent with the specifics of the visitor we are |
| 116 | List( | 120 | // returning facts as `Rule`s with true body. While this is correct |
| 117 | Rule.create(roleRf, atomA, notIn(varX)), | 121 | // there is an easier way to import facts into RDFox. Are we able to |
| 118 | Rule.create(atomB, atomA, notIn(varX)) | 122 | // do that? |
| 119 | ), | 123 | val facts = unfold.map(x => Rule.create(notIn(x))) |
| 120 | unfold map notIn | 124 | val rules = List( |
| 125 | Rule.create(roleRf, atomA, notIn(varX)), | ||
| 126 | Rule.create(atomB, atomA, notIn(varX)) | ||
| 121 | ) | 127 | ) |
| 128 | facts ++ rules | ||
| 122 | } | 129 | } |
| 123 | 130 | ||
| 124 | def rules2(axiom: OWLSubClassOfAxiom): List[Rule] = { | 131 | def rules2(axiom: OWLSubClassOfAxiom): List[Rule] = { |
| @@ -209,10 +216,7 @@ class ProgramGenerator( | |||
| 209 | ) | 216 | ) |
| 210 | axiom.accept(visitor) | 217 | axiom.accept(visitor) |
| 211 | } else { | 218 | } else { |
| 212 | val (r1, f1) = rules1(axiom) | 219 | rules1(axiom) ++ rules2(axiom) ++ rules3(axiom) |
| 213 | val r2 = rules2(axiom) | ||
| 214 | val r3 = rules3(axiom) | ||
| 215 | r1 ++ r2 ++ r3 | ||
| 216 | } | 220 | } |
| 217 | } else { | 221 | } else { |
| 218 | // Fallback to standard OWL to LP translation | 222 | // Fallback to standard OWL to LP translation |
| @@ -221,9 +225,21 @@ class ProgramGenerator( | |||
| 221 | } | 225 | } |
| 222 | 226 | ||
| 223 | override def visit(axiom: OWLSubObjectPropertyOfAxiom): List[Rule] = { | 227 | override def visit(axiom: OWLSubObjectPropertyOfAxiom): List[Rule] = { |
| 224 | // TODO: Generate additional rules for role inclusion | 228 | val varX = Variable.create("X") |
| 225 | val additional = List() | 229 | val varY = Variable.create("Y") |
| 226 | super.visit(axiom) ++ additional | 230 | val visitorF = new RDFoxAxiomConverter( |
| 231 | term, | ||
| 232 | unsafe, | ||
| 233 | SkolemStrategy.None, | ||
| 234 | RSASuffix.Forward | ||
| 235 | ) | ||
| 236 | val visitorB = new RDFoxAxiomConverter( | ||
| 237 | term, | ||
| 238 | unsafe, | ||
| 239 | SkolemStrategy.None, | ||
| 240 | RSASuffix.Backward | ||
| 241 | ) | ||
| 242 | axiom.accept(visitorB) ++ axiom.accept(visitorF) | ||
| 227 | } | 243 | } |
| 228 | 244 | ||
| 229 | } | 245 | } |
