diff options
Diffstat (limited to 'src/main/scala')
| -rw-r--r-- | src/main/scala/rsacomb/FilteringProgram.scala | 45 | ||||
| -rw-r--r-- | src/main/scala/rsacomb/Main.scala | 3 |
2 files changed, 24 insertions, 24 deletions
diff --git a/src/main/scala/rsacomb/FilteringProgram.scala b/src/main/scala/rsacomb/FilteringProgram.scala index dc5e95e..b0d4aab 100644 --- a/src/main/scala/rsacomb/FilteringProgram.scala +++ b/src/main/scala/rsacomb/FilteringProgram.scala | |||
| @@ -32,8 +32,29 @@ class FilteringProgram(query: SelectQuery, constants: List[Term]) | |||
| 32 | /* Makes mplicit conversion OWLAPI IRI <-> RDFox IRI available */ | 32 | /* Makes mplicit conversion OWLAPI IRI <-> RDFox IRI available */ |
| 33 | import RDFoxUtil._ | 33 | import RDFoxUtil._ |
| 34 | 34 | ||
| 35 | val answer: List[Term] = query.getSelection.asScala.map(_.getVariable).toList | 35 | lazy val variables = { |
| 36 | val bounded: List[Term] = this.getBoundedVariables | 36 | query.getQueryBody.getWherePattern match { |
| 37 | case b: ConjunctionPattern => { | ||
| 38 | b.getConjuncts.asScala.toSet.flatMap { conj: QueryPattern => | ||
| 39 | conj match { | ||
| 40 | case c: TriplePattern => | ||
| 41 | Set(c.getSubject, c.getPredicate, c.getObject) | ||
| 42 | .filter(_.isInstanceOf[Variable]) | ||
| 43 | case _ => Set() | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } | ||
| 47 | case _ => Set() | ||
| 48 | } | ||
| 49 | }.toList | ||
| 50 | |||
| 51 | val answer: List[Term] = | ||
| 52 | if (query.getAllPossibleVariables) { | ||
| 53 | variables | ||
| 54 | } else { | ||
| 55 | query.getSelection.asScala.map(_.getVariable).toList | ||
| 56 | } | ||
| 57 | val bounded: List[Term] = this.variables.filterNot(answer.contains(_)) | ||
| 37 | 58 | ||
| 38 | val facts: List[TupleTableAtom] = constants.map(named) | 59 | val facts: List[TupleTableAtom] = constants.map(named) |
| 39 | val rules: List[Rule] = this.generateFilteringProgram().map(reifyRule) | 60 | val rules: List[Rule] = this.generateFilteringProgram().map(reifyRule) |
| @@ -45,26 +66,6 @@ class FilteringProgram(query: SelectQuery, constants: List[Term]) | |||
| 45 | RSA.internal("NAMED") | 66 | RSA.internal("NAMED") |
| 46 | ) | 67 | ) |
| 47 | 68 | ||
| 48 | private def getBoundedVariables: List[Term] = { | ||
| 49 | def extract(body: GroupGraphPattern): Set[Term] = { | ||
| 50 | body match { | ||
| 51 | case b: ConjunctionPattern => { | ||
| 52 | b.getConjuncts.asScala.toSet.flatMap { conj: QueryPattern => | ||
| 53 | conj match { | ||
| 54 | case c: TriplePattern => | ||
| 55 | Set(c.getSubject, c.getPredicate, c.getObject).filter( | ||
| 56 | _.isInstanceOf[Variable] | ||
| 57 | ) | ||
| 58 | case _ => Set() | ||
| 59 | } | ||
| 60 | } | ||
| 61 | } | ||
| 62 | case _ => Set() | ||
| 63 | } | ||
| 64 | } | ||
| 65 | extract(query.getQueryBody.getWherePattern).toList | ||
| 66 | } | ||
| 67 | |||
| 68 | /* NOTE: we are restricting to queries that contain conjunctions of | 69 | /* NOTE: we are restricting to queries that contain conjunctions of |
| 69 | * atoms for the time being. This might need to be reviewed in the | 70 | * atoms for the time being. This might need to be reviewed in the |
| 70 | * future. | 71 | * future. |
diff --git a/src/main/scala/rsacomb/Main.scala b/src/main/scala/rsacomb/Main.scala index 5d92061..830f1e0 100644 --- a/src/main/scala/rsacomb/Main.scala +++ b/src/main/scala/rsacomb/Main.scala | |||
| @@ -62,8 +62,7 @@ object RSAComb extends App { | |||
| 62 | "SELECT ?X WHERE {?X ?Y ?Z}" | 62 | "SELECT ?X WHERE {?X ?Y ?Z}" |
| 63 | ) | 63 | ) |
| 64 | 64 | ||
| 65 | /* Compute the filtering program from the given query */ | 65 | val filter = query map { q => ontology.filteringProgram(q) } |
| 66 | val filter = ontology.filteringProgram(query) | ||
| 67 | 66 | ||
| 68 | /* ... */ | 67 | /* ... */ |
| 69 | } | 68 | } |
