diff options
Diffstat (limited to 'src/main/scala/rsacomb/RDFoxAxiomConverter.scala')
-rw-r--r-- | src/main/scala/rsacomb/RDFoxAxiomConverter.scala | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/main/scala/rsacomb/RDFoxAxiomConverter.scala b/src/main/scala/rsacomb/RDFoxAxiomConverter.scala new file mode 100644 index 0000000..0a6272f --- /dev/null +++ b/src/main/scala/rsacomb/RDFoxAxiomConverter.scala | |||
@@ -0,0 +1,58 @@ | |||
1 | package rsacomb | ||
2 | |||
3 | import org.semanticweb.owlapi.model.{OWLAxiom, OWLSubClassOfAxiom, OWLEquivalentClassesAxiom} | ||
4 | import org.semanticweb.owlapi.model.OWLAxiomVisitorEx | ||
5 | |||
6 | import tech.oxfordsemantic.jrdfox.logic.Rule | ||
7 | import tech.oxfordsemantic.jrdfox.logic.{Atom, Term, Literal, Individual} | ||
8 | |||
9 | import scala.collection.JavaConverters._ | ||
10 | |||
11 | import rsacomb.SkolemStrategy | ||
12 | import rsacomb.RDFoxRuleShards | ||
13 | |||
14 | object RDFoxAxiomConverter { | ||
15 | |||
16 | def apply(term : Term, skolem : SkolemStrategy) : RDFoxAxiomConverter = | ||
17 | new RDFoxAxiomConverter(term, skolem) | ||
18 | |||
19 | def apply(term : Term) : RDFoxAxiomConverter = | ||
20 | new RDFoxAxiomConverter(term, SkolemStrategy.None) | ||
21 | |||
22 | } // object RDFoxAxiomConverter | ||
23 | |||
24 | class RDFoxAxiomConverter(term : Term, skolem : SkolemStrategy) | ||
25 | extends OWLAxiomVisitorEx[List[Rule]] | ||
26 | { | ||
27 | |||
28 | override | ||
29 | def visit(axiom : OWLSubClassOfAxiom) : List[Rule] = { | ||
30 | // Skolemization is needed only for the head of an axiom | ||
31 | val subVisitor = new RDFoxClassExprConverter(term,SkolemStrategy.None) | ||
32 | val superVisitor = new RDFoxClassExprConverter(term, skolem) | ||
33 | // Each visitor returns a `RDFoxRuleShards`, a tuple (res,ext): | ||
34 | // - the `res` List is a list of atoms resulting from the conversion | ||
35 | // of the axiom. | ||
36 | // - for some Class Expressions appearing in the head of an Axiom, | ||
37 | // the conversion might produce atoms that need to appear in the | ||
38 | // body (and not in the head) of the rule. This is what the `ext` | ||
39 | // List is for. | ||
40 | val sub = axiom.getSubClass.accept(subVisitor) | ||
41 | val sup = axiom.getSuperClass.accept(superVisitor) | ||
42 | val head = sup.res.asJava | ||
43 | val body = (sub.res ++ sup.ext).asJava | ||
44 | List(Rule.create(head,body)) | ||
45 | } | ||
46 | |||
47 | override | ||
48 | def visit(axiom : OWLEquivalentClassesAxiom) : List[Rule] = { | ||
49 | for { | ||
50 | axiom1 <- axiom.asPairwiseAxioms.asScala.toList | ||
51 | axiom2 <- axiom1.asOWLSubClassOfAxioms.asScala.toList | ||
52 | rule <- axiom2.accept(this) | ||
53 | } yield rule | ||
54 | } | ||
55 | |||
56 | def doDefault(axiom : OWLAxiom) : List[Rule] = List() | ||
57 | |||
58 | } // class RDFoxAxiomConverter | ||