aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/converter/RDFoxConverter.scala15
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/implicits/RDFox.scala88
2 files changed, 95 insertions, 8 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 4f4df26..6c83caf 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
@@ -8,6 +8,7 @@ import org.semanticweb.owlapi.model.{
8 OWLClassAssertionAxiom, 8 OWLClassAssertionAxiom,
9 OWLClassExpression, 9 OWLClassExpression,
10 OWLDataProperty, 10 OWLDataProperty,
11 OWLDataPropertyAssertionAxiom,
11 OWLDataPropertyDomainAxiom, 12 OWLDataPropertyDomainAxiom,
12 OWLDataPropertyExpression, 13 OWLDataPropertyExpression,
13 OWLDataSomeValuesFrom, 14 OWLDataSomeValuesFrom,
@@ -219,6 +220,20 @@ trait RDFoxConverter {
219 ResultF(List(prop)) 220 ResultF(List(prop))
220 } 221 }
221 222
223 /** Data property assertion.
224 *
225 * @see [[org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom OWLDataPropertyAssertionAxiom]]
226 */
227 case a: OWLDataPropertyAssertionAxiom =>
228 if (!a.getSubject.isNamed || !a.getObject.isNamed)
229 Result()
230 else {
231 val subj = a.getSubject.asOWLNamedIndividual.getIRI
232 val obj = a.getObject
233 val prop = convert(a.getProperty, subj, obj, suffix)
234 ResultF(List(prop))
235 }
236
222 /** Catch-all case for all unhandled axiom types. */ 237 /** Catch-all case for all unhandled axiom types. */
223 case a => 238 case a =>
224 throw new RuntimeException( 239 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 0462a47..35bf25c 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,20 +1,92 @@
1package uk.ac.ox.cs.rsacomb.implicits 1package uk.ac.ox.cs.rsacomb.implicits
2 2
3import tech.oxfordsemantic.jrdfox.logic.expression.{IRI => RDFoxIRI} 3import tech.oxfordsemantic.jrdfox.logic.Datatype
4import org.semanticweb.owlapi.model.{IRI => OWLIRI} 4import tech.oxfordsemantic.jrdfox.logic.expression.{IRI => RDFoxIRI, Literal}
5import org.semanticweb.owlapi.model.{IRI => OWLIRI, OWLLiteral, OWLDatatype}
6import org.semanticweb.owlapi.vocab.OWL2Datatype
5 7
6object RDFox { 8object RDFox {
7 9
8 implicit def rdfoxToOwlapiIri(iri: RDFoxIRI): OWLIRI = { 10 implicit def rdfoxToOwlapiIri(iri: RDFoxIRI): OWLIRI =
9 OWLIRI.create(iri.getIRI) 11 OWLIRI.create(iri.getIRI)
10 }
11 12
12 implicit def owlapiToRdfoxIri(iri: OWLIRI): RDFoxIRI = { 13 implicit def owlapiToRdfoxIri(iri: OWLIRI): RDFoxIRI =
13 RDFoxIRI.create(iri.getIRIString()) 14 RDFoxIRI.create(iri.getIRIString())
14 }
15 15
16 implicit def stringToRdfoxIri(iri: String): RDFoxIRI = { 16 implicit def stringToRdfoxIri(iri: String): RDFoxIRI =
17 RDFoxIRI.create(iri) 17 RDFoxIRI.create(iri)
18 } 18
19 /** Converst an OWLAPI datatype into an RDFox datatype.
20 *
21 * The builtin datatypes defined by the two systems do not match
22 * perfectly. In particular these entities cannot be directly
23 * translated.
24 *
25 * From the OWLAPI (mapped to `INVALID_DATATYPE`):
26 * - OWL_RATIONAL
27 * - OWL_REAL
28 * - RDF_LANG_STRING
29 * - RDF_XML_LITERAL
30 * - XSD_BASE_64_BINARY
31 * - XSD_HEX_BINARY
32 * - XSD_LANGUAGE
33 * - XSD_NAME
34 * - XSD_NCNAME
35 * - XSD_NMTOKEN
36 * - XSD_NORMALIZED_STRING
37 * - XSD_TOKEN
38 *
39 * From RDFox:
40 * - BLANK_NODE
41 * - IRI_REFERENCE
42 * - XSD_DATE
43 * - XSD_DAY_TIME_DURATION
44 * - XSD_DURATION
45 * - XSD_G_DAY
46 * - XSD_G_MONTH
47 * - XSD_G_MONTH_DAY
48 * - XSD_G_YEAR
49 * - XSD_G_YEAR_MONTH
50 * - XSD_TIME
51 * - XSD_YEAR_MONTH_DURATION
52 */
53 implicit def owlapiToRdfoxDatatype(datatype: OWLDatatype): Datatype =
54 if (datatype.isBuiltIn) {
55 datatype.getBuiltInDatatype match {
56 case OWL2Datatype.RDF_PLAIN_LITERAL => Datatype.RDF_PLAIN_LITERAL
57 case OWL2Datatype.RDFS_LITERAL => Datatype.RDFS_LITERAL
58 case OWL2Datatype.XSD_ANY_URI => Datatype.XSD_ANY_URI
59 case OWL2Datatype.XSD_BOOLEAN => Datatype.XSD_BOOLEAN
60 case OWL2Datatype.XSD_BYTE => Datatype.XSD_BYTE
61 case OWL2Datatype.XSD_DATE_TIME => Datatype.XSD_DATE_TIME
62 case OWL2Datatype.XSD_DATE_TIME_STAMP => Datatype.XSD_DATE_TIME_STAMP
63 case OWL2Datatype.XSD_DECIMAL => Datatype.XSD_DECIMAL
64 case OWL2Datatype.XSD_DOUBLE => Datatype.XSD_DOUBLE
65 case OWL2Datatype.XSD_FLOAT => Datatype.XSD_FLOAT
66 case OWL2Datatype.XSD_INT => Datatype.XSD_INT
67 case OWL2Datatype.XSD_INTEGER => Datatype.XSD_INTEGER
68 case OWL2Datatype.XSD_LONG => Datatype.XSD_LONG
69 case OWL2Datatype.XSD_NEGATIVE_INTEGER => Datatype.XSD_NEGATIVE_INTEGER
70 case OWL2Datatype.XSD_NON_NEGATIVE_INTEGER =>
71 Datatype.XSD_NON_NEGATIVE_INTEGER
72 case OWL2Datatype.XSD_NON_POSITIVE_INTEGER =>
73 Datatype.XSD_NON_POSITIVE_INTEGER
74 case OWL2Datatype.XSD_POSITIVE_INTEGER => Datatype.XSD_POSITIVE_INTEGER
75 case OWL2Datatype.XSD_SHORT => Datatype.XSD_SHORT
76 case OWL2Datatype.XSD_STRING => Datatype.XSD_STRING
77 case OWL2Datatype.XSD_UNSIGNED_BYTE => Datatype.XSD_UNSIGNED_BYTE
78 case OWL2Datatype.XSD_UNSIGNED_INT => Datatype.XSD_UNSIGNED_INT
79 case OWL2Datatype.XSD_UNSIGNED_LONG => Datatype.XSD_UNSIGNED_LONG
80 case OWL2Datatype.XSD_UNSIGNED_SHORT => Datatype.XSD_UNSIGNED_SHORT
81 case _ => Datatype.INVALID_DATATYPE
82 }
83 } else {
84 throw new RuntimeException(
85 s"Composite datatypes are not allowed."
86 )
87 }
88
89 implicit def owlapiToRdfoxLiteral(lit: OWLLiteral): Literal =
90 Literal.create(lit.getLiteral, lit.getDatatype)
19 91
20} 92}