aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/rsacomb/RDFoxAxiomConverter.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/rsacomb/RDFoxAxiomConverter.scala')
-rw-r--r--src/main/scala/rsacomb/RDFoxAxiomConverter.scala46
1 files changed, 31 insertions, 15 deletions
diff --git a/src/main/scala/rsacomb/RDFoxAxiomConverter.scala b/src/main/scala/rsacomb/RDFoxAxiomConverter.scala
index 675ca7d..0a79823 100644
--- a/src/main/scala/rsacomb/RDFoxAxiomConverter.scala
+++ b/src/main/scala/rsacomb/RDFoxAxiomConverter.scala
@@ -1,35 +1,39 @@
1package rsacomb 1package rsacomb
2 2
3import org.semanticweb.owlapi.model.{OWLAxiom, OWLSubClassOfAxiom, OWLEquivalentClassesAxiom} 3import org.semanticweb.owlapi.model.{OWLAxiom, OWLSubClassOfAxiom, OWLEquivalentClassesAxiom, OWLObjectPropertyExpression}
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}
8import tech.oxfordsemantic.jrdfox.logic.{TupleTableName}
8 9
9import scala.collection.JavaConverters._ 10import scala.collection.JavaConverters._
10 11
11import rsacomb.SkolemStrategy 12import rsacomb.SkolemStrategy
12import rsacomb.RDFoxRuleShards 13import rsacomb.RDFoxRuleShards
14import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom
15import org.semanticweb.owlapi.model.OWLObjectProperty
13 16
14object RDFoxAxiomConverter { 17object RDFoxAxiomConverter {
15 18
16 def apply(term : Term, skolem : SkolemStrategy) : RDFoxAxiomConverter = 19 def apply(
17 new RDFoxAxiomConverter(term, skolem) 20 term : Term = Variable.create("x"),
18 21 skolem : SkolemStrategy = SkolemStrategy.None,
19 def apply(term : Term) : RDFoxAxiomConverter = 22 unsafe : List[OWLObjectPropertyExpression] = List()
20 new RDFoxAxiomConverter(term, SkolemStrategy.None) 23 ) : RDFoxAxiomConverter =
24 new RDFoxAxiomConverter(term, skolem, unsafe)
21 25
22} // object RDFoxAxiomConverter 26} // object RDFoxAxiomConverter
23 27
24class RDFoxAxiomConverter(term : Term, skolem : SkolemStrategy) 28class RDFoxAxiomConverter(term : Term, skolem : SkolemStrategy, unsafe : List[OWLObjectPropertyExpression])
25 extends OWLAxiomVisitorEx[List[Rule]] 29 extends OWLAxiomVisitorEx[List[Rule]]
26{ 30{
27 31
28 override 32 override
29 def visit(axiom : OWLSubClassOfAxiom) : List[Rule] = { 33 def visit(axiom : OWLSubClassOfAxiom) : List[Rule] = {
30 // Skolemization is needed only for the head of an axiom 34 // Skolemization is needed only for the head of an axiom
31 val subVisitor = new RDFoxClassExprConverter(term,SkolemStrategy.None) 35 val subVisitor = new RDFoxClassExprConverter(term,SkolemStrategy.None, unsafe)
32 val superVisitor = new RDFoxClassExprConverter(term, skolem) 36 val superVisitor = new RDFoxClassExprConverter(term, skolem, unsafe)
33 // Each visitor returns a `RDFoxRuleShards`, a tuple (res,ext): 37 // Each visitor returns a `RDFoxRuleShards`, a tuple (res,ext):
34 // - the `res` List is a list of atoms resulting from the conversion 38 // - the `res` List is a list of atoms resulting from the conversion
35 // of the axiom. 39 // of the axiom.
@@ -46,11 +50,23 @@ class RDFoxAxiomConverter(term : Term, skolem : SkolemStrategy)
46 50
47 override 51 override
48 def visit(axiom : OWLEquivalentClassesAxiom) : List[Rule] = { 52 def visit(axiom : OWLEquivalentClassesAxiom) : List[Rule] = {
49 for { 53 for {
50 axiom1 <- axiom.asPairwiseAxioms.asScala.toList 54 axiom1 <- axiom.asPairwiseAxioms.asScala.toList
51 axiom2 <- axiom1.asOWLSubClassOfAxioms.asScala.toList 55 axiom2 <- axiom1.asOWLSubClassOfAxioms.asScala.toList
52 rule <- axiom2.accept(this) 56 rule <- axiom2.accept(this)
53 } yield rule 57 } yield rule
58 }
59
60 override
61 def visit(axiom : OWLSubObjectPropertyOfAxiom) : List[Rule] = {
62 // TODO: variables needs to be handled at visitor level. Hardcoding
63 // the name of the varibles might lead to errors for complex cases.
64 val term1 = Variable.create("y")
65 val subVisitor = new RDFoxPropertyExprConverter(term,term1,SkolemStrategy.None)
66 val superVisitor = new RDFoxPropertyExprConverter(term,term1,skolem)
67 val body: List[BodyFormula] = axiom.getSubProperty.accept(subVisitor)
68 val head: List[Atom] = axiom.getSuperProperty.accept(superVisitor)
69 List(Rule.create(head.asJava,body.asJava))
54 } 70 }
55 71
56 def doDefault(axiom : OWLAxiom) : List[Rule] = List() 72 def doDefault(axiom : OWLAxiom) : List[Rule] = List()