aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Igne <federico.igne@cs.ox.ac.uk>2021-11-11 17:32:13 +0000
committerFederico Igne <federico.igne@cs.ox.ac.uk>2021-11-11 17:32:13 +0000
commit0b640c3d13c65a8b83ee4313827b5fc6a12e1936 (patch)
treeafdad06b833e3692e98100784309d421fa590677
parent1b9bf987ffa47414122f1078fb457028d244e57e (diff)
downloadRSAComb-0b640c3d13c65a8b83ee4313827b5fc6a12e1936.tar.gz
RSAComb-0b640c3d13c65a8b83ee4313827b5fc6a12e1936.zip
Add support for directory of query files
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala6
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/RSAConfig.scala11
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala18
3 files changed, 27 insertions, 8 deletions
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala
index cbec9ec..3aa81a7 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala
@@ -50,16 +50,14 @@ object RSAComb extends App {
50 val data = config('data).get[List[os.Path]] 50 val data = config('data).get[List[os.Path]]
51 val ontology = Ontology(ontopath, data).normalize(new Normalizer) 51 val ontology = Ontology(ontopath, data).normalize(new Normalizer)
52 52
53 //ontology.axioms foreach println
54
55 /* Approximate the ontology to RSA */ 53 /* Approximate the ontology to RSA */
56 val toRSA = config('approximation).get[Approximation[RSAOntology]] 54 val toRSA = config('approximation).get[Approximation[RSAOntology]]
57 val rsa = ontology approximate toRSA 55 val rsa = ontology approximate toRSA
58 56
59 if (config contains 'queries) { 57 if (config contains 'queries) {
60 val queries = 58 val queries =
61 RDFoxUtil.loadQueriesFromFile( 59 RDFoxUtil.loadQueriesFromFiles(
62 config('queries).get[os.Path] 60 config('queries).get[List[os.Path]]
63 ) 61 )
64 62
65 val answers = rsa ask queries 63 val answers = rsa ask queries
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAConfig.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAConfig.scala
index 3e92d81..1a4afd7 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAConfig.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAConfig.scala
@@ -126,9 +126,14 @@ object RSAConfig {
126 } 126 }
127 case flag @ ("-q" | "--queries") :: _query :: tail => { 127 case flag @ ("-q" | "--queries") :: _query :: tail => {
128 val query = getPath(_query) 128 val query = getPath(_query)
129 if (!os.isFile(query)) 129 val files =
130 exit(s"'${_query}' is not a valid filename.") 130 if (os.isFile(query))
131 parse(tail, config += ('queries -> query)) 131 Seq(query)
132 else if (os.isDir(query))
133 os.walk(query).filter(os.isFile)
134 else
135 exit(s"'${_query}' is not a valid path.")
136 parse(tail, config += ('queries -> files))
132 } 137 }
133 case flag @ ("-o" | "--ontology") :: _ontology :: tail => { 138 case flag @ ("-o" | "--ontology") :: _ontology :: tail => {
134 val ontology = getPath(_ontology) 139 val ontology = getPath(_ontology)
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 d4e55d8..4153fac 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
@@ -250,7 +250,7 @@ object RDFoxUtil {
250 * @note if a query is not recognized as a [[SelectQuery]] by RDFox 250 * @note if a query is not recognized as a [[SelectQuery]] by RDFox
251 * it is discarded. 251 * it is discarded.
252 * 252 *
253 * @param file file containing a list of conjunctive queries. 253 * @param path file containing a list of conjunctive queries.
254 * @param prefixes additional prefixes for the query. It defaults to 254 * @param prefixes additional prefixes for the query. It defaults to
255 * an empty set. 255 * an empty set.
256 * 256 *
@@ -285,6 +285,22 @@ object RDFoxUtil {
285 queries 285 queries
286 } 286 }
287 287
288 /** Load SPARQL queries from files.
289 *
290 * @param paths list of files containing a conjunctive queries.
291 * @param prefixes additional prefixes for the query. It defaults to
292 * an empty set.
293 *
294 * @return a list of [[tech.oxfordsemantic.jrdfox.logic.sparql.statement.SelectQuery SelectQuery]] queries.
295 *
296 * @see [[RDFoxUtil.loadQueriesFromFile()]] for more details on the file format.
297 */
298 def loadQueriesFromFiles(
299 paths: List[os.Path],
300 prefixes: Prefixes = new Prefixes()
301 ): List[ConjunctiveQuery] =
302 paths.flatMap(loadQueriesFromFile(_, prefixes))
303
288 /** Parse a SELECT query from a string in SPARQL format. 304 /** Parse a SELECT query from a string in SPARQL format.
289 * 305 *
290 * @param query the string containing the SPARQL query 306 * @param query the string containing the SPARQL query