diff options
| author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-08-16 16:27:41 +0100 |
|---|---|---|
| committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-08-16 16:27:41 +0100 |
| commit | 99b932a358e0fcf5b463c3a98fb12fdfa393152c (patch) | |
| tree | 9a78d5363937a2707cf516f37f48d2d0c65db5ae /src/main/scala | |
| parent | 6fc6fc2bde597c79e66c3dbf8e3a1f94526ea672 (diff) | |
| download | RSAComb-99b932a358e0fcf5b463c3a98fb12fdfa393152c.tar.gz RSAComb-99b932a358e0fcf5b463c3a98fb12fdfa393152c.zip | |
Include built-in rules in RSA check
Diffstat (limited to 'src/main/scala')
| -rw-r--r-- | src/main/scala/rsacomb/RDFox.scala | 24 | ||||
| -rw-r--r-- | src/main/scala/rsacomb/RDFoxClassExprConverter.scala | 165 | ||||
| -rw-r--r-- | src/main/scala/rsacomb/RDFoxUtil.scala | 42 | ||||
| -rw-r--r-- | src/main/scala/rsacomb/RSAOntology.scala | 95 |
4 files changed, 214 insertions, 112 deletions
diff --git a/src/main/scala/rsacomb/RDFox.scala b/src/main/scala/rsacomb/RDFox.scala deleted file mode 100644 index a263091..0000000 --- a/src/main/scala/rsacomb/RDFox.scala +++ /dev/null | |||
| @@ -1,24 +0,0 @@ | |||
| 1 | package rsacomb | ||
| 2 | |||
| 3 | /* Java imports */ | ||
| 4 | import java.util.HashMap | ||
| 5 | import tech.oxfordsemantic.jrdfox.client.{ConnectionFactory,ServerConnection,DataStoreConnection} | ||
| 6 | |||
| 7 | object RDFox { | ||
| 8 | |||
| 9 | def openConnection(dataStore: String): (ServerConnection,DataStoreConnection) = { | ||
| 10 | val serverUrl = "rdfox:local" | ||
| 11 | val role = "" | ||
| 12 | val password = "" | ||
| 13 | val server = ConnectionFactory.newServerConnection(serverUrl, role, password) | ||
| 14 | server.createDataStore(dataStore,"seq",new HashMap()) | ||
| 15 | val data = server.newDataStoreConnection(dataStore) | ||
| 16 | (server,data) | ||
| 17 | } | ||
| 18 | |||
| 19 | def closeConnection(server: ServerConnection, data: DataStoreConnection): Unit = { | ||
| 20 | server.close(); | ||
| 21 | data.close(); | ||
| 22 | } | ||
| 23 | |||
| 24 | } // object RDFox \ No newline at end of file | ||
diff --git a/src/main/scala/rsacomb/RDFoxClassExprConverter.scala b/src/main/scala/rsacomb/RDFoxClassExprConverter.scala index 227c25b..9116be0 100644 --- a/src/main/scala/rsacomb/RDFoxClassExprConverter.scala +++ b/src/main/scala/rsacomb/RDFoxClassExprConverter.scala | |||
| @@ -1,12 +1,29 @@ | |||
| 1 | package rsacomb | 1 | package rsacomb |
| 2 | 2 | ||
| 3 | import scala.collection.JavaConverters._ | 3 | import scala.collection.JavaConverters._ |
| 4 | import java.util.stream.{Stream,Collectors} | 4 | import java.util.stream.{Stream, Collectors} |
| 5 | 5 | ||
| 6 | import org.semanticweb.owlapi.model.{OWLClassExpression, OWLClass, OWLObjectSomeValuesFrom, OWLObjectIntersectionOf, OWLObjectOneOf, OWLObjectMaxCardinality} | 6 | import org.semanticweb.owlapi.model.{ |
| 7 | OWLClassExpression, | ||
| 8 | OWLClass, | ||
| 9 | OWLObjectSomeValuesFrom, | ||
| 10 | OWLObjectIntersectionOf, | ||
| 11 | OWLObjectOneOf, | ||
| 12 | OWLObjectMaxCardinality | ||
| 13 | } | ||
| 7 | import org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx | 14 | import org.semanticweb.owlapi.model.OWLClassExpressionVisitorEx |
| 8 | import tech.oxfordsemantic.jrdfox.logic.{BindAtom, BuiltinFunctionCall, TupleTableName} | 15 | import tech.oxfordsemantic.jrdfox.logic.{ |
| 9 | import tech.oxfordsemantic.jrdfox.logic.{Atom, Term, Variable, Literal, Datatype} | 16 | BindAtom, |
| 17 | BuiltinFunctionCall, | ||
| 18 | TupleTableName | ||
| 19 | } | ||
| 20 | import tech.oxfordsemantic.jrdfox.logic.{ | ||
| 21 | Atom, | ||
| 22 | Term, | ||
| 23 | Variable, | ||
| 24 | Literal, | ||
| 25 | Datatype | ||
| 26 | } | ||
| 10 | 27 | ||
| 11 | import rsacomb.SkolemStrategy | 28 | import rsacomb.SkolemStrategy |
| 12 | import rsacomb.RDFoxRuleShards | 29 | import rsacomb.RDFoxRuleShards |
| @@ -16,87 +33,100 @@ import org.semanticweb.owlapi.model.OWLObjectProperty | |||
| 16 | object RDFoxClassExprConverter { | 33 | object RDFoxClassExprConverter { |
| 17 | 34 | ||
| 18 | def apply( | 35 | def apply( |
| 19 | term : Term = Variable.create("x"), | 36 | term: Term = Variable.create("x"), |
| 20 | skolem : SkolemStrategy = SkolemStrategy.None, | 37 | skolem: SkolemStrategy = SkolemStrategy.None, |
| 21 | unsafe : List[OWLObjectPropertyExpression] = List() | 38 | unsafe: List[OWLObjectPropertyExpression] = List() |
| 22 | ) : RDFoxClassExprConverter = | 39 | ): RDFoxClassExprConverter = |
| 23 | new RDFoxClassExprConverter(term, skolem, unsafe) | 40 | new RDFoxClassExprConverter(term, skolem, unsafe) |
| 24 | 41 | ||
| 25 | def merge(rules : List[RDFoxRuleShards]) : RDFoxRuleShards = { | 42 | def merge(rules: List[RDFoxRuleShards]): RDFoxRuleShards = { |
| 26 | rules.foldLeft(RDFoxRuleShards(List(),List())) { | 43 | rules.foldLeft(RDFoxRuleShards(List(), List())) { (r1, r2) => |
| 27 | (r1,r2) => | 44 | RDFoxRuleShards( |
| 28 | RDFoxRuleShards( | 45 | r1.res ++ r2.res, |
| 29 | r1.res ++ r2.res, | 46 | r1.ext ++ r2.ext |
| 30 | r1.ext ++ r2.ext | 47 | ) |
| 31 | ) | ||
| 32 | } | 48 | } |
| 33 | } | 49 | } |
| 34 | 50 | ||
| 35 | } // object RDFoxClassExprConverter | 51 | } // object RDFoxClassExprConverter |
| 36 | 52 | ||
| 37 | class RDFoxClassExprConverter(term : Term, skolem : SkolemStrategy, unsafe : List[OWLObjectPropertyExpression]) | 53 | class RDFoxClassExprConverter( |
| 38 | extends OWLClassExpressionVisitorEx[RDFoxRuleShards] | 54 | term: Term, |
| 39 | { | 55 | skolem: SkolemStrategy, |
| 56 | unsafe: List[OWLObjectPropertyExpression] | ||
| 57 | ) extends OWLClassExpressionVisitorEx[RDFoxRuleShards] { | ||
| 40 | 58 | ||
| 41 | // OWLClass | 59 | // OWLClass |
| 42 | override | 60 | override def visit(expr: OWLClass): RDFoxRuleShards = { |
| 43 | def visit(expr : OWLClass) : RDFoxRuleShards = { | ||
| 44 | val name = expr.getIRI.getIRIString | 61 | val name = expr.getIRI.getIRIString |
| 45 | val atom = List(Atom.create(TupleTableName.create(name), term)) | 62 | val atom = List(Atom.create(TupleTableName.create(name), term)) |
| 46 | RDFoxRuleShards(atom,List()) | 63 | RDFoxRuleShards(atom, List()) |
| 47 | } | 64 | } |
| 48 | 65 | ||
| 49 | // OWLObjectIntersectionOf | 66 | // OWLObjectIntersectionOf |
| 50 | override | 67 | override def visit(expr: OWLObjectIntersectionOf): RDFoxRuleShards = { |
| 51 | def visit(expr : OWLObjectIntersectionOf) : RDFoxRuleShards = { | ||
| 52 | val visitor = new RDFoxClassExprConverter(term, skolem, unsafe) | 68 | val visitor = new RDFoxClassExprConverter(term, skolem, unsafe) |
| 53 | // TODO: maybe using `flatMap` instead of `merge` + `map` works as well | 69 | // TODO: maybe using `flatMap` instead of `merge` + `map` works as well |
| 54 | RDFoxClassExprConverter.merge ( | 70 | RDFoxClassExprConverter.merge( |
| 55 | expr.asConjunctSet.asScala.toList | 71 | expr.asConjunctSet.asScala.toList |
| 56 | .map((e : OWLClassExpression) => e.accept(visitor)) | 72 | .map((e: OWLClassExpression) => e.accept(visitor)) |
| 57 | ) | 73 | ) |
| 58 | } | 74 | } |
| 59 | 75 | ||
| 60 | // OWLObjectOneOf | 76 | // OWLObjectOneOf |
| 61 | override | 77 | override def visit(expr: OWLObjectOneOf): RDFoxRuleShards = { |
| 62 | def visit(expr : OWLObjectOneOf) : RDFoxRuleShards = { | 78 | val visitor = RDFoxClassExprConverter(term, skolem) |
| 63 | val visitor = RDFoxClassExprConverter(term,skolem) | ||
| 64 | // TODO: review nominal handling. Here we are taking "just" one | 79 | // TODO: review nominal handling. Here we are taking "just" one |
| 65 | val ind = expr.individuals.collect(Collectors.toList()).asScala | 80 | val ind = expr.individuals |
| 66 | .filter(_.isOWLNamedIndividual) | 81 | .collect(Collectors.toList()) |
| 67 | .head // restricts to proper "nominals" | 82 | .asScala |
| 68 | .asOWLNamedIndividual.getIRI.getIRIString | 83 | .filter(_.isOWLNamedIndividual) |
| 69 | val atom = List(Atom.create( | 84 | .head // restricts to proper "nominals" |
| 70 | TupleTableName.create("owl:sameAs"), term, Literal.create(ind, Datatype.IRI_REFERENCE) | 85 | .asOWLNamedIndividual |
| 71 | )) | 86 | .getIRI |
| 72 | RDFoxRuleShards(atom,List()) | 87 | .getIRIString |
| 88 | val atom = List( | ||
| 89 | Atom.sameAs(term, Literal.create(ind, Datatype.IRI_REFERENCE)) | ||
| 90 | ) | ||
| 91 | RDFoxRuleShards(atom, List()) | ||
| 73 | } | 92 | } |
| 74 | 93 | ||
| 75 | // OWLObjectSomeValuesFrom | 94 | // OWLObjectSomeValuesFrom |
| 76 | override | 95 | override def visit(expr: OWLObjectSomeValuesFrom): RDFoxRuleShards = { |
| 77 | def visit(expr : OWLObjectSomeValuesFrom) : RDFoxRuleShards = { | ||
| 78 | // TODO: variables needs to be handled at visitor level. Hardcoding | 96 | // TODO: variables needs to be handled at visitor level. Hardcoding |
| 79 | // the name of the varibles might lead to errors for complex cases. | 97 | // the name of the varibles might lead to errors for complex cases. |
| 80 | val y = Variable.create("y") | 98 | val y = Variable.create("y") |
| 81 | val prop = expr.getProperty() | 99 | val prop = expr.getProperty() |
| 82 | // Computes the result of rule skolemization. Depending on the used | 100 | // Computes the result of rule skolemization. Depending on the used |
| 83 | // technique it might involve the introduction of additional atoms, | 101 | // technique it might involve the introduction of additional atoms, |
| 84 | // and/or fresh constants and variables. | 102 | // and/or fresh constants and variables. |
| 85 | val (head, body, term1) = skolem match { | 103 | val (head, body, term1) = skolem match { |
| 86 | case SkolemStrategy.None => (List(), List(), y) | 104 | case SkolemStrategy.None => (List(), List(), y) |
| 87 | case SkolemStrategy.Constant(c) => (List(), List(), Literal.create(c, Datatype.IRI_REFERENCE)) | 105 | case SkolemStrategy.Constant(c) => |
| 88 | case SkolemStrategy.ConstantRSA(c) => { | 106 | (List(), List(), Literal.create(c, Datatype.IRI_REFERENCE)) |
| 89 | val lit = Literal.create(c, Datatype.IRI_REFERENCE) | 107 | case SkolemStrategy.ConstantRSA(c) => { |
| 90 | if (unsafe.contains(prop)) | 108 | val lit = Literal.create(c, Datatype.IRI_REFERENCE) |
| 91 | (List(Atom.create(TupleTableName.create("internal:PE"),term,lit), Atom.create(TupleTableName.create("internal:U"),lit)), List(), lit) | 109 | if (unsafe.contains(prop)) |
| 92 | else | 110 | ( |
| 93 | (List(), List(), lit) | 111 | List( |
| 94 | } | 112 | Atom.create(TupleTableName.create("internal:PE"), term, lit), |
| 95 | case SkolemStrategy.Standard(f) => | 113 | Atom.create(TupleTableName.create("internal:U"), lit) |
| 96 | // At the time of writing the RDFox library does not have a | 114 | ), |
| 97 | // particular class for the "SKOLEM" operator and it is instead | 115 | List(), |
| 98 | // a simple builtin function with a "special" name. | 116 | lit |
| 99 | (List(),List(BindAtom.create(BuiltinFunctionCall.create("SKOLEM",term),y)),y) | 117 | ) |
| 118 | else | ||
| 119 | (List(), List(), lit) | ||
| 120 | } | ||
| 121 | case SkolemStrategy.Standard(f) => | ||
| 122 | // At the time of writing the RDFox library does not have a | ||
| 123 | // particular class for the "SKOLEM" operator and it is instead | ||
| 124 | // a simple builtin function with a "special" name. | ||
| 125 | ( | ||
| 126 | List(), | ||
| 127 | List(BindAtom.create(BuiltinFunctionCall.create("SKOLEM", term), y)), | ||
| 128 | y | ||
| 129 | ) | ||
| 100 | } | 130 | } |
| 101 | val classVisitor = new RDFoxClassExprConverter(term1, skolem, unsafe) | 131 | val classVisitor = new RDFoxClassExprConverter(term1, skolem, unsafe) |
| 102 | val classResult = expr.getFiller.accept(classVisitor) | 132 | val classResult = expr.getFiller.accept(classVisitor) |
| @@ -109,25 +139,26 @@ class RDFoxClassExprConverter(term : Term, skolem : SkolemStrategy, unsafe : Lis | |||
| 109 | } | 139 | } |
| 110 | 140 | ||
| 111 | // OWLObjectMaxCardinality | 141 | // OWLObjectMaxCardinality |
| 112 | override | 142 | override def visit(expr: OWLObjectMaxCardinality): RDFoxRuleShards = { |
| 113 | def visit(expr : OWLObjectMaxCardinality) : RDFoxRuleShards = { | ||
| 114 | // TODO: again, no hardcoded variables | 143 | // TODO: again, no hardcoded variables |
| 115 | val vars = List(Variable.create("y"),Variable.create("z")) | 144 | val vars = List(Variable.create("y"), Variable.create("z")) |
| 116 | val classResult = RDFoxClassExprConverter.merge( | 145 | val classResult = RDFoxClassExprConverter.merge( |
| 117 | vars.map(new RDFoxClassExprConverter(_,skolem, unsafe)) | 146 | vars |
| 118 | .map(expr.getFiller.accept(_)) | 147 | .map(new RDFoxClassExprConverter(_, skolem, unsafe)) |
| 148 | .map(expr.getFiller.accept(_)) | ||
| 119 | ) | 149 | ) |
| 120 | val propertyResult = | 150 | val propertyResult = |
| 121 | vars.map(new RDFoxPropertyExprConverter(term,_,skolem)) | 151 | vars |
| 122 | .map(expr.getProperty.accept(_)) | 152 | .map(new RDFoxPropertyExprConverter(term, _, skolem)) |
| 123 | .flatten | 153 | .map(expr.getProperty.accept(_)) |
| 154 | .flatten | ||
| 124 | RDFoxRuleShards( | 155 | RDFoxRuleShards( |
| 125 | List(Atom.create(TupleTableName.create("owl:sameAs"),vars(0),vars(1))), | 156 | List(Atom.create(TupleTableName.create("owl:sameAs"), vars(0), vars(1))), |
| 126 | classResult.res ++ propertyResult | 157 | classResult.res ++ propertyResult |
| 127 | ) | 158 | ) |
| 128 | } | 159 | } |
| 129 | 160 | ||
| 130 | def doDefault(expr : OWLClassExpression) : RDFoxRuleShards = | 161 | def doDefault(expr: OWLClassExpression): RDFoxRuleShards = |
| 131 | RDFoxRuleShards(List(),List()) | 162 | RDFoxRuleShards(List(), List()) |
| 132 | 163 | ||
| 133 | } // class RDFoxClassExprConverter | 164 | } // class RDFoxClassExprConverter |
diff --git a/src/main/scala/rsacomb/RDFoxUtil.scala b/src/main/scala/rsacomb/RDFoxUtil.scala new file mode 100644 index 0000000..96710c4 --- /dev/null +++ b/src/main/scala/rsacomb/RDFoxUtil.scala | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | package rsacomb | ||
| 2 | |||
| 3 | /* Java imports */ | ||
| 4 | import java.util.HashMap | ||
| 5 | import tech.oxfordsemantic.jrdfox.client.{ | ||
| 6 | ConnectionFactory, | ||
| 7 | ServerConnection, | ||
| 8 | DataStoreConnection | ||
| 9 | } | ||
| 10 | |||
| 11 | object RDFoxUtil { | ||
| 12 | |||
| 13 | def openConnection( | ||
| 14 | dataStore: String | ||
| 15 | ): (ServerConnection, DataStoreConnection) = { | ||
| 16 | /* Create local server connection | ||
| 17 | */ | ||
| 18 | val serverUrl = "rdfox:local" | ||
| 19 | val role = "" | ||
| 20 | val password = "" | ||
| 21 | val server = | ||
| 22 | ConnectionFactory.newServerConnection(serverUrl, role, password) | ||
| 23 | |||
| 24 | /* Create datastore connection | ||
| 25 | */ | ||
| 26 | val parameters = new HashMap[String, String]() | ||
| 27 | //parameters.put("equality", "noUNA") | ||
| 28 | server.createDataStore(dataStore, "seq", parameters) | ||
| 29 | val data = server.newDataStoreConnection(dataStore) | ||
| 30 | |||
| 31 | (server, data) | ||
| 32 | } | ||
| 33 | |||
| 34 | def closeConnection( | ||
| 35 | server: ServerConnection, | ||
| 36 | data: DataStoreConnection | ||
| 37 | ): Unit = { | ||
| 38 | server.close(); | ||
| 39 | data.close(); | ||
| 40 | } | ||
| 41 | |||
| 42 | } // object RDFox | ||
diff --git a/src/main/scala/rsacomb/RSAOntology.scala b/src/main/scala/rsacomb/RSAOntology.scala index 3b08e61..06752ef 100644 --- a/src/main/scala/rsacomb/RSAOntology.scala +++ b/src/main/scala/rsacomb/RSAOntology.scala | |||
| @@ -2,7 +2,7 @@ package rsacomb | |||
| 2 | 2 | ||
| 3 | /* Java imports */ | 3 | /* Java imports */ |
| 4 | import java.util.HashMap | 4 | import java.util.HashMap |
| 5 | import java.util.stream.{Collectors,Stream} | 5 | import java.util.stream.{Collectors, Stream} |
| 6 | 6 | ||
| 7 | import org.semanticweb.owlapi.model.OWLOntology | 7 | import org.semanticweb.owlapi.model.OWLOntology |
| 8 | import org.semanticweb.owlapi.model.OWLObjectPropertyExpression | 8 | import org.semanticweb.owlapi.model.OWLObjectPropertyExpression |
| @@ -13,7 +13,6 @@ import tech.oxfordsemantic.jrdfox.Prefixes | |||
| 13 | import tech.oxfordsemantic.jrdfox.logic.Variable | 13 | import tech.oxfordsemantic.jrdfox.logic.Variable |
| 14 | import tech.oxfordsemantic.jrdfox.client.UpdateType | 14 | import tech.oxfordsemantic.jrdfox.client.UpdateType |
| 15 | 15 | ||
| 16 | |||
| 17 | /* Scala imports */ | 16 | /* Scala imports */ |
| 18 | import scala.collection.JavaConverters._ | 17 | import scala.collection.JavaConverters._ |
| 19 | 18 | ||
| @@ -42,9 +41,14 @@ trait RSAOntology { | |||
| 42 | * step of approximation of an Horn-ALCHOIQ to RSA | 41 | * step of approximation of an Horn-ALCHOIQ to RSA |
| 43 | */ | 42 | */ |
| 44 | 43 | ||
| 45 | val tbox = | 44 | val tbox = |
| 46 | Stream.concat(ontology.tboxAxioms(Imports.INCLUDED), ontology.rboxAxioms(Imports.INCLUDED)) | 45 | Stream |
| 47 | .collect(Collectors.toList()).asScala | 46 | .concat( |
| 47 | ontology.tboxAxioms(Imports.INCLUDED), | ||
| 48 | ontology.rboxAxioms(Imports.INCLUDED) | ||
| 49 | ) | ||
| 50 | .collect(Collectors.toList()) | ||
| 51 | .asScala | ||
| 48 | val unsafe = ontology.getUnsafeRoles | 52 | val unsafe = ontology.getUnsafeRoles |
| 49 | 53 | ||
| 50 | /* DEBUG: print rules in DL syntax */ | 54 | /* DEBUG: print rules in DL syntax */ |
| @@ -55,18 +59,29 @@ trait RSAOntology { | |||
| 55 | /* Ontology convertion into LP rules */ | 59 | /* Ontology convertion into LP rules */ |
| 56 | val datalog = for { | 60 | val datalog = for { |
| 57 | axiom <- tbox | 61 | axiom <- tbox |
| 58 | visitor = new RDFoxAxiomConverter(Variable.create("x"), SkolemStrategy.ConstantRSA(axiom.toString), unsafe) | 62 | visitor = new RDFoxAxiomConverter( |
| 59 | rule <- axiom.accept(visitor) | 63 | Variable.create("x"), |
| 64 | SkolemStrategy.ConstantRSA(axiom.toString), | ||
| 65 | unsafe | ||
| 66 | ) | ||
| 67 | rule <- axiom.accept(visitor) | ||
| 60 | } yield rule | 68 | } yield rule |
| 61 | 69 | ||
| 62 | val prefixes = new Prefixes() | 70 | val prefixes = new Prefixes() |
| 63 | prefixes.declarePrefix(":", "http://example.com/rsa_example.owl#") | 71 | prefixes.declarePrefix(":", "http://example.com/rsa_example.owl#") |
| 72 | prefixes.declarePrefix( | ||
| 73 | "rdf:", | ||
| 74 | "http://www.w3.org/1999/02/22-rdf-syntax-ns#" | ||
| 75 | ) | ||
| 76 | prefixes.declarePrefix("rdfs:", "http://www.w3.org/2000/01/rdf-schema#") | ||
| 77 | prefixes.declarePrefix("owl:", "http://www.w3.org/2002/07/owl#") | ||
| 64 | 78 | ||
| 65 | // Open connection with RDFox | 79 | // Open connection with RDFox |
| 66 | val (server,data) = RDFox.openConnection("RSACheck") | 80 | val (server, data) = RDFoxUtil.openConnection("RSACheck") |
| 67 | // Add Data (hardcoded for now) | 81 | // Add Data (hardcoded for now) |
| 68 | data.importData(UpdateType.ADDITION, prefixes,":a a :A .") | 82 | data.importData(UpdateType.ADDITION, prefixes, ":a a :A .") |
| 69 | /* Add Datalog rules | 83 | |
| 84 | /* Add rules | ||
| 70 | * | 85 | * |
| 71 | * NOTE: | 86 | * NOTE: |
| 72 | * - using the `addRules(...)` method in `DataStoreConnection` is not working as expected, complaining | 87 | * - using the `addRules(...)` method in `DataStoreConnection` is not working as expected, complaining |
| @@ -76,18 +91,45 @@ trait RSAOntology { | |||
| 76 | * for predicate arguments (e.g., `<predicate>(?X,?Y)`) while the specification for the proprietary RDFox | 91 | * for predicate arguments (e.g., `<predicate>(?X,?Y)`) while the specification for the proprietary RDFox |
| 77 | * syntax uses squared brackets (e.g., `<preditate>[?X,?Y]`). | 92 | * syntax uses squared brackets (e.g., `<preditate>[?X,?Y]`). |
| 78 | */ | 93 | */ |
| 94 | |||
| 95 | /* Add built-in rules | ||
| 96 | */ | ||
| 97 | data.importData( | ||
| 98 | UpdateType.ADDITION, | ||
| 99 | prefixes, | ||
| 100 | "<internal:E>[?X,?Y] :- <internal:PE>[?X,?Y], <internal:U>[?X], <internal:U>[?Y] ." | ||
| 101 | ) | ||
| 102 | |||
| 103 | /* Add ontology rules | ||
| 104 | */ | ||
| 79 | data.importData( | 105 | data.importData( |
| 80 | UpdateType.ADDITION, | 106 | UpdateType.ADDITION, |
| 81 | prefixes, | 107 | prefixes, |
| 82 | datalog.foldLeft("")((str,rule) => str ++ "\n" ++ rule.toString().replace("(", "[").replace(")","]")) | 108 | datalog.foldLeft("")((str, rule) => |
| 109 | str ++ "\n" ++ rule.toString().replace("(", "[").replace(")", "]") | ||
| 110 | ) | ||
| 83 | ) | 111 | ) |
| 84 | 112 | ||
| 85 | // Retrieve all instances of PE | 113 | // Retrieve all instances of PE |
| 86 | println("\nQuery results:") | 114 | println("\nQuery results:") |
| 87 | data.evaluateQuery(prefixes,"SELECT ?X ?Y WHERE { ?X <internal:PE> ?Y }", new HashMap[String,String](), System.out, "text/csv"); | 115 | data.evaluateQuery( |
| 116 | prefixes, | ||
| 117 | "SELECT ?X ?Y WHERE { ?X <internal:PE> ?Y }", | ||
| 118 | new HashMap[String, String](), | ||
| 119 | System.out, | ||
| 120 | "text/csv" | ||
| 121 | ); | ||
| 122 | |||
| 123 | data.evaluateQuery( | ||
| 124 | prefixes, | ||
| 125 | "SELECT ?X ?Y WHERE { ?X <internal:E> ?Y }", | ||
| 126 | new HashMap[String, String](), | ||
| 127 | System.out, | ||
| 128 | "text/csv" | ||
| 129 | ); | ||
| 88 | 130 | ||
| 89 | // Close connection to RDFox | 131 | // Close connection to RDFox |
| 90 | RDFox.closeConnection(server,data) | 132 | RDFoxUtil.closeConnection(server, data) |
| 91 | 133 | ||
| 92 | /* DEBUG */ | 134 | /* DEBUG */ |
| 93 | true | 135 | true |
| @@ -98,13 +140,16 @@ trait RSAOntology { | |||
| 98 | val factory = new StructuralReasonerFactory() | 140 | val factory = new StructuralReasonerFactory() |
| 99 | val reasoner = factory.createReasoner(ontology) | 141 | val reasoner = factory.createReasoner(ontology) |
| 100 | 142 | ||
| 101 | val tbox = ontology.tboxAxioms(Imports.INCLUDED).collect(Collectors.toSet()).asScala | 143 | val tbox = ontology |
| 144 | .tboxAxioms(Imports.INCLUDED) | ||
| 145 | .collect(Collectors.toSet()) | ||
| 146 | .asScala | ||
| 102 | 147 | ||
| 103 | /* DEBUG: print rules in DL syntax */ | 148 | /* DEBUG: print rules in DL syntax */ |
| 104 | //val renderer = new DLSyntaxObjectRenderer() | 149 | //val renderer = new DLSyntaxObjectRenderer() |
| 105 | 150 | ||
| 106 | /* Checking for (1) unsafety condition: | 151 | /* Checking for (1) unsafety condition: |
| 107 | * | 152 | * |
| 108 | * For all roles r1 appearing in an axiom of type T5, r1 is unsafe | 153 | * For all roles r1 appearing in an axiom of type T5, r1 is unsafe |
| 109 | * if there exists a role r2 (different from top) appearing in an axiom | 154 | * if there exists a role r2 (different from top) appearing in an axiom |
| 110 | * of type T3 and r1 is a subproperty of the inverse of r2. | 155 | * of type T3 and r1 is a subproperty of the inverse of r2. |
| @@ -113,11 +158,15 @@ trait RSAOntology { | |||
| 113 | axiom <- tbox | 158 | axiom <- tbox |
| 114 | if axiom.isT5 | 159 | if axiom.isT5 |
| 115 | role1 <- axiom.objectPropertyExpressionsInSignature | 160 | role1 <- axiom.objectPropertyExpressionsInSignature |
| 116 | roleSuper = role1 +: reasoner.superObjectProperties(role1).collect(Collectors.toList()).asScala | 161 | roleSuper = |
| 162 | role1 +: reasoner | ||
| 163 | .superObjectProperties(role1) | ||
| 164 | .collect(Collectors.toList()) | ||
| 165 | .asScala | ||
| 117 | roleSuperInv = roleSuper.map(_.getInverseProperty) | 166 | roleSuperInv = roleSuper.map(_.getInverseProperty) |
| 118 | axiom <- tbox | 167 | axiom <- tbox |
| 119 | if axiom.isT3 && !axiom.isT3top | 168 | if axiom.isT3 && !axiom.isT3top |
| 120 | role2 <- axiom.objectPropertyExpressionsInSignature | 169 | role2 <- axiom.objectPropertyExpressionsInSignature |
| 121 | if roleSuperInv.contains(role2) | 170 | if roleSuperInv.contains(role2) |
| 122 | } yield role1 | 171 | } yield role1 |
| 123 | 172 | ||
| @@ -126,17 +175,21 @@ trait RSAOntology { | |||
| 126 | * For all roles p1 appearing in an axiom of type T5, p1 is unsafe if | 175 | * For all roles p1 appearing in an axiom of type T5, p1 is unsafe if |
| 127 | * there exists a role p2 appearing in an axiom of type T4 and p1 is a | 176 | * there exists a role p2 appearing in an axiom of type T4 and p1 is a |
| 128 | * subproperty of either p2 or the inverse of p2. | 177 | * subproperty of either p2 or the inverse of p2. |
| 129 | * | 178 | * |
| 130 | */ | 179 | */ |
| 131 | val unsafe2 = for { | 180 | val unsafe2 = for { |
| 132 | axiom <- tbox | 181 | axiom <- tbox |
| 133 | if axiom.isT5 | 182 | if axiom.isT5 |
| 134 | role1 <- axiom.objectPropertyExpressionsInSignature | 183 | role1 <- axiom.objectPropertyExpressionsInSignature |
| 135 | roleSuper = role1 +: reasoner.superObjectProperties(role1).collect(Collectors.toList()).asScala | 184 | roleSuper = |
| 185 | role1 +: reasoner | ||
| 186 | .superObjectProperties(role1) | ||
| 187 | .collect(Collectors.toList()) | ||
| 188 | .asScala | ||
| 136 | roleSuperInv = roleSuper.map(_.getInverseProperty) | 189 | roleSuperInv = roleSuper.map(_.getInverseProperty) |
| 137 | axiom <- tbox | 190 | axiom <- tbox |
| 138 | if axiom.isT4 | 191 | if axiom.isT4 |
| 139 | role2 <- axiom.objectPropertyExpressionsInSignature | 192 | role2 <- axiom.objectPropertyExpressionsInSignature |
| 140 | if roleSuper.contains(role2) || roleSuperInv.contains(role2) | 193 | if roleSuper.contains(role2) || roleSuperInv.contains(role2) |
| 141 | } yield role1 | 194 | } yield role1 |
| 142 | 195 | ||
| @@ -149,4 +202,4 @@ trait RSAOntology { | |||
| 149 | 202 | ||
| 150 | } // implicit class RSAOntology | 203 | } // implicit class RSAOntology |
| 151 | 204 | ||
| 152 | } // trait RSAOntology \ No newline at end of file | 205 | } // trait RSAOntology |
