diff options
Diffstat (limited to 'src/main/scala/rsacomb/RDFoxClassExprConverter.scala')
| -rw-r--r-- | src/main/scala/rsacomb/RDFoxClassExprConverter.scala | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/src/main/scala/rsacomb/RDFoxClassExprConverter.scala b/src/main/scala/rsacomb/RDFoxClassExprConverter.scala index 58bee44..227c25b 100644 --- a/src/main/scala/rsacomb/RDFoxClassExprConverter.scala +++ b/src/main/scala/rsacomb/RDFoxClassExprConverter.scala | |||
| @@ -10,14 +10,17 @@ import tech.oxfordsemantic.jrdfox.logic.{Atom, Term, Variable, Literal, Datatype | |||
| 10 | 10 | ||
| 11 | import rsacomb.SkolemStrategy | 11 | import rsacomb.SkolemStrategy |
| 12 | import rsacomb.RDFoxRuleShards | 12 | import rsacomb.RDFoxRuleShards |
| 13 | import org.semanticweb.owlapi.model.OWLObjectPropertyExpression | ||
| 14 | import org.semanticweb.owlapi.model.OWLObjectProperty | ||
| 13 | 15 | ||
| 14 | object RDFoxClassExprConverter { | 16 | object RDFoxClassExprConverter { |
| 15 | 17 | ||
| 16 | def apply(term : Term, skolem : SkolemStrategy) : RDFoxClassExprConverter = | 18 | def apply( |
| 17 | new RDFoxClassExprConverter(term, skolem) | 19 | term : Term = Variable.create("x"), |
| 18 | 20 | skolem : SkolemStrategy = SkolemStrategy.None, | |
| 19 | def apply(term : Term) : RDFoxClassExprConverter = | 21 | unsafe : List[OWLObjectPropertyExpression] = List() |
| 20 | new RDFoxClassExprConverter(term, SkolemStrategy.None) | 22 | ) : RDFoxClassExprConverter = |
| 23 | new RDFoxClassExprConverter(term, skolem, unsafe) | ||
| 21 | 24 | ||
| 22 | def merge(rules : List[RDFoxRuleShards]) : RDFoxRuleShards = { | 25 | def merge(rules : List[RDFoxRuleShards]) : RDFoxRuleShards = { |
| 23 | rules.foldLeft(RDFoxRuleShards(List(),List())) { | 26 | rules.foldLeft(RDFoxRuleShards(List(),List())) { |
| @@ -31,7 +34,7 @@ object RDFoxClassExprConverter { | |||
| 31 | 34 | ||
| 32 | } // object RDFoxClassExprConverter | 35 | } // object RDFoxClassExprConverter |
| 33 | 36 | ||
| 34 | class RDFoxClassExprConverter(term : Term, skolem : SkolemStrategy) | 37 | class RDFoxClassExprConverter(term : Term, skolem : SkolemStrategy, unsafe : List[OWLObjectPropertyExpression]) |
| 35 | extends OWLClassExpressionVisitorEx[RDFoxRuleShards] | 38 | extends OWLClassExpressionVisitorEx[RDFoxRuleShards] |
| 36 | { | 39 | { |
| 37 | 40 | ||
| @@ -46,7 +49,7 @@ class RDFoxClassExprConverter(term : Term, skolem : SkolemStrategy) | |||
| 46 | // OWLObjectIntersectionOf | 49 | // OWLObjectIntersectionOf |
| 47 | override | 50 | override |
| 48 | def visit(expr : OWLObjectIntersectionOf) : RDFoxRuleShards = { | 51 | def visit(expr : OWLObjectIntersectionOf) : RDFoxRuleShards = { |
| 49 | val visitor = new RDFoxClassExprConverter(term,skolem) | 52 | val visitor = new RDFoxClassExprConverter(term, skolem, unsafe) |
| 50 | // TODO: maybe using `flatMap` instead of `merge` + `map` works as well | 53 | // TODO: maybe using `flatMap` instead of `merge` + `map` works as well |
| 51 | RDFoxClassExprConverter.merge ( | 54 | RDFoxClassExprConverter.merge ( |
| 52 | expr.asConjunctSet.asScala.toList | 55 | expr.asConjunctSet.asScala.toList |
| @@ -75,22 +78,33 @@ class RDFoxClassExprConverter(term : Term, skolem : SkolemStrategy) | |||
| 75 | // TODO: variables needs to be handled at visitor level. Hardcoding | 78 | // TODO: variables needs to be handled at visitor level. Hardcoding |
| 76 | // the name of the varibles might lead to errors for complex cases. | 79 | // the name of the varibles might lead to errors for complex cases. |
| 77 | val y = Variable.create("y") | 80 | val y = Variable.create("y") |
| 78 | val (fun,term1) = skolem match { | 81 | val prop = expr.getProperty() |
| 79 | case SkolemStrategy.None => (List(),y) | 82 | // Computes the result of rule skolemization. Depending on the used |
| 80 | case SkolemStrategy.Constant(c) => (List(), Literal.create(c, Datatype.IRI_REFERENCE)) | 83 | // technique it might involve the introduction of additional atoms, |
| 84 | // and/or fresh constants and variables. | ||
| 85 | val (head, body, term1) = skolem match { | ||
| 86 | case SkolemStrategy.None => (List(), List(), y) | ||
| 87 | case SkolemStrategy.Constant(c) => (List(), List(), Literal.create(c, Datatype.IRI_REFERENCE)) | ||
| 88 | case SkolemStrategy.ConstantRSA(c) => { | ||
| 89 | val lit = Literal.create(c, Datatype.IRI_REFERENCE) | ||
| 90 | if (unsafe.contains(prop)) | ||
| 91 | (List(Atom.create(TupleTableName.create("internal:PE"),term,lit), Atom.create(TupleTableName.create("internal:U"),lit)), List(), lit) | ||
| 92 | else | ||
| 93 | (List(), List(), lit) | ||
| 94 | } | ||
| 81 | case SkolemStrategy.Standard(f) => | 95 | case SkolemStrategy.Standard(f) => |
| 82 | // At the time of writing the RDFox library does not have a | 96 | // At the time of writing the RDFox library does not have a |
| 83 | // particular class for the "SKOLEM" operator and it is instead | 97 | // particular class for the "SKOLEM" operator and it is instead |
| 84 | // a simple builtin function with a special name. | 98 | // a simple builtin function with a "special" name. |
| 85 | (List(BindAtom.create(BuiltinFunctionCall.create("SKOLEM",term),y)),y) | 99 | (List(),List(BindAtom.create(BuiltinFunctionCall.create("SKOLEM",term),y)),y) |
| 86 | } | 100 | } |
| 87 | val classVisitor = new RDFoxClassExprConverter(term1,skolem) | 101 | val classVisitor = new RDFoxClassExprConverter(term1, skolem, unsafe) |
| 88 | val classResult = expr.getFiller.accept(classVisitor) | 102 | val classResult = expr.getFiller.accept(classVisitor) |
| 89 | val propertyVisitor = new RDFoxPropertyExprConverter(term, term1, skolem) | 103 | val propertyVisitor = new RDFoxPropertyExprConverter(term, term1, skolem) |
| 90 | val propertyResult = expr.getProperty.accept(propertyVisitor) | 104 | val propertyResult = expr.getProperty.accept(propertyVisitor) |
| 91 | RDFoxRuleShards( | 105 | RDFoxRuleShards( |
| 92 | classResult.res ++ propertyResult, | 106 | classResult.res ++ propertyResult ++ head, |
| 93 | fun ++ classResult.ext | 107 | classResult.ext ++ body |
| 94 | ) | 108 | ) |
| 95 | } | 109 | } |
| 96 | 110 | ||
| @@ -100,7 +114,7 @@ class RDFoxClassExprConverter(term : Term, skolem : SkolemStrategy) | |||
| 100 | // TODO: again, no hardcoded variables | 114 | // TODO: again, no hardcoded variables |
| 101 | val vars = List(Variable.create("y"),Variable.create("z")) | 115 | val vars = List(Variable.create("y"),Variable.create("z")) |
| 102 | val classResult = RDFoxClassExprConverter.merge( | 116 | val classResult = RDFoxClassExprConverter.merge( |
| 103 | vars.map(new RDFoxClassExprConverter(_,skolem)) | 117 | vars.map(new RDFoxClassExprConverter(_,skolem, unsafe)) |
| 104 | .map(expr.getFiller.accept(_)) | 118 | .map(expr.getFiller.accept(_)) |
| 105 | ) | 119 | ) |
| 106 | val propertyResult = | 120 | val propertyResult = |
