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.scala106
1 files changed, 0 insertions, 106 deletions
diff --git a/src/main/scala/rsacomb/RDFoxAxiomConverter.scala b/src/main/scala/rsacomb/RDFoxAxiomConverter.scala
deleted file mode 100644
index 9b78e8e..0000000
--- a/src/main/scala/rsacomb/RDFoxAxiomConverter.scala
+++ /dev/null
@@ -1,106 +0,0 @@
1package rsacomb
2
3import org.semanticweb.owlapi.model.{
4 OWLAxiom,
5 OWLSubClassOfAxiom,
6 OWLEquivalentClassesAxiom,
7 OWLObjectPropertyExpression
8}
9import org.semanticweb.owlapi.model.OWLAxiomVisitorEx
10
11import tech.oxfordsemantic.jrdfox.logic.datalog.{
12 Rule,
13 BodyFormula,
14 TupleTableAtom,
15 TupleTableName
16}
17import tech.oxfordsemantic.jrdfox.logic.expression.{
18 Term,
19 IRI,
20 Variable,
21 Literal
22}
23
24import scala.collection.JavaConverters._
25
26import rsacomb.SkolemStrategy
27import rsacomb.RDFoxRuleShards
28import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom
29import org.semanticweb.owlapi.model.OWLObjectProperty
30import org.semanticweb.owlapi.model.OWLClassAssertionAxiom
31
32import suffix.{RSASuffix, Empty}
33
34object RDFoxAxiomConverter {
35
36 def apply(
37 term: Term,
38 unsafe: List[OWLObjectPropertyExpression],
39 skolem: SkolemStrategy = SkolemStrategy.None,
40 suffix: RSASuffix = Empty
41 ): RDFoxAxiomConverter =
42 new RDFoxAxiomConverter(term, unsafe, skolem, suffix)
43
44} // object RDFoxAxiomConverter
45
46class RDFoxAxiomConverter(
47 term: Term,
48 unsafe: List[OWLObjectPropertyExpression],
49 skolem: SkolemStrategy,
50 suffix: RSASuffix
51) extends OWLAxiomVisitorEx[List[Rule]] {
52
53 override def visit(axiom: OWLSubClassOfAxiom): List[Rule] = {
54 // Skolemization is needed only for the head of an axiom
55 val subVisitor =
56 new RDFoxClassExprConverter(term, unsafe, SkolemStrategy.None, suffix)
57 val superVisitor = new RDFoxClassExprConverter(term, unsafe, skolem, suffix)
58 // Each visitor returns a `RDFoxRuleShards`, a tuple (res,ext):
59 // - the `res` List is a list of atoms resulting from the conversion
60 // of the axiom.
61 // - for some Class Expressions appearing in the head of an Axiom,
62 // the conversion might produce atoms that need to appear in the
63 // body (and not in the head) of the rule. This is what the `ext`
64 // List is for.
65 val sub = axiom.getSubClass.accept(subVisitor)
66 val sup = axiom.getSuperClass.accept(superVisitor)
67 val head = sup.res.asJava
68 val body = (sub.res ++ sup.ext).asJava
69 List(Rule.create(head, body))
70 }
71
72 override def visit(axiom: OWLEquivalentClassesAxiom): List[Rule] = {
73 for {
74 axiom1 <- axiom.asPairwiseAxioms.asScala.toList
75 axiom2 <- axiom1.asOWLSubClassOfAxioms.asScala.toList
76 rule <- axiom2.accept(this)
77 } yield rule
78 }
79
80 override def visit(axiom: OWLSubObjectPropertyOfAxiom): List[Rule] = {
81 val term1 = RSAOntology.genFreshVariable()
82 val subVisitor =
83 new RDFoxPropertyExprConverter(term, term1, suffix)
84 val superVisitor = new RDFoxPropertyExprConverter(term, term1, suffix)
85 val body: List[BodyFormula] = axiom.getSubProperty.accept(subVisitor)
86 val head: List[TupleTableAtom] = axiom.getSuperProperty.accept(superVisitor)
87 List(Rule.create(head.asJava, body.asJava))
88 }
89
90 override def visit(axiom: OWLClassAssertionAxiom): List[Rule] = {
91 val ind = axiom.getIndividual
92 if (ind.isNamed) {
93 val term = IRI.create(ind.asOWLNamedIndividual().getIRI.getIRIString)
94 val cls = axiom.getClassExpression
95 val visitor =
96 new RDFoxClassExprConverter(term, unsafe, SkolemStrategy.None, suffix)
97 val shard = cls.accept(visitor)
98 List(Rule.create(shard.res.asJava, shard.ext.asJava))
99 } else {
100 List()
101 }
102 }
103
104 def doDefault(axiom: OWLAxiom): List[Rule] = List()
105
106} // class RDFoxAxiomConverter