diff options
| author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2021-02-04 10:41:09 +0000 |
|---|---|---|
| committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2021-02-04 10:41:09 +0000 |
| commit | 1cb2165ccbcd6b1210bee1dfb7b527b4d2440901 (patch) | |
| tree | 878e6666433d15cc48c23cdc4c4d7c8770a39411 /src/main | |
| parent | b9fe66ed1b48d21f3fe6cb960c8fbe8f22f4a39c (diff) | |
| download | RSAComb-1cb2165ccbcd6b1210bee1dfb7b527b4d2440901.tar.gz RSAComb-1cb2165ccbcd6b1210bee1dfb7b527b4d2440901.zip | |
Add versioning system for different versions of code
Later on this will allow us to select the algorithm from the command
line and compare performance easily.
Diffstat (limited to 'src/main')
| -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 |
4 files changed, 66 insertions, 12 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 | } | ||
