From 50f5cd42f73b655d7d349eef70e5c269826429f9 Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Wed, 19 Aug 2020 11:33:40 +0100 Subject: Generalise prefixes --- .../scala/rsacomb/RDFoxClassExprConverter.scala | 4 +-- src/main/scala/rsacomb/RSA.scala | 19 +++++++++---- src/main/scala/rsacomb/RSAOntology.scala | 33 ++++------------------ 3 files changed, 21 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/main/scala/rsacomb/RDFoxClassExprConverter.scala b/src/main/scala/rsacomb/RDFoxClassExprConverter.scala index c1fd85a..b9d3ea2 100644 --- a/src/main/scala/rsacomb/RDFoxClassExprConverter.scala +++ b/src/main/scala/rsacomb/RDFoxClassExprConverter.scala @@ -108,8 +108,8 @@ class RDFoxClassExprConverter( if (unsafe.contains(prop)) ( List( - Atom.rdf(term, IRI.create(RSA.PredicatePE), c), - Atom.rdf(c, IRI.RDF_TYPE, IRI.create(RSA.PredicateU)) + Atom.rdf(term, RSA.internal("PE"), c), + Atom.rdf(c, IRI.RDF_TYPE, RSA.internal("U")) ), List(), c diff --git a/src/main/scala/rsacomb/RSA.scala b/src/main/scala/rsacomb/RSA.scala index 1fa0fc1..79617c7 100644 --- a/src/main/scala/rsacomb/RSA.scala +++ b/src/main/scala/rsacomb/RSA.scala @@ -2,17 +2,26 @@ package rsacomb /* Java imports */ import java.io.File +import java.util.Map +import tech.oxfordsemantic.jrdfox.Prefixes +import tech.oxfordsemantic.jrdfox.logic.IRI import org.semanticweb.owlapi.apibinding.OWLManager import org.semanticweb.owlapi.model.OWLOntology object RSA extends RSAOntology { - val PrefixBase = "http://example.com/rsa_example.owl#" - val PrefixInternal = "http://127.0.0.1/" - val PredicatePE = PrefixInternal + "PE" - val PredicateU = PrefixInternal + "U" - val PredicateE = PrefixInternal + "E" + val Prefixes = new Prefixes() + Prefixes.declarePrefix(":", "http://example.com/rsa_example.owl#") + Prefixes.declarePrefix("internal:", "http://127.0.0.1/") + 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#") + + def internal(name: String): IRI = + IRI.create( + Prefixes.getPrefixIRIsByPrefixName.get("internal:").getIRI + name + ) // TODO: move this somewhere else... maybe an OntoUtils class or something. def loadOntology(onto: File): OWLOntology = { diff --git a/src/main/scala/rsacomb/RSAOntology.scala b/src/main/scala/rsacomb/RSAOntology.scala index 681dbb0..10f2fa4 100644 --- a/src/main/scala/rsacomb/RSAOntology.scala +++ b/src/main/scala/rsacomb/RSAOntology.scala @@ -9,7 +9,6 @@ import org.semanticweb.owlapi.model.OWLObjectPropertyExpression import org.semanticweb.owlapi.model.parameters.Imports import org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory -import tech.oxfordsemantic.jrdfox.Prefixes import tech.oxfordsemantic.jrdfox.logic.Variable import tech.oxfordsemantic.jrdfox.client.UpdateType import tech.oxfordsemantic.jrdfox.logic.{Rule, Atom, Variable, IRI} @@ -74,38 +73,16 @@ trait RSAOntology { println("\nDatalog roles:") datalog.foreach(println) - // TODO: Define Prefixes in RSA object - val prefixes = new Prefixes() - prefixes.declarePrefix(":", RSA.PrefixBase) - prefixes.declarePrefix("internal:", RSA.PrefixInternal) - 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#") - // Open connection with RDFox val (server, data) = RDFoxUtil.openConnection("RSACheck") // Add Data (hardcoded for now) - data.importData(UpdateType.ADDITION, prefixes, ":a a :A .") - - /* Add rules - * - * NOTE: - * - using the `addRules(...)` method in `DataStoreConnection` is not working as expected, complaining - * about missing TupleTable entries; - * - weirdly enough, the same error is returned when trying to pass the rules to the `importData` method, - * simply turning them into strings. It seems like the `toString` implementation of `Rule` uses parenthesis - * for predicate arguments (e.g., `(?X,?Y)`) while the specification for the proprietary RDFox - * syntax uses squared brackets (e.g., `[?X,?Y]`). - */ + data.importData(UpdateType.ADDITION, RSA.Prefixes, ":a a :A .") /* Add built-in rules */ data.importData( UpdateType.ADDITION, - prefixes, + RSA.Prefixes, "[?X,?Y] :- [?X,?Y], [?X], [?Y] ." ) @@ -117,17 +94,17 @@ trait RSAOntology { println("\nQueries:") RDFoxUtil.query( data, - prefixes, + RSA.Prefixes, "SELECT ?X ?Y WHERE { ?X internal:PE ?Y }" ) RDFoxUtil.query( data, - prefixes, + RSA.Prefixes, "SELECT ?X ?Y WHERE { ?X internal:E ?Y }" ) RDFoxUtil.query( data, - prefixes, + RSA.Prefixes, "SELECT ?X WHERE { ?X rdf:type owl:Thing }" ) -- cgit v1.2.3