diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala | 8 | ||||
| -rw-r--r-- | src/test/scala/uk/ac/ox/cs/rsacomb/functional/Functional.scala | 49 |
2 files changed, 54 insertions, 3 deletions
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala index 46f1160..e3e7dd4 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala | |||
| @@ -243,7 +243,8 @@ object RDFoxUtil { | |||
| 243 | path: os.Path, | 243 | path: os.Path, |
| 244 | prefixes: Prefixes = new Prefixes() | 244 | prefixes: Prefixes = new Prefixes() |
| 245 | ): List[ConjunctiveQuery] = { | 245 | ): List[ConjunctiveQuery] = { |
| 246 | val pattern = raw"\^\[Query(\d+)\]".r | 246 | val header = raw"\^\[[Qq]uery(\d+)\]".r |
| 247 | val comment = "^#.*".r | ||
| 247 | val queries = os.read | 248 | val queries = os.read |
| 248 | .lines(path) | 249 | .lines(path) |
| 249 | .map(_.trim.filter(_ >= ' ')) | 250 | .map(_.trim.filter(_ >= ' ')) |
| @@ -251,12 +252,13 @@ object RDFoxUtil { | |||
| 251 | .foldRight((List.empty[Option[ConjunctiveQuery]], List.empty[String])) { | 252 | .foldRight((List.empty[Option[ConjunctiveQuery]], List.empty[String])) { |
| 252 | case (line, (acc, query)) => { | 253 | case (line, (acc, query)) => { |
| 253 | line match { | 254 | line match { |
| 254 | case pattern(id) => { | 255 | case header(id) => { |
| 255 | val cq = | 256 | val cq = |
| 256 | ConjunctiveQuery.parse(id.toInt, query.mkString(" "), prefixes) | 257 | ConjunctiveQuery.parse(id.toInt, query.mkString(" "), prefixes) |
| 257 | (cq :: acc, List.empty) | 258 | (cq :: acc, List.empty) |
| 258 | } | 259 | } |
| 259 | case _ => (acc, line :: query) | 260 | case comment() => (acc, query) |
| 261 | case _ => (acc, line :: query) | ||
| 260 | } | 262 | } |
| 261 | } | 263 | } |
| 262 | } | 264 | } |
diff --git a/src/test/scala/uk/ac/ox/cs/rsacomb/functional/Functional.scala b/src/test/scala/uk/ac/ox/cs/rsacomb/functional/Functional.scala new file mode 100644 index 0000000..6882997 --- /dev/null +++ b/src/test/scala/uk/ac/ox/cs/rsacomb/functional/Functional.scala | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | package uk.ac.ox.cs.rsacomb.functional | ||
| 2 | |||
| 3 | import org.scalatest.funspec.AnyFunSpec | ||
| 4 | import org.scalatest.matchers.should.Matchers | ||
| 5 | |||
| 6 | import uk.ac.ox.cs.rsacomb.ontology.Ontology | ||
| 7 | import uk.ac.ox.cs.rsacomb.approximation.Upperbound | ||
| 8 | import uk.ac.ox.cs.rsacomb.converter.Normalizer | ||
| 9 | import uk.ac.ox.cs.rsacomb.util.RDFoxUtil | ||
| 10 | |||
| 11 | class LUBM extends AnyFunSpec with Matchers { | ||
| 12 | |||
| 13 | private val test = os.pwd / "tests" / "lubm" | ||
| 14 | |||
| 15 | /* Approximation algorithms */ | ||
| 16 | //private val toLowerbound = new Lowerbound | ||
| 17 | private val toUpperbound = new Upperbound | ||
| 18 | |||
| 19 | /* Normalization algorithms */ | ||
| 20 | private val normalizer = new Normalizer | ||
| 21 | |||
| 22 | /* Ontology */ | ||
| 23 | private val ontology = Ontology( | ||
| 24 | test / "univ-bench.owl", | ||
| 25 | List(test / "data" / "lubm1.ttl") | ||
| 26 | ) normalize normalizer | ||
| 27 | private val rsa = ontology approximate toUpperbound | ||
| 28 | |||
| 29 | /* Queries and results */ | ||
| 30 | private val queries = | ||
| 31 | RDFoxUtil.loadQueriesFromFile(test / "queries.sparql") | ||
| 32 | private val results = ujson.read(os.read(test / "results.json")).arr | ||
| 33 | |||
| 34 | describe("Ontology size: 1)") { | ||
| 35 | |||
| 36 | queries foreach { query => | ||
| 37 | it(s"Tested Query${query.id}") { | ||
| 38 | val answers = rsa.ask(query).answers.map(_._2.mkString(" ")) | ||
| 39 | val reference = results | ||
| 40 | .find(_("queryID").num == query.id) | ||
| 41 | .get("answers") | ||
| 42 | .arr | ||
| 43 | .map(_.str) | ||
| 44 | answers should contain theSameElementsAs reference | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | } | ||
| 49 | } | ||
