diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/rsacomb/RSA.scala | 19 | ||||
| -rw-r--r-- | src/main/scala/rsacomb/RSAAxiom.scala | 14 | ||||
| -rw-r--r-- | src/main/scala/rsacomb/RSAOntology.scala | 23 |
3 files changed, 44 insertions, 12 deletions
diff --git a/src/main/scala/rsacomb/RSA.scala b/src/main/scala/rsacomb/RSA.scala index a6f4b88..66de974 100644 --- a/src/main/scala/rsacomb/RSA.scala +++ b/src/main/scala/rsacomb/RSA.scala | |||
| @@ -9,12 +9,17 @@ import tech.oxfordsemantic.jrdfox.Prefixes | |||
| 9 | import tech.oxfordsemantic.jrdfox.logic.expression.{Variable, 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 org.semanticweb.owlapi.model.{ | ||
| 13 | OWLAxiom, | ||
| 14 | OWLClass, | ||
| 15 | OWLObjectPropertyExpression | ||
| 16 | } | ||
| 12 | import rsacomb.RSAOntology | 17 | import rsacomb.RSAOntology |
| 13 | 18 | ||
| 14 | // Debug only | 19 | // Debug only |
| 15 | import scala.collection.JavaConverters._ | 20 | import scala.collection.JavaConverters._ |
| 16 | 21 | ||
| 17 | object RSA extends RSAOntology { | 22 | object RSA extends RSAOntology with RSAAxiom { |
| 18 | 23 | ||
| 19 | val Prefixes = new Prefixes() | 24 | val Prefixes = new Prefixes() |
| 20 | Prefixes.declarePrefix(":", "http://example.com/rsa_example.owl#") | 25 | Prefixes.declarePrefix(":", "http://example.com/rsa_example.owl#") |
| @@ -43,6 +48,18 @@ object RSA extends RSAOntology { | |||
| 43 | + name.toString | 48 | + name.toString |
| 44 | ) | 49 | ) |
| 45 | 50 | ||
| 51 | def hashed( | ||
| 52 | cls1: OWLClass, | ||
| 53 | prop: OWLObjectPropertyExpression, | ||
| 54 | cls2: OWLClass | ||
| 55 | ): String = | ||
| 56 | (cls1, prop, cls2).hashCode.toString | ||
| 57 | |||
| 58 | def hashed(axiom: OWLAxiom): String = { | ||
| 59 | val (cls1, prop, cls2) = axiom.toTriple.get | ||
| 60 | this.hashed(cls1, prop, cls2) | ||
| 61 | } | ||
| 62 | |||
| 46 | // TODO: move this somewhere else... maybe an OntoUtils class or something. | 63 | // TODO: move this somewhere else... maybe an OntoUtils class or something. |
| 47 | def loadOntology(onto: File): OWLOntology = { | 64 | def loadOntology(onto: File): OWLOntology = { |
| 48 | val manager = OWLManager.createOWLOntologyManager() | 65 | val manager = OWLManager.createOWLOntologyManager() |
diff --git a/src/main/scala/rsacomb/RSAAxiom.scala b/src/main/scala/rsacomb/RSAAxiom.scala index aca44b1..f504bbe 100644 --- a/src/main/scala/rsacomb/RSAAxiom.scala +++ b/src/main/scala/rsacomb/RSAAxiom.scala | |||
| @@ -19,6 +19,7 @@ import org.semanticweb.owlapi.model.{ | |||
| 19 | OWLAxiomVisitorEx, | 19 | OWLAxiomVisitorEx, |
| 20 | OWLClassExpressionVisitorEx | 20 | OWLClassExpressionVisitorEx |
| 21 | } | 21 | } |
| 22 | import org.semanticweb.owlapi.model.OWLObjectProperty | ||
| 22 | 23 | ||
| 23 | /* Wrapper trait for the implicit class `RSAAxiom`. | 24 | /* Wrapper trait for the implicit class `RSAAxiom`. |
| 24 | */ | 25 | */ |
| @@ -163,6 +164,19 @@ trait RSAAxiom { | |||
| 163 | val visitor = new RSAAxiomRoleExtractor() | 164 | val visitor = new RSAAxiomRoleExtractor() |
| 164 | axiom.accept(visitor) | 165 | axiom.accept(visitor) |
| 165 | } | 166 | } |
| 167 | |||
| 168 | lazy val toTriple: Option[(OWLClass, OWLObjectProperty, OWLClass)] = | ||
| 169 | for { | ||
| 170 | subClass <- Some(axiom) collect { case a: OWLSubClassOfAxiom => a } | ||
| 171 | cls1 <- Some(subClass.getSubClass) collect { case a: OWLClass => a } | ||
| 172 | someValues <- Some(subClass.getSuperClass) collect { | ||
| 173 | case a: OWLObjectSomeValuesFrom => a | ||
| 174 | } | ||
| 175 | prop <- Some(someValues.getProperty) collect { | ||
| 176 | case a: OWLObjectProperty => a | ||
| 177 | } | ||
| 178 | cls2 <- Some(someValues.getFiller) collect { case a: OWLClass => a } | ||
| 179 | } yield (cls1, prop, cls2) | ||
| 166 | } | 180 | } |
| 167 | 181 | ||
| 168 | } // trait RSAAxiom | 182 | } // trait RSAAxiom |
diff --git a/src/main/scala/rsacomb/RSAOntology.scala b/src/main/scala/rsacomb/RSAOntology.scala index e273dc5..5681843 100644 --- a/src/main/scala/rsacomb/RSAOntology.scala +++ b/src/main/scala/rsacomb/RSAOntology.scala | |||
| @@ -38,6 +38,7 @@ import scalax.collection.GraphEdge.UnDiEdge | |||
| 38 | import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer | 38 | import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer |
| 39 | import tech.oxfordsemantic.jrdfox.logic._ | 39 | import tech.oxfordsemantic.jrdfox.logic._ |
| 40 | 40 | ||
| 41 | object RSAOntology {} | ||
| 41 | /* Wrapper trait for the implicit class `RSAOntology`. | 42 | /* Wrapper trait for the implicit class `RSAOntology`. |
| 42 | */ | 43 | */ |
| 43 | trait RSAOntology { | 44 | trait RSAOntology { |
| @@ -267,8 +268,8 @@ trait RSAOntology { | |||
| 267 | val role = axiom.objectPropertyExpressionsInSignature(0) | 268 | val role = axiom.objectPropertyExpressionsInSignature(0) |
| 268 | if (this.confl(role).contains(role)) { | 269 | if (this.confl(role).contains(role)) { |
| 269 | Set( | 270 | Set( |
| 270 | RSA.internal("v0_" ++ axiom.hashCode.toString()), | 271 | RSA.internal("v0_" ++ RSA.hashed(axiom)), |
| 271 | RSA.internal("v1_" ++ axiom.hashCode.toString()) | 272 | RSA.internal("v1_" ++ RSA.hashed(axiom)) |
| 272 | ) | 273 | ) |
| 273 | } else { | 274 | } else { |
| 274 | Set() | 275 | Set() |
| @@ -329,15 +330,15 @@ trait RSAOntology { | |||
| 329 | classC <- classes | 330 | classC <- classes |
| 330 | // Keeping this check for now | 331 | // Keeping this check for now |
| 331 | if !unsafeRoles.contains(roleS) | 332 | if !unsafeRoles.contains(roleS) |
| 332 | tripleARB = Seq(classA, roleR, classB).hashCode | 333 | tripleARB = RSA.hashed(classA, roleR, classB) |
| 333 | tripleDSC = Seq(classD, roleS, classC).hashCode | 334 | tripleDSC = RSA.hashed(classD, roleS, classC) |
| 334 | individual = | 335 | individual = |
| 335 | if (tripleARB > tripleDSC) { | 336 | if (tripleARB > tripleDSC) { |
| 336 | RSA.internal("v1_" ++ tripleDSC.hashCode.toString()) | 337 | RSA.internal("v1_" ++ tripleDSC) |
| 337 | } else { | 338 | } else { |
| 338 | // Note that this is also the case for | 339 | // Note that this is also the case for |
| 339 | // `tripleARB == tripleDSC` | 340 | // `tripleARB == tripleDSC` |
| 340 | RSA.internal("v0_" ++ tripleDSC.hashCode.toString()) | 341 | RSA.internal("v0_" ++ tripleDSC) |
| 341 | } | 342 | } |
| 342 | } yield individual | 343 | } yield individual |
| 343 | } | 344 | } |
| @@ -433,7 +434,7 @@ trait RSAOntology { | |||
| 433 | private def rules1(axiom: OWLSubClassOfAxiom): List[Rule] = { | 434 | private def rules1(axiom: OWLSubClassOfAxiom): List[Rule] = { |
| 434 | val unfold = ontology.unfold(axiom).toList | 435 | val unfold = ontology.unfold(axiom).toList |
| 435 | // Fresh Variables | 436 | // Fresh Variables |
| 436 | val v0 = RSA.internal("v0_" ++ axiom.hashCode.toString) | 437 | val v0 = RSA.internal("v0_" ++ RSA.hashed(axiom)) |
| 437 | val varX = Variable.create("X") | 438 | val varX = Variable.create("X") |
| 438 | // Predicates | 439 | // Predicates |
| 439 | val atomA: TupleTableAtom = { | 440 | val atomA: TupleTableAtom = { |
| @@ -484,9 +485,9 @@ trait RSAOntology { | |||
| 484 | .getProperty | 485 | .getProperty |
| 485 | if (ontology.confl(roleR) contains roleR) { | 486 | if (ontology.confl(roleR) contains roleR) { |
| 486 | // Fresh Variables | 487 | // Fresh Variables |
| 487 | val v0 = RSA.internal("v0_" ++ axiom.hashCode.toString) | 488 | val v0 = RSA.internal("v0_" ++ RSA.hashed(axiom)) |
| 488 | val v1 = RSA.internal("v1_" ++ axiom.hashCode.toString) | 489 | val v1 = RSA.internal("v1_" ++ RSA.hashed(axiom)) |
| 489 | val v2 = RSA.internal("v2_" ++ axiom.hashCode.toString) | 490 | val v2 = RSA.internal("v2_" ++ RSA.hashed(axiom)) |
| 490 | // Predicates | 491 | // Predicates |
| 491 | def atomA(t: Term): TupleTableAtom = { | 492 | def atomA(t: Term): TupleTableAtom = { |
| 492 | val cls = axiom.getSubClass.asInstanceOf[OWLClass].getIRI | 493 | val cls = axiom.getSubClass.asInstanceOf[OWLClass].getIRI |
| @@ -524,7 +525,7 @@ trait RSAOntology { | |||
| 524 | .asInstanceOf[OWLObjectSomeValuesFrom] | 525 | .asInstanceOf[OWLObjectSomeValuesFrom] |
| 525 | .getProperty | 526 | .getProperty |
| 526 | // Fresh Variables | 527 | // Fresh Variables |
| 527 | val v1 = RSA.internal("v1_" ++ axiom.hashCode.toString) | 528 | val v1 = RSA.internal("v1_" ++ RSA.hashed(axiom)) |
| 528 | // Predicates | 529 | // Predicates |
| 529 | def atomA(t: Term): TupleTableAtom = { | 530 | def atomA(t: Term): TupleTableAtom = { |
| 530 | val cls = axiom.getSubClass.asInstanceOf[OWLClass].getIRI | 531 | val cls = axiom.getSubClass.asInstanceOf[OWLClass].getIRI |
