diff options
Diffstat (limited to 'src/main/scala/uk/ac')
-rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | 16 | ||||
-rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswers.scala | 3 |
2 files changed, 16 insertions, 3 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 b1fd721..c030301 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | |||
@@ -16,7 +16,8 @@ | |||
16 | 16 | ||
17 | package uk.ac.ox.cs.rsacomb | 17 | package uk.ac.ox.cs.rsacomb |
18 | 18 | ||
19 | import java.io.File | 19 | import java.io.{File, PrintWriter} |
20 | import java.nio.file.{Path, Paths, InvalidPathException} | ||
20 | import java.util.HashMap | 21 | import java.util.HashMap |
21 | import scala.collection.JavaConverters._ | 22 | import scala.collection.JavaConverters._ |
22 | import tech.oxfordsemantic.jrdfox.client.UpdateType | 23 | import tech.oxfordsemantic.jrdfox.client.UpdateType |
@@ -97,6 +98,14 @@ object RSAConfig { | |||
97 | println(help) | 98 | println(help) |
98 | sys.exit(0) | 99 | sys.exit(0) |
99 | } | 100 | } |
101 | case flag @ ("-o" | "--output") :: _output :: tail => | ||
102 | try { | ||
103 | val output = Paths.get(_output) | ||
104 | parse(tail, config ++ Map('output -> output)) | ||
105 | } catch { | ||
106 | case e: InvalidPathException => | ||
107 | exit(s"'${_output}' is not a valid filename.") | ||
108 | } | ||
100 | case flag @ ("-q" | "--queries") :: _query :: tail => { | 109 | case flag @ ("-q" | "--queries") :: _query :: tail => { |
101 | val query = new File(_query) | 110 | val query = new File(_query) |
102 | if (!query.isFile) | 111 | if (!query.isFile) |
@@ -144,6 +153,11 @@ object RSAComb extends App { | |||
144 | 153 | ||
145 | val answers = rsa ask queries | 154 | val answers = rsa ask queries |
146 | 155 | ||
156 | /* Write answers to output file */ | ||
157 | val output = new PrintWriter(config('output).get[Path].toFile) | ||
158 | output.write(ujson.write(ujson.Arr(answers.map(_.toJSON)), indent = 4)) | ||
159 | output.close() | ||
160 | |||
147 | // Logger.print(s"$answers", Logger.VERBOSE) | 161 | // Logger.print(s"$answers", Logger.VERBOSE) |
148 | // Logger print s"Number of answers: ${answers.length} (${answers.lengthWithMultiplicity})" | 162 | // Logger print s"Number of answers: ${answers.length} (${answers.lengthWithMultiplicity})" |
149 | // Retrieve unfiltered answers | 163 | // Retrieve unfiltered answers |
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswers.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswers.scala index 3d16351..5b97679 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswers.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQueryAnswers.scala | |||
@@ -46,7 +46,7 @@ class ConjunctiveQueryAnswers( | |||
46 | val lengthWithMultiplicity: Long = answers.map(_._1).sum | 46 | val lengthWithMultiplicity: Long = answers.map(_._1).sum |
47 | 47 | ||
48 | /** Serialise answers as JSON file */ | 48 | /** Serialise answers as JSON file */ |
49 | def toJSON(): ujson.Js.Value = { | 49 | def toJSON(): ujson.Js.Value = |
50 | ujson.Obj( | 50 | ujson.Obj( |
51 | "queryID" -> query.id, | 51 | "queryID" -> query.id, |
52 | "queryText" -> query.toString | 52 | "queryText" -> query.toString |
@@ -56,7 +56,6 @@ class ConjunctiveQueryAnswers( | |||
56 | "answerVariables" -> ujson.Arr(query.answer.map(_.toString())), | 56 | "answerVariables" -> ujson.Arr(query.answer.map(_.toString())), |
57 | "answers" -> ujson.Arr(answers.map(_._2.mkString(" ")).sorted) | 57 | "answers" -> ujson.Arr(answers.map(_._2.mkString(" ")).sorted) |
58 | ) | 58 | ) |
59 | } | ||
60 | 59 | ||
61 | override def toString(): String = | 60 | override def toString(): String = |
62 | if (query.bcq) { | 61 | if (query.bcq) { |