diff options
| author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2021-10-30 23:17:42 +0100 |
|---|---|---|
| committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2021-10-30 23:17:42 +0100 |
| commit | 78f726607b32925923d7e48686f7c6e9c8d7e831 (patch) | |
| tree | 4b366cbed1e6a2312a608ef0cdfd868fb01f1b84 /src/main/scala | |
| parent | 49a8889b02a25b46aa52252fb96ec489800582c0 (diff) | |
| download | RSAComb-78f726607b32925923d7e48686f7c6e9c8d7e831.tar.gz RSAComb-78f726607b32925923d7e48686f7c6e9c8d7e831.zip | |
Finalise dbpedia functional testing
Diffstat (limited to 'src/main/scala')
7 files changed, 56 insertions, 12 deletions
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala index fe7a6db..1aa748a 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | |||
| @@ -59,6 +59,7 @@ object RSAComb extends App { | |||
| 59 | ) | 59 | ) |
| 60 | 60 | ||
| 61 | val answers = rsa ask queries | 61 | val answers = rsa ask queries |
| 62 | Logger print s"Number of answers: ${answers.length}" | ||
| 62 | 63 | ||
| 63 | /* Write answers to output file */ | 64 | /* Write answers to output file */ |
| 64 | os.write( | 65 | os.write( |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala index 2b165c4..a0d567e 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | |||
| @@ -214,7 +214,7 @@ class RSAOntology( | |||
| 214 | /** Retrieve individuals/literals in the ontology */ | 214 | /** Retrieve individuals/literals in the ontology */ |
| 215 | private val individuals: List[IRI] = | 215 | private val individuals: List[IRI] = |
| 216 | ontology | 216 | ontology |
| 217 | .getIndividualsInSignature() | 217 | .getIndividualsInSignature(Imports.INCLUDED) |
| 218 | .asScala | 218 | .asScala |
| 219 | .map(_.getIRI) | 219 | .map(_.getIRI) |
| 220 | .map(implicits.RDFox.owlapiToRdfoxIri) | 220 | .map(implicits.RDFox.owlapiToRdfoxIri) |
| @@ -588,23 +588,44 @@ class RSAOntology( | |||
| 588 | RDFoxUtil.addData(data, RSAOntology.CanonGraph, datafiles: _*) | 588 | RDFoxUtil.addData(data, RSAOntology.CanonGraph, datafiles: _*) |
| 589 | 589 | ||
| 590 | /* Top/equality axiomatization */ | 590 | /* Top/equality axiomatization */ |
| 591 | RDFoxUtil.updateData(data, | ||
| 592 | s""" | ||
| 593 | INSERT { | ||
| 594 | GRAPH ${RSAOntology.CanonGraph} { ?X a ${IRI.THING} } | ||
| 595 | } WHERE { | ||
| 596 | GRAPH ${RSAOntology.CanonGraph} { ?X ?Y ?Z } | ||
| 597 | } | ||
| 598 | """ | ||
| 599 | ) | ||
| 600 | RDFoxUtil.updateData(data, | ||
| 601 | s""" | ||
| 602 | INSERT { | ||
| 603 | GRAPH ${RSAOntology.CanonGraph} { ?Z a ${RSA.NAMED} } | ||
| 604 | } WHERE { | ||
| 605 | GRAPH ${RSAOntology.CanonGraph} { ?X ?Y ?Z }. | ||
| 606 | FILTER( ?Y != a ) | ||
| 607 | } | ||
| 608 | """ | ||
| 609 | ) | ||
| 591 | RDFoxUtil.addRules(data, topAxioms ++ equalityAxioms) | 610 | RDFoxUtil.addRules(data, topAxioms ++ equalityAxioms) |
| 592 | Logger.write(topAxioms.mkString("\n"), "axiomatisation.dlog") | 611 | Logger.write(topAxioms.mkString("\n"), "axiomatisation.dlog") |
| 593 | Logger.write(equalityAxioms.mkString("\n"), "axiomatisation.dlog") | 612 | Logger.write(equalityAxioms.mkString("\n"), "axiomatisation.dlog") |
| 594 | 613 | ||
| 595 | /* Introduce `rsacomb:Named` concept */ | 614 | /* Introduce `rsacomb:Named` concept */ |
| 596 | data.evaluateUpdate( | 615 | /* From data */ |
| 597 | null, // the base IRI for the query (if null, a default is used) | 616 | RDFoxUtil.updateData(data, |
| 598 | RSA.Prefixes, | ||
| 599 | s""" | 617 | s""" |
| 600 | INSERT { | 618 | INSERT { |
| 601 | GRAPH ${RSAOntology.CanonGraph} { ?X a ${RSA.NAMED} } | 619 | GRAPH ${RSAOntology.CanonGraph} { ?X a ${RSA.NAMED} } |
| 602 | } WHERE { | 620 | } WHERE { |
| 603 | GRAPH ${RSAOntology.CanonGraph} { ?X a ${IRI.THING} } | 621 | GRAPH ${RSAOntology.CanonGraph} { ?X a ${IRI.THING} } |
| 604 | } | 622 | } |
| 605 | """, | 623 | """ |
| 606 | new java.util.HashMap[String, String] | ||
| 607 | ) | 624 | ) |
| 625 | /* From ontology */ | ||
| 626 | val named = individuals.map(RSA.Named(RSAOntology.CanonGraph)(_)) | ||
| 627 | RDFoxUtil.addFacts(data, RSAOntology.CanonGraph, named) | ||
| 628 | Logger.write(named.mkString("", ".\n", ".\n"), "canonical_model.dlog") | ||
| 608 | 629 | ||
| 609 | /* Add canonical model */ | 630 | /* Add canonical model */ |
| 610 | Logger print s"Canonical model facts: ${this.canonicalModel.facts.length}" | 631 | Logger print s"Canonical model facts: ${this.canonicalModel.facts.length}" |
| @@ -630,7 +651,7 @@ class RSAOntology( | |||
| 630 | RDFoxUtil.addRules(data, filter.rules) | 651 | RDFoxUtil.addRules(data, filter.rules) |
| 631 | 652 | ||
| 632 | // TODO: We remove the rules, should we drop the tuple table as well? | 653 | // TODO: We remove the rules, should we drop the tuple table as well? |
| 633 | data.clearRulesAxiomsExplicateFacts() | 654 | //data.clearRulesAxiomsExplicateFacts() |
| 634 | 655 | ||
| 635 | /* Gather answers to the query */ | 656 | /* Gather answers to the query */ |
| 636 | val answers = RDFoxUtil | 657 | val answers = RDFoxUtil |
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 505937b..d9f000d 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 | |||
| @@ -350,7 +350,7 @@ trait RDFoxConverter { | |||
| 350 | (List(atom), List()) | 350 | (List(atom), List()) |
| 351 | } | 351 | } |
| 352 | 352 | ||
| 353 | /** Existential class expression (for data properties). | 353 | /** Existential class expression (for object properties). |
| 354 | * | 354 | * |
| 355 | * Parameter `skolem` is used to determine the skolemization | 355 | * Parameter `skolem` is used to determine the skolemization |
| 356 | * technique (if any) to use for the translation. | 356 | * technique (if any) to use for the translation. |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/util/DataFactory.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/util/DataFactory.scala index 848c6b5..863122e 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/util/DataFactory.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/util/DataFactory.scala | |||
| @@ -25,5 +25,5 @@ class DataFactory(private var counter: Integer) { | |||
| 25 | Variable.create(f"I${this.getNext()}%05d") | 25 | Variable.create(f"I${this.getNext()}%05d") |
| 26 | 26 | ||
| 27 | def getOWLClass(): OWLClass = | 27 | def getOWLClass(): OWLClass = |
| 28 | DataFactory.factory.getOWLClass(s"X${this.getNext()}") | 28 | DataFactory.factory.getOWLClass(RSA(s"tmp${this.getNext()}").getIRI) |
| 29 | } | 29 | } |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/util/Logger.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/util/Logger.scala index 0fcde53..f3b0232 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/util/Logger.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/util/Logger.scala | |||
| @@ -112,6 +112,8 @@ echo "\n[Import data]" | |||
| 112 | .map(d => s"""import > rsacomb:CanonicalModel \"$d\"""") | 112 | .map(d => s"""import > rsacomb:CanonicalModel \"$d\"""") |
| 113 | .mkString("\n") | 113 | .mkString("\n") |
| 114 | ++ s""" | 114 | ++ s""" |
| 115 | insert { graph rsacomb:CanonicalModel { ?x a owl:Thing } } where { graph rsacomb:CanonicalModel { ?x ?y ?z } } | ||
| 116 | insert { graph rsacomb:CanonicalModel { ?z a owl:Thing } } where { graph rsacomb:CanonicalModel { ?x ?y ?z } . filter( ?y != a ) } | ||
| 115 | import "axiomatisation.dlog" | 117 | import "axiomatisation.dlog" |
| 116 | insert { graph rsacomb:CanonicalModel { ?x a rsacomb:Named } } where { graph rsacomb:CanonicalModel { ?x a owl:Thing } } | 118 | insert { graph rsacomb:CanonicalModel { ?x a rsacomb:Named } } where { graph rsacomb:CanonicalModel { ?x a owl:Thing } } |
| 117 | 119 | ||
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala index e3e7dd4..d4e55d8 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala | |||
| @@ -183,7 +183,7 @@ object RDFoxUtil { | |||
| 183 | /** Imports a sequence of files directly into a datastore. | 183 | /** Imports a sequence of files directly into a datastore. |
| 184 | * | 184 | * |
| 185 | * @param data datastore connection. | 185 | * @param data datastore connection. |
| 186 | * @param graph named graph where the data should be uploaded | 186 | * @param graph named graph where the data should be uploaded. |
| 187 | * @param files sequence of files to upload. | 187 | * @param files sequence of files to upload. |
| 188 | */ | 188 | */ |
| 189 | def addData(data: DataStoreConnection, graph: IRI, files: os.Path*): Unit = | 189 | def addData(data: DataStoreConnection, graph: IRI, files: os.Path*): Unit = |
| @@ -200,6 +200,23 @@ object RDFoxUtil { | |||
| 200 | Logger.DEBUG | 200 | Logger.DEBUG |
| 201 | ) | 201 | ) |
| 202 | 202 | ||
| 203 | /** Execute an update SPARQL query on a datastore. | ||
| 204 | * | ||
| 205 | * @param data datastore connection. | ||
| 206 | * @param query update SPARQL query. | ||
| 207 | */ | ||
| 208 | def updateData(data: DataStoreConnection, query: String): Unit = | ||
| 209 | Logger.timed( | ||
| 210 | data.evaluateUpdate( | ||
| 211 | null, // the base IRI for the query (if null, a default is used) | ||
| 212 | RSA.Prefixes, | ||
| 213 | query, | ||
| 214 | new java.util.HashMap[String, String] | ||
| 215 | ), | ||
| 216 | "Updating data", | ||
| 217 | Logger.DEBUG | ||
| 218 | ) | ||
| 219 | |||
| 203 | /** Force materialization in RDFox. */ | 220 | /** Force materialization in RDFox. */ |
| 204 | def materialize(data: DataStoreConnection): Unit = | 221 | def materialize(data: DataStoreConnection): Unit = |
| 205 | Logger.timed(data.updateMaterialization(), "Materialization", Logger.DEBUG) | 222 | Logger.timed(data.updateMaterialization(), "Materialization", Logger.DEBUG) |
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 5abb83c..6ea4dc6 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 | |||
| @@ -47,9 +47,12 @@ object RSA { | |||
| 47 | 47 | ||
| 48 | /** Set of default prefixes to be included in all datastore operations */ | 48 | /** Set of default prefixes to be included in all datastore operations */ |
| 49 | val Prefixes: Prefixes = new Prefixes() | 49 | val Prefixes: Prefixes = new Prefixes() |
| 50 | Prefixes.declarePrefix("rsacomb:", "http://www.cs.ox.ac.uk/isg/RSAComb#") | 50 | Prefixes.declarePrefix("xml:", "http://www.w3.org/XML/1998/namespace") |
| 51 | Prefixes.declarePrefix("rdfox:", "http://oxfordsemantic.tech/RDFox#") | 51 | 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#") | ||
| 52 | Prefixes.declarePrefix("owl:", "http://www.w3.org/2002/07/owl#") | 53 | Prefixes.declarePrefix("owl:", "http://www.w3.org/2002/07/owl#") |
| 54 | Prefixes.declarePrefix("rdfox:", "http://oxfordsemantic.tech/RDFox#") | ||
| 55 | Prefixes.declarePrefix("rsacomb:", "http://www.cs.ox.ac.uk/isg/RSAComb#") | ||
| 53 | 56 | ||
| 54 | /** Creates a `rsacomb:<name>` IRI */ | 57 | /** Creates a `rsacomb:<name>` IRI */ |
| 55 | def apply(name: Any): IRI = | 58 | def apply(name: Any): IRI = |
