diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | 3 | ||||
| -rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/filtering/FilteringProgram.scala | 41 | ||||
| -rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/filtering/NaiveFilteringProgram.scala (renamed from src/main/scala/uk/ac/ox/cs/rsacomb/FilteringProgram.scala) | 16 | ||||
| -rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/util/Versioned.scala | 18 | ||||
| -rw-r--r-- | src/test/scala/uk/ac/ox/cs/rsacomb/SuiteAll.scala | 33 | ||||
| -rw-r--r-- | src/test/scala/uk/ac/ox/cs/rsacomb/filtering/FilteringProgramSpecs.scala (renamed from src/test/scala/uk/ac/ox/cs/rsacomb/FilteringProgramSpecs.scala) | 20 |
6 files changed, 98 insertions, 33 deletions
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala index 42a5b87..b0b52c7 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | |||
| @@ -58,6 +58,7 @@ import tech.oxfordsemantic.jrdfox.logic._ | |||
| 58 | import org.semanticweb.owlapi.model.OWLObjectInverseOf | 58 | import org.semanticweb.owlapi.model.OWLObjectInverseOf |
| 59 | 59 | ||
| 60 | import uk.ac.ox.cs.rsacomb.converter._ | 60 | import uk.ac.ox.cs.rsacomb.converter._ |
| 61 | import uk.ac.ox.cs.rsacomb.filtering.{FilteringProgram, FilterType} | ||
| 61 | import uk.ac.ox.cs.rsacomb.suffix._ | 62 | import uk.ac.ox.cs.rsacomb.suffix._ |
| 62 | import uk.ac.ox.cs.rsacomb.sparql._ | 63 | import uk.ac.ox.cs.rsacomb.sparql._ |
| 63 | import uk.ac.ox.cs.rsacomb.util.{RDFoxUtil, RSA} | 64 | import uk.ac.ox.cs.rsacomb.util.{RDFoxUtil, RSA} |
| @@ -409,7 +410,7 @@ class RSAOntology(_ontology: File, val datafiles: File*) { | |||
| 409 | 410 | ||
| 410 | def filteringProgram(query: ConjunctiveQuery): FilteringProgram = | 411 | def filteringProgram(query: ConjunctiveQuery): FilteringProgram = |
| 411 | Logger.timed( | 412 | Logger.timed( |
| 412 | new FilteringProgram(query), | 413 | FilteringProgram(FilterType.FILTER_NAIVE)(query), |
| 413 | "Generating filtering program", | 414 | "Generating filtering program", |
| 414 | Logger.DEBUG | 415 | Logger.DEBUG |
| 415 | ) | 416 | ) |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/filtering/FilteringProgram.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/filtering/FilteringProgram.scala new file mode 100644 index 0000000..9c8cbaa --- /dev/null +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/filtering/FilteringProgram.scala | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | package uk.ac.ox.cs.rsacomb.filtering | ||
| 2 | |||
| 3 | import tech.oxfordsemantic.jrdfox.logic.datalog.Rule | ||
| 4 | import uk.ac.ox.cs.rsacomb.sparql.ConjunctiveQuery | ||
| 5 | import uk.ac.ox.cs.rsacomb.util.Versioned | ||
| 6 | |||
| 7 | sealed trait FilterType | ||
| 8 | object FilterType { | ||
| 9 | case object FILTER_NAIVE extends FilterType | ||
| 10 | case object FILTER_REVISED_V1 extends FilterType | ||
| 11 | } | ||
| 12 | |||
| 13 | object FilteringProgram extends Versioned[FilterType] { | ||
| 14 | |||
| 15 | import FilterType._ | ||
| 16 | |||
| 17 | type Result = (ConjunctiveQuery) => FilteringProgram | ||
| 18 | |||
| 19 | def apply(t: FilterType): (ConjunctiveQuery) => FilteringProgram = | ||
| 20 | t match { | ||
| 21 | case FILTER_NAIVE => NaiveFilteringProgram(_) | ||
| 22 | case FILTER_REVISED_V1 => NaiveFilteringProgram(_) | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | /** Filtering Program generator | ||
| 27 | * | ||
| 28 | * Handles the conversion of a CQ into a set of logic rules, | ||
| 29 | * representing the filtering step of the RSA combined approach. | ||
| 30 | */ | ||
| 31 | trait FilteringProgram { | ||
| 32 | |||
| 33 | /** Query from which the filtering program is generated */ | ||
| 34 | val query: ConjunctiveQuery | ||
| 35 | |||
| 36 | /** Collection of filtering program rules. */ | ||
| 37 | def rules: List[Rule] | ||
| 38 | |||
| 39 | /** Pretty-print filtering rule */ | ||
| 40 | override def toString(): String = rules mkString "\n" | ||
| 41 | } | ||
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/FilteringProgram.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/filtering/NaiveFilteringProgram.scala index 06224e7..57898a8 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/FilteringProgram.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/filtering/NaiveFilteringProgram.scala | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | package uk.ac.ox.cs.rsacomb | 1 | package uk.ac.ox.cs.rsacomb.filtering |
| 2 | 2 | ||
| 3 | //import scala.collection.JavaConverters._ | 3 | //import scala.collection.JavaConverters._ |
| 4 | import tech.oxfordsemantic.jrdfox.logic.Datatype | 4 | import tech.oxfordsemantic.jrdfox.logic.Datatype |
| @@ -14,17 +14,14 @@ import uk.ac.ox.cs.rsacomb.suffix.{Forward, Backward} | |||
| 14 | import uk.ac.ox.cs.rsacomb.util.{RSA, RDFoxUtil} | 14 | import uk.ac.ox.cs.rsacomb.util.{RSA, RDFoxUtil} |
| 15 | 15 | ||
| 16 | /** Factory for [[uk.ac.ox.cs.rsacomb.FilteringProgram FilteringProgram]] */ | 16 | /** Factory for [[uk.ac.ox.cs.rsacomb.FilteringProgram FilteringProgram]] */ |
| 17 | object FilteringProgram { | 17 | object NaiveFilteringProgram { |
| 18 | 18 | ||
| 19 | /** Create a new FilteringProgram instance. | 19 | /** Create a new FilteringProgram instance. |
| 20 | * | 20 | * |
| 21 | * @param query CQ to be converted into logic rules. | 21 | * @param query CQ to be converted into logic rules. |
| 22 | * @param constants constants in the original ontology. They will be | ||
| 23 | * used to initialize predicate `rsa:Named`. | ||
| 24 | */ | 22 | */ |
| 25 | def apply(query: ConjunctiveQuery): FilteringProgram = | 23 | def apply(query: ConjunctiveQuery): FilteringProgram = |
| 26 | new FilteringProgram(query) | 24 | new NaiveFilteringProgram(query) |
| 27 | |||
| 28 | } | 25 | } |
| 29 | 26 | ||
| 30 | /** Filtering Program generator | 27 | /** Filtering Program generator |
| @@ -34,7 +31,8 @@ object FilteringProgram { | |||
| 34 | * | 31 | * |
| 35 | * Instances can be created using the companion object. | 32 | * Instances can be created using the companion object. |
| 36 | */ | 33 | */ |
| 37 | class FilteringProgram(query: ConjunctiveQuery) { | 34 | class NaiveFilteringProgram(val query: ConjunctiveQuery) |
| 35 | extends FilteringProgram { | ||
| 38 | 36 | ||
| 39 | /** Extends capabilities of | 37 | /** Extends capabilities of |
| 40 | * [[tech.oxfordsemantic.jrdfox.logic.datalog.TupleTableAtom TupleTableAtom]] | 38 | * [[tech.oxfordsemantic.jrdfox.logic.datalog.TupleTableAtom TupleTableAtom]] |
| @@ -306,8 +304,4 @@ class FilteringProgram(query: ConjunctiveQuery) { | |||
| 306 | r8a ::: r8b :: r8c ::: | 304 | r8a ::: r8b :: r8c ::: |
| 307 | r9 :: List()) map RDFoxUtil.reify | 305 | r9 :: List()) map RDFoxUtil.reify |
| 308 | } | 306 | } |
| 309 | |||
| 310 | /** Pretty-print filtering rule */ | ||
| 311 | override def toString(): String = rules mkString "\n" | ||
| 312 | |||
| 313 | } | 307 | } |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/util/Versioned.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/util/Versioned.scala new file mode 100644 index 0000000..aa2a963 --- /dev/null +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/util/Versioned.scala | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | package uk.ac.ox.cs.rsacomb.util | ||
| 2 | |||
| 3 | /** Utility to allow hussle free version switching of blocks of code | ||
| 4 | * | ||
| 5 | * This allows for example testing different implementations of a | ||
| 6 | * module or algorithm. | ||
| 7 | */ | ||
| 8 | trait Versioned[T] { | ||
| 9 | |||
| 10 | /** Type of the returned versioned object */ | ||
| 11 | type Result | ||
| 12 | |||
| 13 | /** Returns correct instance of the versioned object | ||
| 14 | * | ||
| 15 | * @param t object uniquely identifing the requested instance. | ||
| 16 | */ | ||
| 17 | def apply(t: T): Result | ||
| 18 | } | ||
diff --git a/src/test/scala/uk/ac/ox/cs/rsacomb/SuiteAll.scala b/src/test/scala/uk/ac/ox/cs/rsacomb/SuiteAll.scala index 2162f8c..f32c088 100644 --- a/src/test/scala/uk/ac/ox/cs/rsacomb/SuiteAll.scala +++ b/src/test/scala/uk/ac/ox/cs/rsacomb/SuiteAll.scala | |||
| @@ -2,16 +2,25 @@ package uk.ac.ox.cs.rsacomb | |||
| 2 | 2 | ||
| 3 | import org.scalatest.Suites | 3 | import org.scalatest.Suites |
| 4 | 4 | ||
| 5 | import uk.ac.ox.cs.rsacomb.converter.{OWLAxiomSpec, OWLClassSpec, RDFoxConverterSpec} | 5 | import uk.ac.ox.cs.rsacomb.converter.{ |
| 6 | import uk.ac.ox.cs.rsacomb.sparql.{ConjunctiveQueryAnswerSpec, ConjunctiveQuerySpec} | 6 | OWLAxiomSpec, |
| 7 | OWLClassSpec, | ||
| 8 | RDFoxConverterSpec | ||
| 9 | } | ||
| 10 | import uk.ac.ox.cs.rsacomb.filtering.NaiveFilteringProgramSpec | ||
| 11 | import uk.ac.ox.cs.rsacomb.sparql.{ | ||
| 12 | ConjunctiveQueryAnswerSpec, | ||
| 13 | ConjunctiveQuerySpec | ||
| 14 | } | ||
| 7 | 15 | ||
| 8 | class SuiteAll extends Suites ( | 16 | class SuiteAll |
| 9 | new Ontology1_CanonicalModelSpec, | 17 | extends Suites( |
| 10 | new Ontology2_CanonicalModelSpec, | 18 | new Ontology1_CanonicalModelSpec, |
| 11 | new FilteringProgramSpec, | 19 | new Ontology2_CanonicalModelSpec, |
| 12 | new OWLAxiomSpec, | 20 | new NaiveFilteringProgramSpec, |
| 13 | new OWLClassSpec, | 21 | new OWLAxiomSpec, |
| 14 | new RDFoxConverterSpec, | 22 | new OWLClassSpec, |
| 15 | new ConjunctiveQueryAnswerSpec, | 23 | new RDFoxConverterSpec, |
| 16 | new ConjunctiveQuerySpec | 24 | new ConjunctiveQueryAnswerSpec, |
| 17 | ) | 25 | new ConjunctiveQuerySpec |
| 26 | ) | ||
diff --git a/src/test/scala/uk/ac/ox/cs/rsacomb/FilteringProgramSpecs.scala b/src/test/scala/uk/ac/ox/cs/rsacomb/filtering/FilteringProgramSpecs.scala index 32ef8da..372b78c 100644 --- a/src/test/scala/uk/ac/ox/cs/rsacomb/FilteringProgramSpecs.scala +++ b/src/test/scala/uk/ac/ox/cs/rsacomb/filtering/FilteringProgramSpecs.scala | |||
| @@ -1,12 +1,14 @@ | |||
| 1 | package uk.ac.ox.cs.rsacomb | 1 | package uk.ac.ox.cs.rsacomb.filtering |
| 2 | 2 | ||
| 3 | import org.scalatest.flatspec.AnyFlatSpec | 3 | import org.scalatest.flatspec.AnyFlatSpec |
| 4 | import org.scalatest.matchers.should.Matchers | 4 | import org.scalatest.matchers.should.Matchers |
| 5 | import tech.oxfordsemantic.jrdfox.logic.expression.IRI | 5 | import tech.oxfordsemantic.jrdfox.logic.expression.IRI |
| 6 | import uk.ac.ox.cs.rsacomb.FilteringProgram | 6 | import uk.ac.ox.cs.rsacomb.filtering.{FilteringProgram, FilterType} |
| 7 | import uk.ac.ox.cs.rsacomb.sparql.ConjunctiveQuery | 7 | import uk.ac.ox.cs.rsacomb.sparql.ConjunctiveQuery |
| 8 | 8 | ||
| 9 | object FilteringProgramSpec { | 9 | object NaiveFilteringProgramSpec { |
| 10 | |||
| 11 | val naive: FilterType = FilterType.FILTER_NAIVE | ||
| 10 | 12 | ||
| 11 | val constants = | 13 | val constants = |
| 12 | List(IRI.create("_:iri1"), IRI.create("_:iri2"), IRI.create("_:iri3")) | 14 | List(IRI.create("_:iri1"), IRI.create("_:iri2"), IRI.create("_:iri3")) |
| @@ -61,31 +63,31 @@ object FilteringProgramSpec { | |||
| 61 | """ | 63 | """ |
| 62 | } | 64 | } |
| 63 | 65 | ||
| 64 | class FilteringProgramSpec extends AnyFlatSpec with Matchers { | 66 | class NaiveFilteringProgramSpec extends AnyFlatSpec with Matchers { |
| 65 | 67 | ||
| 66 | import FilteringProgramSpec._ | 68 | import NaiveFilteringProgramSpec._ |
| 67 | 69 | ||
| 68 | "CQ 0" should "generate 27 rules and 3 facts" in { | 70 | "CQ 0" should "generate 27 rules and 3 facts" in { |
| 69 | val cq = ConjunctiveQuery.parse(cq0).get | 71 | val cq = ConjunctiveQuery.parse(cq0).get |
| 70 | val filter = FilteringProgram(cq) | 72 | val filter = FilteringProgram(naive)(cq) |
| 71 | filter.rules should have length 27 | 73 | filter.rules should have length 27 |
| 72 | } | 74 | } |
| 73 | 75 | ||
| 74 | "CQ 1" should "generate 15 rules" in { | 76 | "CQ 1" should "generate 15 rules" in { |
| 75 | val cq = ConjunctiveQuery.parse(cq1).get | 77 | val cq = ConjunctiveQuery.parse(cq1).get |
| 76 | val filter = FilteringProgram(cq) | 78 | val filter = FilteringProgram(naive)(cq) |
| 77 | filter.rules should have length 15 | 79 | filter.rules should have length 15 |
| 78 | } | 80 | } |
| 79 | 81 | ||
| 80 | "CQ 2" should "generate 51 rules" in { | 82 | "CQ 2" should "generate 51 rules" in { |
| 81 | val cq = ConjunctiveQuery.parse(cq2).get | 83 | val cq = ConjunctiveQuery.parse(cq2).get |
| 82 | val filter = FilteringProgram(cq) | 84 | val filter = FilteringProgram(naive)(cq) |
| 83 | filter.rules should have length 51 | 85 | filter.rules should have length 51 |
| 84 | } | 86 | } |
| 85 | 87 | ||
| 86 | "BCQ 0" should "generate 46 rules" in { | 88 | "BCQ 0" should "generate 46 rules" in { |
| 87 | val cq = ConjunctiveQuery.parse(bcq0).get | 89 | val cq = ConjunctiveQuery.parse(bcq0).get |
| 88 | val filter = FilteringProgram(cq) | 90 | val filter = FilteringProgram(naive)(cq) |
| 89 | filter.rules should have length 43 | 91 | filter.rules should have length 43 |
| 90 | } | 92 | } |
| 91 | 93 | ||
