aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Igne <federico.igne@cs.ox.ac.uk>2022-05-19 15:11:06 +0100
committerFederico Igne <federico.igne@cs.ox.ac.uk>2022-05-19 15:21:37 +0100
commitace698dedd486e64127aeb96af6675fa461377ed (patch)
tree12cf487417449df05cd14714f3f6639c6aa8c7da
parent3b21b25763dffd117488e99378d466fcf97c6d52 (diff)
downloadRSAComb-ace698dedd486e64127aeb96af6675fa461377ed.tar.gz
RSAComb-ace698dedd486e64127aeb96af6675fa461377ed.zip
refactor: RSA utilsdevelop
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/converter/SkolemStrategy.scala4
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/util/RSA.scala127
2 files changed, 116 insertions, 15 deletions
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/SkolemStrategy.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/SkolemStrategy.scala
index 92763d0..1a46e2e 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/converter/SkolemStrategy.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/converter/SkolemStrategy.scala
@@ -20,6 +20,8 @@ import org.semanticweb.owlapi.model.OWLAxiom
20import tech.oxfordsemantic.jrdfox.logic.Datatype 20import tech.oxfordsemantic.jrdfox.logic.Datatype
21import tech.oxfordsemantic.jrdfox.logic.expression.{Literal, IRI} 21import tech.oxfordsemantic.jrdfox.logic.expression.{Literal, IRI}
22 22
23import uk.ac.ox.cs.rsacomb.util.RSA
24
23sealed trait SkolemStrategy { 25sealed trait SkolemStrategy {
24 def dup(a: OWLAxiom): SkolemStrategy 26 def dup(a: OWLAxiom): SkolemStrategy
25} 27}
@@ -91,5 +93,5 @@ case class Standard(axiom: OWLAxiom)(implicit toString: (OWLAxiom) => String)
91case class Constant(axiom: OWLAxiom)(implicit toString: (OWLAxiom) => String) 93case class Constant(axiom: OWLAxiom)(implicit toString: (OWLAxiom) => String)
92 extends SkolemStrategy { 94 extends SkolemStrategy {
93 def dup(_axiom: OWLAxiom): Constant = copy(axiom = _axiom)(toString) 95 def dup(_axiom: OWLAxiom): Constant = copy(axiom = _axiom)(toString)
94 lazy val iri = IRI.create(s"c_${toString(axiom)}") 96 lazy val iri = RSA(s"c_${toString(axiom)}")
95} 97}
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/util/RSA.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/util/RSA.scala
index 6ea4dc6..5e76421 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/util/RSA.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/util/RSA.scala
@@ -22,9 +22,10 @@ import java.util.Map
22import tech.oxfordsemantic.jrdfox.formats.SPARQLParser 22import tech.oxfordsemantic.jrdfox.formats.SPARQLParser
23import tech.oxfordsemantic.jrdfox.Prefixes 23import tech.oxfordsemantic.jrdfox.Prefixes
24import tech.oxfordsemantic.jrdfox.logic.datalog.{ 24import tech.oxfordsemantic.jrdfox.logic.datalog.{
25 Negation,
26 Rule,
25 TupleTableAtom, 27 TupleTableAtom,
26 TupleTableName, 28 TupleTableName,
27 Negation
28} 29}
29import tech.oxfordsemantic.jrdfox.logic.expression.{Term, Variable, IRI} 30import tech.oxfordsemantic.jrdfox.logic.expression.{Term, Variable, IRI}
30import org.semanticweb.owlapi.model.OWLOntology 31import org.semanticweb.owlapi.model.OWLOntology
@@ -45,9 +46,13 @@ object RSA {
45 /** Simplify conversion between Java and Scala `List`s */ 46 /** Simplify conversion between Java and Scala `List`s */
46 import uk.ac.ox.cs.rsacomb.implicits.JavaCollections._ 47 import uk.ac.ox.cs.rsacomb.implicits.JavaCollections._
47 48
49 /** Experimental DLS for RDFox */
50 import RDFoxDSL._
51
48 /** Set of default prefixes to be included in all datastore operations */ 52 /** Set of default prefixes to be included in all datastore operations */
49 val Prefixes: Prefixes = new Prefixes() 53 val Prefixes: Prefixes = new Prefixes()
50 Prefixes.declarePrefix("xml:", "http://www.w3.org/XML/1998/namespace") 54 Prefixes.declarePrefix("xml:", "http://www.w3.org/XML/1998/namespace")
55 Prefixes.declarePrefix("xsd:", "http://www.w3.org/2001/XMLSchema#")
51 Prefixes.declarePrefix("rdf:", "http://www.w3.org/1999/02/22-rdf-syntax-ns#") 56 Prefixes.declarePrefix("rdf:", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
52 Prefixes.declarePrefix("rdfs:", "http://www.w3.org/2000/01/rdf-schema#") 57 Prefixes.declarePrefix("rdfs:", "http://www.w3.org/2000/01/rdf-schema#")
53 Prefixes.declarePrefix("owl:", "http://www.w3.org/2002/07/owl#") 58 Prefixes.declarePrefix("owl:", "http://www.w3.org/2002/07/owl#")
@@ -57,7 +62,6 @@ object RSA {
57 /** Creates a `rsacomb:<name>` IRI */ 62 /** Creates a `rsacomb:<name>` IRI */
58 def apply(name: Any): IRI = 63 def apply(name: Any): IRI =
59 IRI.create( 64 IRI.create(
60 //Prefixes.decodeIRI("rsacomb:") + name.toString
61 Prefixes.getPrefixIRIsByPrefixName.get("rsacomb:").getIRI + name.toString 65 Prefixes.getPrefixIRIsByPrefixName.get("rsacomb:").getIRI + name.toString
62 ) 66 )
63 67
@@ -73,6 +77,8 @@ object RSA {
73 val QM = RSA("QM") 77 val QM = RSA("QM")
74 val SP = RSA("SP") 78 val SP = RSA("SP")
75 val TQ = RSA("TQ") 79 val TQ = RSA("TQ")
80 val E = RSA("E")
81 val U = RSA("U")
76 82
77 def Named(tt: TupleTableName)(x: Term): TupleTableAtom = 83 def Named(tt: TupleTableName)(x: Term): TupleTableAtom =
78 TupleTableAtom.create(tt, x, IRI.RDF_TYPE, RSA.NAMED) 84 TupleTableAtom.create(tt, x, IRI.RDF_TYPE, RSA.NAMED)
@@ -80,24 +86,117 @@ object RSA {
80 TupleTableAtom.create(tt, x, RSA.CONGRUENT, y) 86 TupleTableAtom.create(tt, x, RSA.CONGRUENT, y)
81 def Skolem(skolem: Term, terms: List[Term]): TupleTableAtom = 87 def Skolem(skolem: Term, terms: List[Term]): TupleTableAtom =
82 TupleTableAtom.create(TupleTableName.SKOLEM, terms :+ skolem) 88 TupleTableAtom.create(TupleTableName.SKOLEM, terms :+ skolem)
89 def E(tt: TupleTableName)(x: Term, y: Term): TupleTableAtom =
90 TupleTableAtom.create(tt, x, RSA.E, y)
91 def PE(tt: TupleTableName)(x: Term, y: Term) =
92 TupleTableAtom.create(tt, x, RSA("PE"), y)
93 def U(tt: TupleTableName)(x: Term): TupleTableAtom =
94 TupleTableAtom.create(tt, x, IRI.RDF_TYPE, RSA.U)
83 95
84 // def In(t: Term)(implicit set: Term) = 96 // def In(t: Term)(implicit set: Term) =
85 // TupleTableAtom.rdf(t, RSA("In"), set) 97 // TupleTableAtom.rdf(t, RSA("In"), set)
86
87 // def NotIn(t: Term)(implicit set: Term) = Negation.create(In(t)(set)) 98 // def NotIn(t: Term)(implicit set: Term) = Negation.create(In(t)(set))
88
89 /* TODO: review after reworking the dependency graph construction */
90
91 // private def atom(name: IRI, vars: List[Term]): TupleTableAtom = 99 // private def atom(name: IRI, vars: List[Term]): TupleTableAtom =
92 // TupleTableAtom.create(TupleTableName.create(name.getIRI), vars: _*) 100 // TupleTableAtom.create(TupleTableName.create(name.getIRI), vars: _*)
93 101
94 def E(t1: Term, t2: Term) = 102 def RBoxReasoning(graph: IRI): List[Rule] = {
95 TupleTableAtom.rdf(t1, RSA("E"), t2) 103 val tt = TupleTableName.create(graph.getIRI)
96 104 val subPropertyOf = IRI.create(Prefixes.getPrefixIRIsByPrefixName.get("rdfs:").getIRI + "subPropertyOf")
97 def PE(t1: Term, t2: Term) = 105 val subPropertyOfTrans = RSA("subPropertyOfTrans")
98 TupleTableAtom.rdf(t1, RSA("PE"), t2) 106 val inverseOf = IRI.create(Prefixes.getPrefixIRIsByPrefixName.get("owl:").getIRI + "inverseOf")
99 107 List(
100 def U(t: Term) = 108 Rule.create(
101 TupleTableAtom.rdf(t, IRI.RDF_TYPE, RSA("U")) 109 TupleTableAtom.create(tt, v"X", subPropertyOfTrans, v"Y"),
110 TupleTableAtom.create(tt, v"X", subPropertyOf, v"Y"),
111 ),
112 Rule.create(
113 TupleTableAtom.create(tt, v"X", subPropertyOfTrans, v"Z"),
114 TupleTableAtom.create(tt, v"X", subPropertyOfTrans, v"Y"),
115 TupleTableAtom.create(tt, v"Y", subPropertyOfTrans, v"Z")
116 ),
117 Rule.create(
118 TupleTableAtom.create(tt, v"Yi", subPropertyOf, v"Xi"),
119 TupleTableAtom.create(tt, v"X", subPropertyOf, v"Y"),
120 TupleTableAtom.create(tt, v"Xi", inverseOf, v"X"),
121 TupleTableAtom.create(tt, v"Yi", inverseOf, v"Y"),
122 ),
123 Rule.create(
124 TupleTableAtom.create(tt, v"X", inverseOf, v"Y"),
125 TupleTableAtom.create(tt, v"Y", inverseOf, v"X"),
126 )
127 )
128 }
102 129
103} 130}
131
132/** Some common ontology prefixes:
133 *
134 * @prefix dc: <http://purl.org/dc/elements/1.1/> .
135 * @prefix ex: <http://semantics.id/ns/example#> .
136 * @prefix fn: <http://www.w3.org/2005/xpath-functions> .
137 * @prefix ms: <http://www.novartis.com/metastore#> .
138 * @prefix vb: <http://eresources.nlb.gov.sg/ID/NLBDM/vocab/> .
139 * @prefix xs: <http://www.w3.org/2001/XMLSchema> .
140 * @prefix NBN: <http://urn.fi/#> .
141 * @prefix XML: <http://www.w3.org/XML/1998/> .
142 * @prefix bot: <https://w3id.org/bot#> .
143 * @prefix cbx: <http://cybox.mitre.org/cybox_v1#> .
144 * @prefix dct: <http://purl.org/dc/terms/> .
145 * @prefix esv: <http://eresources.nlb.gov.sg/ID/NLBDM/vocab-esv/> .
146 * @prefix gss: <http://www.w3.org/2001/11/IsaViz/graphstylesheets#> .
147 * @prefix ioc: <http://w3id.org/ioc#> .
148 * @prefix j.0: <http://www.eurovision.com#> .
149 * @prefix mlo: <http://www.a2rd.net.br/mlo#> .
150 * @prefix ns1: <http://eresources.nlb.gov.sg/ID/NLBDM/marcext/> .
151 * @prefix ns2: <http://bibfra.me/vocab/marc/> .
152 * @prefix ns3: <http://eresources.nlb.gov.sg/ID/NLBDM/vocab-ccv/> .
153 * @prefix ns4: <http://bio2rdf.org/bio2rdf_vocabulary:> .
154 * @prefix obo: <http://purl.obolibrary.org/obo/> .
155 * @prefix owl: <http://www.w3.org/2002/07/owl#> .
156 * @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
157 * @prefix tmp: <http://www.semanticweb.org/maria/ontologies/2021/9/running_example#> .
158 * @prefix www: <http://www.movieontology.org/2009/11/09/> .
159 * @prefix xml: <http://www.w3.org/XML/1998/namespace> .
160 * @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
161 * @prefix xsp: <http://www.owl-ontologies.com/2005/08/07/xsp.owl#> .
162 * @prefix bibo: <http://purl.org/ontology/bibo/> .
163 * @prefix daml: <http://www.daml.org/2001/03/daml+oil#> .
164 * @prefix foaf: <http://xmlns.com/foaf/0.1/> .
165 * @prefix lego: <http://spatialai.org/lego/core/v1#> .
166 * @prefix mlo1: <http://www.a2rd.net.br/mlo#mlo:> .
167 * @prefix mlo2: <http://www.semanticweb.org/user/ontologies/2020/0/ml-ontology#mlo:> .
168 * @prefix obda: <https://w3id.org/obda/vocabulary#> .
169 * @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
170 * @prefix skos: <http://www.w3.org/2004/02/skos/core#> .
171 * @prefix swrl: <http://www.w3.org/2003/11/swrl#> .
172 * @prefix vann: <http://purl.org/vocab/vann/> .
173 * @prefix void: <http://rdfs.org/ns/void#> .
174 * @prefix admin: <http://webns.net/mvcb/> .
175 * @prefix nlbdm: <http://eresources.nlb.gov.sg/ID/NLBDM/vocab/> .
176 * @prefix pizza: <http://www.co-ode.org/ontologies/pizza/pizza.owl#> .
177 * @prefix pstcn: <http://burningbird.net/postcon/elements/1.0/> .
178 * @prefix swrla: <http://swrl.stanford.edu/ontologies/3.3/swrla.owl#> .
179 * @prefix swrlb: <http://www.w3.org/2003/11/swrlb#> .
180 * @prefix terms: <http://purl.org/dc/terms/> .
181 * @prefix vcard: <http://www.w3.org/2006/vcard/ns#> .
182 * @prefix PLCore: <http://www.perpetuallabs.io/ontologies/2021/9/PLCore#> .
183 * @prefix Server: <urn:absolute:Server#> .
184 * @prefix TypeQL: <http://www.perpetuallabs.io/ontologies/2021/9/TypeQL#> .
185 * @prefix schema: <http://schema.org/> .
186 * @prefix travel: <http://www.owl-ontologies.com/travel.owl#> .
187 * @prefix current: <http://erlangen-crm.org/current/> .
188 * @prefix dcterms: <http://purl.org/dc/terms/> .
189 * @prefix ebucore: <http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#> .
190 * @prefix example: <http://www.ics.forth.gr/example#> .
191 * @prefix ontokin: <http://www.theworldavatar.com/kb/ontokin/ontokin.owl#> .
192 * @prefix opla-sd: <http://ontologydesignpatterns.org/opla-sd#> .
193 * @prefix owl2xml: <http://www.w3.org/2006/12/owl2-xml#> .
194 * @prefix protege: <http://protege.stanford.edu/plugins/owl/protege#> .
195 * @prefix mappings: <http://www.cs.ox.ac.uk/isg/projects/LogMap/mappings.owl#> .
196 * @prefix oboInOwl: <http://www.geneontology.org/formats/oboInOwl#> .
197 * @prefix otherOnt: <http://example.org/otherOntologies/families/> .
198 * @prefix EurosData: <http://www.EurosFile.com/EurosData#> .
199 * @prefix geosparql: <http://www.opengis.net/ont/geosparql#> .
200 * @prefix restaurant: <http://www.univrouen.fr/ontologies/restaurant#> .
201 * @prefix ml-ontology: <http://www.semanticweb.org/user/ontologies/2020/0/ml-ontology#> .
202 */