diff options
| author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2021-01-23 10:42:26 +0000 |
|---|---|---|
| committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2021-01-23 10:42:26 +0000 |
| commit | cf3c93abbc7d1be32a8962340baf8b71a615cc56 (patch) | |
| tree | b34ff48f09f13ddbb01e28b198ddf1b0c8a6d11d /src/main/scala | |
| parent | 5a7c5b14a825d940956040541e127bc62f22fe6f (diff) | |
| download | RSAComb-cf3c93abbc7d1be32a8962340baf8b71a615cc56.tar.gz RSAComb-cf3c93abbc7d1be32a8962340baf8b71a615cc56.zip | |
Add OWL{Data,Object}MinCardinality and OWLHasValue expression support
Diffstat (limited to 'src/main/scala')
| -rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxConverter.scala | 67 | ||||
| -rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/implicits/RDFox.scala | 19 |
2 files changed, 81 insertions, 5 deletions
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxConverter.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxConverter.scala index e3c44c6..dadc81c 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxConverter.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxConverter.scala | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | package uk.ac.ox.cs.rsacomb.converter | 1 | package uk.ac.ox.cs.rsacomb.converter |
| 2 | 2 | ||
| 3 | import java.util.stream.Collectors | 3 | import java.util.stream.Collectors |
| 4 | import org.semanticweb.owlapi.apibinding.OWLManager | ||
| 4 | import org.semanticweb.owlapi.model._ | 5 | import org.semanticweb.owlapi.model._ |
| 5 | import scala.collection.JavaConverters._ | 6 | import scala.collection.JavaConverters._ |
| 6 | import tech.oxfordsemantic.jrdfox.logic.datalog.{ | 7 | import tech.oxfordsemantic.jrdfox.logic.datalog.{ |
| @@ -40,6 +41,15 @@ trait RDFoxConverter { | |||
| 40 | */ | 41 | */ |
| 41 | import uk.ac.ox.cs.rsacomb.implicits.RDFox._ | 42 | import uk.ac.ox.cs.rsacomb.implicits.RDFox._ |
| 42 | 43 | ||
| 44 | /** Factory used for converting expressions when needed. | ||
| 45 | * | ||
| 46 | * @note most of the time this is used to perform some kind of | ||
| 47 | * normalization on axioms. In later versions it might be worth | ||
| 48 | * moving the normalization code in its own independent step. | ||
| 49 | */ | ||
| 50 | private val manager = OWLManager.createOWLOntologyManager() | ||
| 51 | private val factory = manager.getOWLDataFactory() | ||
| 52 | |||
| 43 | /** Represents the result of the conversion of a | 53 | /** Represents the result of the conversion of a |
| 44 | * [[org.semanticweb.owlapi.model.OWLClassExpression OWLClassExpression]]. | 54 | * [[org.semanticweb.owlapi.model.OWLClassExpression OWLClassExpression]]. |
| 45 | * | 55 | * |
| @@ -228,14 +238,11 @@ trait RDFoxConverter { | |||
| 228 | * - [[org.semanticweb.owlapi.model.OWLDataAllValuesFrom OWLDataAllValuesFrom]] | 238 | * - [[org.semanticweb.owlapi.model.OWLDataAllValuesFrom OWLDataAllValuesFrom]] |
| 229 | * - [[org.semanticweb.owlapi.model.OWLDataExactCardinality OWLDataExactCardinality]] | 239 | * - [[org.semanticweb.owlapi.model.OWLDataExactCardinality OWLDataExactCardinality]] |
| 230 | * - [[org.semanticweb.owlapi.model.OWLDataMaxCardinality OWLDataMaxCardinality]] | 240 | * - [[org.semanticweb.owlapi.model.OWLDataMaxCardinality OWLDataMaxCardinality]] |
| 231 | * - [[org.semanticweb.owlapi.model.OWLDataMinCardinality OWLDataMinCardinality]] | ||
| 232 | * - [[org.semanticweb.owlapi.model.OWLDataHasValue OWLDataHasValue]] | 241 | * - [[org.semanticweb.owlapi.model.OWLDataHasValue OWLDataHasValue]] |
| 233 | * - [[org.semanticweb.owlapi.model.OWLObjectAllValuesFrom OWLObjectAllValuesFrom]] | 242 | * - [[org.semanticweb.owlapi.model.OWLObjectAllValuesFrom OWLObjectAllValuesFrom]] |
| 234 | * - [[org.semanticweb.owlapi.model.OWLObjectComplementOf OWLObjectComplementOf]] | 243 | * - [[org.semanticweb.owlapi.model.OWLObjectComplementOf OWLObjectComplementOf]] |
| 235 | * - [[org.semanticweb.owlapi.model.OWLObjectExactCardinality OWLObjectExactCardinality]] | 244 | * - [[org.semanticweb.owlapi.model.OWLObjectExactCardinality OWLObjectExactCardinality]] |
| 236 | * - [[org.semanticweb.owlapi.model.OWLObjectHasSelf OWLObjectHasSelf]] | 245 | * - [[org.semanticweb.owlapi.model.OWLObjectHasSelf OWLObjectHasSelf]] |
| 237 | * - [[org.semanticweb.owlapi.model.OWLObjectHasValue OWLObjectHasValue]] | ||
| 238 | * - [[org.semanticweb.owlapi.model.OWLObjectMinCardinality OWLObjectMinCardinality]] | ||
| 239 | * - [[org.semanticweb.owlapi.model.OWLObjectUnionOf OWLObjectUnionOf]] | 246 | * - [[org.semanticweb.owlapi.model.OWLObjectUnionOf OWLObjectUnionOf]] |
| 240 | * | 247 | * |
| 241 | * Moreover: | 248 | * Moreover: |
| @@ -365,6 +372,60 @@ trait RDFoxConverter { | |||
| 365 | (List(eq), res.flatten ++ props) | 372 | (List(eq), res.flatten ++ props) |
| 366 | } | 373 | } |
| 367 | 374 | ||
| 375 | /** Minimum cardinality restriction class | ||
| 376 | * | ||
| 377 | * @note we only admit classes with cardinality set to 1 because | ||
| 378 | * they are equivalent to existential quantification. | ||
| 379 | * | ||
| 380 | * @throws `RuntimeException` when dealing with a restriction | ||
| 381 | * with cardinality != 1. | ||
| 382 | * | ||
| 383 | * @see [[https://www.w3.org/TR/owl2-syntax/#Minimum_Cardinality]] | ||
| 384 | */ | ||
| 385 | case e: OWLObjectMinCardinality => { | ||
| 386 | if (e.getCardinality != 1) | ||
| 387 | throw new RuntimeException( | ||
| 388 | s"Class expression '$e' has cardinality restriction != 1." | ||
| 389 | ) | ||
| 390 | val filler = e.getFiller | ||
| 391 | val property = e.getProperty | ||
| 392 | val expr = factory.getOWLObjectSomeValuesFrom(property, filler) | ||
| 393 | convert(expr, term, unsafe, skolem, suffix) | ||
| 394 | } | ||
| 395 | |||
| 396 | /** Minimum cardinality restriction class | ||
| 397 | * | ||
| 398 | * @note we only admit classes with cardinality set to 1 because | ||
| 399 | * they are equivalent to existential quantification. | ||
| 400 | * | ||
| 401 | * @throws `RuntimeException` when dealing with a restriction | ||
| 402 | * with cardinality != 1. | ||
| 403 | * | ||
| 404 | * @see [[http://www.w3.org/TR/owl2-syntax/#Minimum_Cardinality_2]] | ||
| 405 | */ | ||
| 406 | case e: OWLDataMinCardinality => { | ||
| 407 | if (e.getCardinality != 1) | ||
| 408 | throw new RuntimeException( | ||
| 409 | s"Class expression '$e' has cardinality restriction != 1." | ||
| 410 | ) | ||
| 411 | val filler = e.getFiller | ||
| 412 | val property = e.getProperty | ||
| 413 | val expr = factory.getOWLDataSomeValuesFrom(property, filler) | ||
| 414 | convert(expr, term, unsafe, skolem, suffix) | ||
| 415 | } | ||
| 416 | |||
| 417 | /** Existential quantification with singleton filler | ||
| 418 | * | ||
| 419 | * @see | ||
| 420 | * [[http://www.w3.org/TR/owl2-syntax/#Individual_Value_Restriction]] | ||
| 421 | */ | ||
| 422 | case e: OWLObjectHasValue => { | ||
| 423 | val term1: Term = e.getFiller match { | ||
| 424 | case i: OWLNamedIndividual => i.getIRI | ||
| 425 | case i: OWLAnonymousIndividual => i.getID | ||
| 426 | } | ||
| 427 | (List(convert(e.getProperty, term, term1, suffix)), List()) | ||
| 428 | } | ||
| 368 | /** Catch-all case for all unhandled class expressions. */ | 429 | /** Catch-all case for all unhandled class expressions. */ |
| 369 | case e => | 430 | case e => |
| 370 | throw new RuntimeException( | 431 | throw new RuntimeException( |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/implicits/RDFox.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/implicits/RDFox.scala index 35bf25c..0407ae9 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/implicits/RDFox.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/implicits/RDFox.scala | |||
| @@ -1,8 +1,17 @@ | |||
| 1 | package uk.ac.ox.cs.rsacomb.implicits | 1 | package uk.ac.ox.cs.rsacomb.implicits |
| 2 | 2 | ||
| 3 | import tech.oxfordsemantic.jrdfox.logic.Datatype | 3 | import tech.oxfordsemantic.jrdfox.logic.Datatype |
| 4 | import tech.oxfordsemantic.jrdfox.logic.expression.{IRI => RDFoxIRI, Literal} | 4 | import tech.oxfordsemantic.jrdfox.logic.expression.{ |
| 5 | import org.semanticweb.owlapi.model.{IRI => OWLIRI, OWLLiteral, OWLDatatype} | 5 | BlankNode, |
| 6 | IRI => RDFoxIRI, | ||
| 7 | Literal | ||
| 8 | } | ||
| 9 | import org.semanticweb.owlapi.model.{ | ||
| 10 | IRI => OWLIRI, | ||
| 11 | NodeID, | ||
| 12 | OWLLiteral, | ||
| 13 | OWLDatatype | ||
| 14 | } | ||
| 6 | import org.semanticweb.owlapi.vocab.OWL2Datatype | 15 | import org.semanticweb.owlapi.vocab.OWL2Datatype |
| 7 | 16 | ||
| 8 | object RDFox { | 17 | object RDFox { |
| @@ -13,6 +22,12 @@ object RDFox { | |||
| 13 | implicit def owlapiToRdfoxIri(iri: OWLIRI): RDFoxIRI = | 22 | implicit def owlapiToRdfoxIri(iri: OWLIRI): RDFoxIRI = |
| 14 | RDFoxIRI.create(iri.getIRIString()) | 23 | RDFoxIRI.create(iri.getIRIString()) |
| 15 | 24 | ||
| 25 | implicit def nodeIdToBlankNode(node: NodeID): BlankNode = | ||
| 26 | BlankNode.create(node.getID) | ||
| 27 | |||
| 28 | implicit def blankNodeToNodeId(node: BlankNode): NodeID = | ||
| 29 | NodeID.getNodeID(node.getID) | ||
| 30 | |||
| 16 | implicit def stringToRdfoxIri(iri: String): RDFoxIRI = | 31 | implicit def stringToRdfoxIri(iri: String): RDFoxIRI = |
| 17 | RDFoxIRI.create(iri) | 32 | RDFoxIRI.create(iri) |
| 18 | 33 | ||
