aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/rsacomb
diff options
context:
space:
mode:
authorFederico Igne <federico.igne@cs.ox.ac.uk>2020-08-03 09:52:53 +0100
committerFederico Igne <federico.igne@cs.ox.ac.uk>2020-08-03 09:52:53 +0100
commit88597503975804e3cb83d116f3cc9a3f12c57461 (patch)
tree9b9dd9be397718b1381736e656a89cf59c7199c5 /src/main/scala/rsacomb
parent633529ca7a911646048886b7e2e0d1d98c94fdf3 (diff)
downloadRSAComb-88597503975804e3cb83d116f3cc9a3f12c57461.tar.gz
RSAComb-88597503975804e3cb83d116f3cc9a3f12c57461.zip
Add DL renderer for input rules
Diffstat (limited to 'src/main/scala/rsacomb')
-rw-r--r--src/main/scala/rsacomb/RDFoxAxiomConverter.scala25
-rw-r--r--src/main/scala/rsacomb/RDFoxClassExprConverter.scala18
-rw-r--r--src/main/scala/rsacomb/RDFoxPropertyExprConverter.scala7
-rw-r--r--src/main/scala/rsacomb/RSAComb.scala22
4 files changed, 55 insertions, 17 deletions
diff --git a/src/main/scala/rsacomb/RDFoxAxiomConverter.scala b/src/main/scala/rsacomb/RDFoxAxiomConverter.scala
index 675ca7d..3edc908 100644
--- a/src/main/scala/rsacomb/RDFoxAxiomConverter.scala
+++ b/src/main/scala/rsacomb/RDFoxAxiomConverter.scala
@@ -4,12 +4,13 @@ import org.semanticweb.owlapi.model.{OWLAxiom, OWLSubClassOfAxiom, OWLEquivalent
4import org.semanticweb.owlapi.model.OWLAxiomVisitorEx 4import org.semanticweb.owlapi.model.OWLAxiomVisitorEx
5 5
6import tech.oxfordsemantic.jrdfox.logic.{Rule, BodyFormula} 6import tech.oxfordsemantic.jrdfox.logic.{Rule, BodyFormula}
7import tech.oxfordsemantic.jrdfox.logic.{Atom, Term, Literal} 7import tech.oxfordsemantic.jrdfox.logic.{Atom, Term, Variable, Literal}
8 8
9import scala.collection.JavaConverters._ 9import scala.collection.JavaConverters._
10 10
11import rsacomb.SkolemStrategy 11import rsacomb.SkolemStrategy
12import rsacomb.RDFoxRuleShards 12import rsacomb.RDFoxRuleShards
13import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom
13 14
14object RDFoxAxiomConverter { 15object RDFoxAxiomConverter {
15 16
@@ -46,11 +47,23 @@ class RDFoxAxiomConverter(term : Term, skolem : SkolemStrategy)
46 47
47 override 48 override
48 def visit(axiom : OWLEquivalentClassesAxiom) : List[Rule] = { 49 def visit(axiom : OWLEquivalentClassesAxiom) : List[Rule] = {
49 for { 50 for {
50 axiom1 <- axiom.asPairwiseAxioms.asScala.toList 51 axiom1 <- axiom.asPairwiseAxioms.asScala.toList
51 axiom2 <- axiom1.asOWLSubClassOfAxioms.asScala.toList 52 axiom2 <- axiom1.asOWLSubClassOfAxioms.asScala.toList
52 rule <- axiom2.accept(this) 53 rule <- axiom2.accept(this)
53 } yield rule 54 } yield rule
55 }
56
57 override
58 def visit(axiom : OWLSubObjectPropertyOfAxiom) : List[Rule] = {
59 // TODO: variables needs to be handled at visitor level. Hardcoding
60 // the name of the varibles might lead to errors for complex cases.
61 val term1 = Variable.create("y")
62 val subVisitor = new RDFoxPropertyExprConverter(term,term1,SkolemStrategy.None)
63 val superVisitor = new RDFoxPropertyExprConverter(term,term1,skolem)
64 val body: List[BodyFormula] = axiom.getSubProperty.accept(subVisitor)
65 val head: List[Atom] = axiom.getSuperProperty.accept(superVisitor)
66 List(Rule.create(head.asJava,body.asJava))
54 } 67 }
55 68
56 def doDefault(axiom : OWLAxiom) : List[Rule] = List() 69 def doDefault(axiom : OWLAxiom) : List[Rule] = List()
diff --git a/src/main/scala/rsacomb/RDFoxClassExprConverter.scala b/src/main/scala/rsacomb/RDFoxClassExprConverter.scala
index bf026c3..58bee44 100644
--- a/src/main/scala/rsacomb/RDFoxClassExprConverter.scala
+++ b/src/main/scala/rsacomb/RDFoxClassExprConverter.scala
@@ -75,15 +75,15 @@ class RDFoxClassExprConverter(term : Term, skolem : SkolemStrategy)
75 // TODO: variables needs to be handled at visitor level. Hardcoding 75 // TODO: variables needs to be handled at visitor level. Hardcoding
76 // the name of the varibles might lead to errors for complex cases. 76 // the name of the varibles might lead to errors for complex cases.
77 val y = Variable.create("y") 77 val y = Variable.create("y")
78 val (fun,term1) = skolem match { 78 val (fun,term1) = skolem match {
79 case SkolemStrategy.None => (List(),y) 79 case SkolemStrategy.None => (List(),y)
80 case SkolemStrategy.Constant(c) => (List(), Literal.create(c, Datatype.IRI_REFERENCE)) 80 case SkolemStrategy.Constant(c) => (List(), Literal.create(c, Datatype.IRI_REFERENCE))
81 case SkolemStrategy.Standard(f) => 81 case SkolemStrategy.Standard(f) =>
82 // At the time of writing the RDFox library does not have a 82 // At the time of writing the RDFox library does not have a
83 // particular class for the "SKOLEM" operator and it is instead 83 // particular class for the "SKOLEM" operator and it is instead
84 // a simple builtin function with a special name. 84 // a simple builtin function with a special name.
85 (List(BindAtom.create(BuiltinFunctionCall.create("SKOLEM",term),y)),y) 85 (List(BindAtom.create(BuiltinFunctionCall.create("SKOLEM",term),y)),y)
86 } 86 }
87 val classVisitor = new RDFoxClassExprConverter(term1,skolem) 87 val classVisitor = new RDFoxClassExprConverter(term1,skolem)
88 val classResult = expr.getFiller.accept(classVisitor) 88 val classResult = expr.getFiller.accept(classVisitor)
89 val propertyVisitor = new RDFoxPropertyExprConverter(term, term1, skolem) 89 val propertyVisitor = new RDFoxPropertyExprConverter(term, term1, skolem)
diff --git a/src/main/scala/rsacomb/RDFoxPropertyExprConverter.scala b/src/main/scala/rsacomb/RDFoxPropertyExprConverter.scala
index 8d472bf..78ac98c 100644
--- a/src/main/scala/rsacomb/RDFoxPropertyExprConverter.scala
+++ b/src/main/scala/rsacomb/RDFoxPropertyExprConverter.scala
@@ -7,6 +7,7 @@ import tech.oxfordsemantic.jrdfox.logic.{TupleTableName}
7import tech.oxfordsemantic.jrdfox.logic.{Atom, Term, Variable, Literal} 7import tech.oxfordsemantic.jrdfox.logic.{Atom, Term, Variable, Literal}
8 8
9import rsacomb.SkolemStrategy 9import rsacomb.SkolemStrategy
10import org.semanticweb.owlapi.model.OWLObjectInverseOf
10 11
11class RDFoxPropertyExprConverter(term1 : Term, term2 : Term, skolem : SkolemStrategy) 12class RDFoxPropertyExprConverter(term1 : Term, term2 : Term, skolem : SkolemStrategy)
12 extends OWLPropertyExpressionVisitorEx[List[Atom]] 13 extends OWLPropertyExpressionVisitorEx[List[Atom]]
@@ -18,6 +19,12 @@ class RDFoxPropertyExprConverter(term1 : Term, term2 : Term, skolem : SkolemStra
18 List(Atom.create(TupleTableName.create(name), term1, term2)) 19 List(Atom.create(TupleTableName.create(name), term1, term2))
19 } 20 }
20 21
22 override
23 def visit(expr : OWLObjectInverseOf) : List[Atom] = {
24 val name = expr.getInverse.getNamedProperty.getIRI.getIRIString;
25 List(Atom.create(TupleTableName.create(name ++ "_inv"), term1, term2))
26 }
27
21 def doDefault(expr : OWLPropertyExpression) : List[Atom] = List() 28 def doDefault(expr : OWLPropertyExpression) : List[Atom] = List()
22 29
23} // class RDFoxPropertyExprConverter 30} // class RDFoxPropertyExprConverter
diff --git a/src/main/scala/rsacomb/RSAComb.scala b/src/main/scala/rsacomb/RSAComb.scala
index 16d7a04..a6f237f 100644
--- a/src/main/scala/rsacomb/RSAComb.scala
+++ b/src/main/scala/rsacomb/RSAComb.scala
@@ -22,6 +22,7 @@ import tech.oxfordsemantic.jrdfox.logic.{LogicFormat}
22import scala.collection.JavaConverters._ 22import scala.collection.JavaConverters._
23 23
24import rsacomb.SkolemStrategy 24import rsacomb.SkolemStrategy
25import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer
25 26
26class RSA(ontology : OWLOntology) { 27class RSA(ontology : OWLOntology) {
27 28
@@ -52,12 +53,29 @@ object RSA {
52 * step of approximation of an Horn-ALCHOIQ to RSA 53 * step of approximation of an Horn-ALCHOIQ to RSA
53 */ 54 */
54 55
56 val renderer = new DLSyntaxObjectRenderer()
57
58 /* Print TBox axioms */
59 println("TBox/RBox:")
60 for {
61 axiom <- onto.tboxAxioms(Imports.EXCLUDED).collect(Collectors.toList()).asScala
62 } yield println(renderer.render(axiom))
63 for {
64 axiom <- onto.rboxAxioms(Imports.EXCLUDED).collect(Collectors.toList()).asScala
65 } yield println(renderer.render(axiom))
66
55 /* Ontology axiom convertion into LP rules */ 67 /* Ontology axiom convertion into LP rules */
56 for { 68 println("Logic rules:")
69 for {
57 axiom <- onto.tboxAxioms(Imports.EXCLUDED).collect(Collectors.toList()).asScala 70 axiom <- onto.tboxAxioms(Imports.EXCLUDED).collect(Collectors.toList()).asScala
58 visitor = new RDFoxAxiomConverter(Variable.create("x"), SkolemStrategy.Constant(axiom.toString)) 71 visitor = new RDFoxAxiomConverter(Variable.create("x"), SkolemStrategy.Constant(axiom.toString))
59 rule <- axiom.accept(visitor) 72 rule <- axiom.accept(visitor)
60 } yield println(rule) 73 } yield println(rule)
74 for {
75 axiom <- onto.rboxAxioms(Imports.EXCLUDED).collect(Collectors.toList()).asScala
76 visitor = new RDFoxAxiomConverter(Variable.create("x"), SkolemStrategy.Constant(axiom.toString))
77 rule <- axiom.accept(visitor)
78 } yield println(rule)
61 79
62 /* Return true for now... */ 80 /* Return true for now... */
63 true 81 true