diff options
| author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-09-07 17:55:34 +0200 |
|---|---|---|
| committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-09-07 17:55:34 +0200 |
| commit | 3bc39ecf2eb168e1124bb123b9df0a8b933e6955 (patch) | |
| tree | f92491ab1d0158a95ea831210f32f6c328464601 /src/main/scala/rsacomb/RDFoxAxiomConverter.scala | |
| parent | d085aeae07a729467047aba50b22e9baa7a4d10f (diff) | |
| download | RSAComb-3bc39ecf2eb168e1124bb123b9df0a8b933e6955.tar.gz RSAComb-3bc39ecf2eb168e1124bb123b9df0a8b933e6955.zip | |
Introduce naive fresh variable generator
Diffstat (limited to 'src/main/scala/rsacomb/RDFoxAxiomConverter.scala')
| -rw-r--r-- | src/main/scala/rsacomb/RDFoxAxiomConverter.scala | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/src/main/scala/rsacomb/RDFoxAxiomConverter.scala b/src/main/scala/rsacomb/RDFoxAxiomConverter.scala index 0a79823..d90c966 100644 --- a/src/main/scala/rsacomb/RDFoxAxiomConverter.scala +++ b/src/main/scala/rsacomb/RDFoxAxiomConverter.scala | |||
| @@ -1,6 +1,11 @@ | |||
| 1 | package rsacomb | 1 | package rsacomb |
| 2 | 2 | ||
| 3 | import org.semanticweb.owlapi.model.{OWLAxiom, OWLSubClassOfAxiom, OWLEquivalentClassesAxiom, OWLObjectPropertyExpression} | 3 | import org.semanticweb.owlapi.model.{ |
| 4 | OWLAxiom, | ||
| 5 | OWLSubClassOfAxiom, | ||
| 6 | OWLEquivalentClassesAxiom, | ||
| 7 | OWLObjectPropertyExpression | ||
| 8 | } | ||
| 4 | import org.semanticweb.owlapi.model.OWLAxiomVisitorEx | 9 | import org.semanticweb.owlapi.model.OWLAxiomVisitorEx |
| 5 | 10 | ||
| 6 | import tech.oxfordsemantic.jrdfox.logic.{Rule, BodyFormula} | 11 | import tech.oxfordsemantic.jrdfox.logic.{Rule, BodyFormula} |
| @@ -17,22 +22,24 @@ import org.semanticweb.owlapi.model.OWLObjectProperty | |||
| 17 | object RDFoxAxiomConverter { | 22 | object RDFoxAxiomConverter { |
| 18 | 23 | ||
| 19 | def apply( | 24 | def apply( |
| 20 | term : Term = Variable.create("x"), | 25 | term: Term, |
| 21 | skolem : SkolemStrategy = SkolemStrategy.None, | 26 | skolem: SkolemStrategy = SkolemStrategy.None, |
| 22 | unsafe : List[OWLObjectPropertyExpression] = List() | 27 | unsafe: List[OWLObjectPropertyExpression] = List() |
| 23 | ) : RDFoxAxiomConverter = | 28 | ): RDFoxAxiomConverter = |
| 24 | new RDFoxAxiomConverter(term, skolem, unsafe) | 29 | new RDFoxAxiomConverter(term, skolem, unsafe) |
| 25 | 30 | ||
| 26 | } // object RDFoxAxiomConverter | 31 | } // object RDFoxAxiomConverter |
| 27 | 32 | ||
| 28 | class RDFoxAxiomConverter(term : Term, skolem : SkolemStrategy, unsafe : List[OWLObjectPropertyExpression]) | 33 | class RDFoxAxiomConverter( |
| 29 | extends OWLAxiomVisitorEx[List[Rule]] | 34 | term: Term, |
| 30 | { | 35 | skolem: SkolemStrategy, |
| 36 | unsafe: List[OWLObjectPropertyExpression] | ||
| 37 | ) extends OWLAxiomVisitorEx[List[Rule]] { | ||
| 31 | 38 | ||
| 32 | override | 39 | override def visit(axiom: OWLSubClassOfAxiom): List[Rule] = { |
| 33 | def visit(axiom : OWLSubClassOfAxiom) : List[Rule] = { | ||
| 34 | // Skolemization is needed only for the head of an axiom | 40 | // Skolemization is needed only for the head of an axiom |
| 35 | val subVisitor = new RDFoxClassExprConverter(term,SkolemStrategy.None, unsafe) | 41 | val subVisitor = |
| 42 | new RDFoxClassExprConverter(term, SkolemStrategy.None, unsafe) | ||
| 36 | val superVisitor = new RDFoxClassExprConverter(term, skolem, unsafe) | 43 | val superVisitor = new RDFoxClassExprConverter(term, skolem, unsafe) |
| 37 | // Each visitor returns a `RDFoxRuleShards`, a tuple (res,ext): | 44 | // Each visitor returns a `RDFoxRuleShards`, a tuple (res,ext): |
| 38 | // - the `res` List is a list of atoms resulting from the conversion | 45 | // - the `res` List is a list of atoms resulting from the conversion |
| @@ -45,30 +52,27 @@ class RDFoxAxiomConverter(term : Term, skolem : SkolemStrategy, unsafe : List[OW | |||
| 45 | val sup = axiom.getSuperClass.accept(superVisitor) | 52 | val sup = axiom.getSuperClass.accept(superVisitor) |
| 46 | val head = sup.res.asJava | 53 | val head = sup.res.asJava |
| 47 | val body = (sub.res ++ sup.ext).asJava | 54 | val body = (sub.res ++ sup.ext).asJava |
| 48 | List(Rule.create(head,body)) | 55 | List(Rule.create(head, body)) |
| 49 | } | 56 | } |
| 50 | 57 | ||
| 51 | override | 58 | override def visit(axiom: OWLEquivalentClassesAxiom): List[Rule] = { |
| 52 | def visit(axiom : OWLEquivalentClassesAxiom) : List[Rule] = { | ||
| 53 | for { | 59 | for { |
| 54 | axiom1 <- axiom.asPairwiseAxioms.asScala.toList | 60 | axiom1 <- axiom.asPairwiseAxioms.asScala.toList |
| 55 | axiom2 <- axiom1.asOWLSubClassOfAxioms.asScala.toList | 61 | axiom2 <- axiom1.asOWLSubClassOfAxioms.asScala.toList |
| 56 | rule <- axiom2.accept(this) | 62 | rule <- axiom2.accept(this) |
| 57 | } yield rule | 63 | } yield rule |
| 58 | } | 64 | } |
| 59 | 65 | ||
| 60 | override | 66 | override def visit(axiom: OWLSubObjectPropertyOfAxiom): List[Rule] = { |
| 61 | def visit(axiom : OWLSubObjectPropertyOfAxiom) : List[Rule] = { | 67 | val term1 = RSA.getFreshVariable() |
| 62 | // TODO: variables needs to be handled at visitor level. Hardcoding | 68 | val subVisitor = |
| 63 | // the name of the varibles might lead to errors for complex cases. | 69 | new RDFoxPropertyExprConverter(term, term1, SkolemStrategy.None) |
| 64 | val term1 = Variable.create("y") | 70 | val superVisitor = new RDFoxPropertyExprConverter(term, term1, skolem) |
| 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) | 71 | val body: List[BodyFormula] = axiom.getSubProperty.accept(subVisitor) |
| 68 | val head: List[Atom] = axiom.getSuperProperty.accept(superVisitor) | 72 | val head: List[Atom] = axiom.getSuperProperty.accept(superVisitor) |
| 69 | List(Rule.create(head.asJava,body.asJava)) | 73 | List(Rule.create(head.asJava, body.asJava)) |
| 70 | } | 74 | } |
| 71 | 75 | ||
| 72 | def doDefault(axiom : OWLAxiom) : List[Rule] = List() | 76 | def doDefault(axiom: OWLAxiom): List[Rule] = List() |
| 73 | 77 | ||
| 74 | } // class RDFoxAxiomConverter | 78 | } // class RDFoxAxiomConverter |
