blob: ca7740948e704f06a0106e53fb2a86096df8f291 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*
* Copyright 2020, 2021 KRR Oxford
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package uk.ac.ox.cs.rsacomb.implicits
import tech.oxfordsemantic.jrdfox.logic.Datatype
import tech.oxfordsemantic.jrdfox.logic.datalog.TupleTableName
import tech.oxfordsemantic.jrdfox.logic.expression.{
BlankNode,
IRI => RDFoxIRI,
Literal
}
import org.semanticweb.owlapi.model.{
IRI => OWLIRI,
NodeID,
OWLLiteral,
OWLDatatype
}
import org.semanticweb.owlapi.vocab.OWL2Datatype
object RDFox {
implicit def rdfoxToOwlapiIri(iri: RDFoxIRI): OWLIRI =
OWLIRI.create(iri.getIRI)
implicit def owlapiToRdfoxIri(iri: OWLIRI): RDFoxIRI =
RDFoxIRI.create(iri.getIRIString())
implicit def nodeIdToBlankNode(node: NodeID): BlankNode =
BlankNode.create(node.getID)
implicit def blankNodeToNodeId(node: BlankNode): NodeID =
NodeID.getNodeID(node.getID)
implicit def stringToRdfoxIri(iri: String): RDFoxIRI =
RDFoxIRI.create(iri)
implicit def iriToTupleTableName(iri: RDFoxIRI): TupleTableName =
TupleTableName.create(iri.getIRI)
/** Converst an OWLAPI datatype into an RDFox datatype.
*
* The builtin datatypes defined by the two systems do not match
* perfectly. In particular these entities cannot be directly
* translated.
*
* From the OWLAPI (mapped to `INVALID_DATATYPE`):
* - OWL_RATIONAL
* - OWL_REAL
* - RDF_LANG_STRING
* - RDF_XML_LITERAL
* - XSD_BASE_64_BINARY
* - XSD_HEX_BINARY
* - XSD_LANGUAGE
* - XSD_NAME
* - XSD_NCNAME
* - XSD_NMTOKEN
* - XSD_NORMALIZED_STRING
* - XSD_TOKEN
*
* From RDFox:
* - BLANK_NODE
* - IRI_REFERENCE
* - XSD_DATE
* - XSD_DAY_TIME_DURATION
* - XSD_DURATION
* - XSD_G_DAY
* - XSD_G_MONTH
* - XSD_G_MONTH_DAY
* - XSD_G_YEAR
* - XSD_G_YEAR_MONTH
* - XSD_TIME
* - XSD_YEAR_MONTH_DURATION
*/
implicit def owlapiToRdfoxDatatype(datatype: OWLDatatype): Datatype =
if (datatype.isBuiltIn) {
datatype.getBuiltInDatatype match {
case OWL2Datatype.RDF_PLAIN_LITERAL => Datatype.RDF_PLAIN_LITERAL
case OWL2Datatype.RDFS_LITERAL => Datatype.RDFS_LITERAL
case OWL2Datatype.XSD_ANY_URI => Datatype.XSD_ANY_URI
case OWL2Datatype.XSD_BOOLEAN => Datatype.XSD_BOOLEAN
case OWL2Datatype.XSD_BYTE => Datatype.XSD_BYTE
case OWL2Datatype.XSD_DATE_TIME => Datatype.XSD_DATE_TIME
case OWL2Datatype.XSD_DATE_TIME_STAMP => Datatype.XSD_DATE_TIME_STAMP
case OWL2Datatype.XSD_DECIMAL => Datatype.XSD_DECIMAL
case OWL2Datatype.XSD_DOUBLE => Datatype.XSD_DOUBLE
case OWL2Datatype.XSD_FLOAT => Datatype.XSD_FLOAT
case OWL2Datatype.XSD_INT => Datatype.XSD_INT
case OWL2Datatype.XSD_INTEGER => Datatype.XSD_INTEGER
case OWL2Datatype.XSD_LONG => Datatype.XSD_LONG
case OWL2Datatype.XSD_NEGATIVE_INTEGER => Datatype.XSD_NEGATIVE_INTEGER
case OWL2Datatype.XSD_NON_NEGATIVE_INTEGER =>
Datatype.XSD_NON_NEGATIVE_INTEGER
case OWL2Datatype.XSD_NON_POSITIVE_INTEGER =>
Datatype.XSD_NON_POSITIVE_INTEGER
case OWL2Datatype.XSD_POSITIVE_INTEGER => Datatype.XSD_POSITIVE_INTEGER
case OWL2Datatype.XSD_SHORT => Datatype.XSD_SHORT
case OWL2Datatype.XSD_STRING => Datatype.XSD_STRING
case OWL2Datatype.XSD_UNSIGNED_BYTE => Datatype.XSD_UNSIGNED_BYTE
case OWL2Datatype.XSD_UNSIGNED_INT => Datatype.XSD_UNSIGNED_INT
case OWL2Datatype.XSD_UNSIGNED_LONG => Datatype.XSD_UNSIGNED_LONG
case OWL2Datatype.XSD_UNSIGNED_SHORT => Datatype.XSD_UNSIGNED_SHORT
case _ => Datatype.INVALID_DATATYPE
}
} else {
throw new RuntimeException(
s"Composite datatypes are not allowed."
)
}
implicit def owlapiToRdfoxLiteral(lit: OWLLiteral): Literal =
Literal.create(lit.getLiteral, lit.getDatatype)
}
|