From 78f726607b32925923d7e48686f7c6e9c8d7e831 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Sat, 30 Oct 2021 23:17:42 +0100 Subject: Finalise dbpedia functional testing --- src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | 1 + .../scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | 35 +++++++++++++++++----- .../ox/cs/rsacomb/converter/RDFoxConverter.scala | 2 +- .../uk/ac/ox/cs/rsacomb/util/DataFactory.scala | 2 +- .../scala/uk/ac/ox/cs/rsacomb/util/Logger.scala | 2 ++ .../scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala | 19 +++++++++++- src/main/scala/uk/ac/ox/cs/rsacomb/util/RSA.scala | 7 +++-- 7 files changed, 56 insertions(+), 12 deletions(-) (limited to 'src/main/scala/uk/ac/ox/cs/rsacomb') 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 { ) val answers = rsa ask queries + Logger print s"Number of answers: ${answers.length}" /* Write answers to output file */ 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( /** Retrieve individuals/literals in the ontology */ private val individuals: List[IRI] = ontology - .getIndividualsInSignature() + .getIndividualsInSignature(Imports.INCLUDED) .asScala .map(_.getIRI) .map(implicits.RDFox.owlapiToRdfoxIri) @@ -588,23 +588,44 @@ class RSAOntology( RDFoxUtil.addData(data, RSAOntology.CanonGraph, datafiles: _*) /* Top/equality axiomatization */ + RDFoxUtil.updateData(data, + s""" + INSERT { + GRAPH ${RSAOntology.CanonGraph} { ?X a ${IRI.THING} } + } WHERE { + GRAPH ${RSAOntology.CanonGraph} { ?X ?Y ?Z } + } + """ + ) + RDFoxUtil.updateData(data, + s""" + INSERT { + GRAPH ${RSAOntology.CanonGraph} { ?Z a ${RSA.NAMED} } + } WHERE { + GRAPH ${RSAOntology.CanonGraph} { ?X ?Y ?Z }. + FILTER( ?Y != a ) + } + """ + ) RDFoxUtil.addRules(data, topAxioms ++ equalityAxioms) Logger.write(topAxioms.mkString("\n"), "axiomatisation.dlog") Logger.write(equalityAxioms.mkString("\n"), "axiomatisation.dlog") /* Introduce `rsacomb:Named` concept */ - data.evaluateUpdate( - null, // the base IRI for the query (if null, a default is used) - RSA.Prefixes, + /* From data */ + RDFoxUtil.updateData(data, s""" INSERT { GRAPH ${RSAOntology.CanonGraph} { ?X a ${RSA.NAMED} } } WHERE { GRAPH ${RSAOntology.CanonGraph} { ?X a ${IRI.THING} } } - """, - new java.util.HashMap[String, String] + """ ) + /* From ontology */ + val named = individuals.map(RSA.Named(RSAOntology.CanonGraph)(_)) + RDFoxUtil.addFacts(data, RSAOntology.CanonGraph, named) + Logger.write(named.mkString("", ".\n", ".\n"), "canonical_model.dlog") /* Add canonical model */ Logger print s"Canonical model facts: ${this.canonicalModel.facts.length}" @@ -630,7 +651,7 @@ class RSAOntology( RDFoxUtil.addRules(data, filter.rules) // TODO: We remove the rules, should we drop the tuple table as well? - data.clearRulesAxiomsExplicateFacts() + //data.clearRulesAxiomsExplicateFacts() /* Gather answers to the query */ 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 { (List(atom), List()) } - /** Existential class expression (for data properties). + /** Existential class expression (for object properties). * * Parameter `skolem` is used to determine the skolemization * 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) { Variable.create(f"I${this.getNext()}%05d") def getOWLClass(): OWLClass = - DataFactory.factory.getOWLClass(s"X${this.getNext()}") + DataFactory.factory.getOWLClass(RSA(s"tmp${this.getNext()}").getIRI) } 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]" .map(d => s"""import > rsacomb:CanonicalModel \"$d\"""") .mkString("\n") ++ s""" +insert { graph rsacomb:CanonicalModel { ?x a owl:Thing } } where { graph rsacomb:CanonicalModel { ?x ?y ?z } } +insert { graph rsacomb:CanonicalModel { ?z a owl:Thing } } where { graph rsacomb:CanonicalModel { ?x ?y ?z } . filter( ?y != a ) } import "axiomatisation.dlog" insert { graph rsacomb:CanonicalModel { ?x a rsacomb:Named } } where { graph rsacomb:CanonicalModel { ?x a owl:Thing } } 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 { /** Imports a sequence of files directly into a datastore. * * @param data datastore connection. - * @param graph named graph where the data should be uploaded + * @param graph named graph where the data should be uploaded. * @param files sequence of files to upload. */ def addData(data: DataStoreConnection, graph: IRI, files: os.Path*): Unit = @@ -200,6 +200,23 @@ object RDFoxUtil { Logger.DEBUG ) + /** Execute an update SPARQL query on a datastore. + * + * @param data datastore connection. + * @param query update SPARQL query. + */ + def updateData(data: DataStoreConnection, query: String): Unit = + Logger.timed( + data.evaluateUpdate( + null, // the base IRI for the query (if null, a default is used) + RSA.Prefixes, + query, + new java.util.HashMap[String, String] + ), + "Updating data", + Logger.DEBUG + ) + /** Force materialization in RDFox. */ def materialize(data: DataStoreConnection): Unit = 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 { /** Set of default prefixes to be included in all datastore operations */ val Prefixes: Prefixes = new Prefixes() - Prefixes.declarePrefix("rsacomb:", "http://www.cs.ox.ac.uk/isg/RSAComb#") - Prefixes.declarePrefix("rdfox:", "http://oxfordsemantic.tech/RDFox#") + Prefixes.declarePrefix("xml:", "http://www.w3.org/XML/1998/namespace") + Prefixes.declarePrefix("rdf:", "http://www.w3.org/1999/02/22-rdf-syntax-ns#") + Prefixes.declarePrefix("rdfs:", "http://www.w3.org/2000/01/rdf-schema#") Prefixes.declarePrefix("owl:", "http://www.w3.org/2002/07/owl#") + Prefixes.declarePrefix("rdfox:", "http://oxfordsemantic.tech/RDFox#") + Prefixes.declarePrefix("rsacomb:", "http://www.cs.ox.ac.uk/isg/RSAComb#") /** Creates a `rsacomb:` IRI */ def apply(name: Any): IRI = -- cgit v1.2.3