diff options
Diffstat (limited to 'src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala')
-rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | 50 |
1 files changed, 28 insertions, 22 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 22b1f76..24bda1f 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala | |||
@@ -88,6 +88,14 @@ object RSAConfig { | |||
88 | sys.exit(1) | 88 | sys.exit(1) |
89 | } | 89 | } |
90 | 90 | ||
91 | private def getPath(str: String): os.Path = | ||
92 | try { | ||
93 | os.Path(str, base = os.pwd) | ||
94 | } catch { | ||
95 | case e: IllegalArgumentException => | ||
96 | exit(s"'$str' is not a well formed path.") | ||
97 | } | ||
98 | |||
91 | /** Parse arguments with default options | 99 | /** Parse arguments with default options |
92 | * | 100 | * |
93 | * @param args arguments list | 101 | * @param args arguments list |
@@ -116,26 +124,20 @@ object RSAConfig { | |||
116 | } | 124 | } |
117 | parse(tail, config += ('logger -> level)) | 125 | parse(tail, config += ('logger -> level)) |
118 | } | 126 | } |
119 | case flag @ ("-o" | "--output") :: _output :: tail => | 127 | case flag @ ("-o" | "--output") :: output :: tail => |
120 | try { | 128 | parse(tail, config += ('output -> getPath(output))) |
121 | val output = Paths.get(_output) | ||
122 | parse(tail, config += ('output -> output)) | ||
123 | } catch { | ||
124 | case e: InvalidPathException => | ||
125 | exit(s"'${_output}' is not a valid filename.") | ||
126 | } | ||
127 | case flag @ ("-q" | "--queries") :: _query :: tail => { | 129 | case flag @ ("-q" | "--queries") :: _query :: tail => { |
128 | val query = new File(_query) | 130 | val query = getPath(_query) |
129 | if (!query.isFile) | 131 | if (!os.isFile(query)) |
130 | exit(s"'$query' is not a valid filename.") | 132 | exit(s"'${_query}' is not a valid filename.") |
131 | parse(tail, config += ('queries -> query)) | 133 | parse(tail, config += ('queries -> query)) |
132 | } | 134 | } |
133 | case _ontology :: _data => { | 135 | case _ontology :: _data => { |
134 | val ontology = new File(_ontology) | 136 | val ontology = getPath(_ontology) |
135 | val data = _data.map(new File(_)) | 137 | val data = _data map getPath |
136 | (ontology :: data) foreach { (file) => | 138 | (ontology :: data) foreach { (path) => |
137 | if (!file.isFile) | 139 | if (!os.isFile(path)) |
138 | exit(s"'$file' is not a valid filename.") | 140 | exit(s"'$path' is not a valid filename.") |
139 | } | 141 | } |
140 | finalise(config += ('ontology -> ontology) += ('data -> data)) | 142 | finalise(config += ('ontology -> ontology) += ('data -> data)) |
141 | } | 143 | } |
@@ -156,8 +158,8 @@ object RSAComb extends App { | |||
156 | 158 | ||
157 | /* Load original ontology and normalize it */ | 159 | /* Load original ontology and normalize it */ |
158 | val ontology = Ontology( | 160 | val ontology = Ontology( |
159 | config('ontology).get[File], | 161 | config('ontology).get[os.Path], |
160 | config('data).get[List[File]] | 162 | config('data).get[List[os.Path]] |
161 | ).normalize(new Normalizer) | 163 | ).normalize(new Normalizer) |
162 | 164 | ||
163 | //ontology.axioms foreach println | 165 | //ontology.axioms foreach println |
@@ -168,14 +170,18 @@ object RSAComb extends App { | |||
168 | 170 | ||
169 | if (config contains 'queries) { | 171 | if (config contains 'queries) { |
170 | val queries = | 172 | val queries = |
171 | RDFoxUtil.loadQueriesFromFile(config('queries).get[File].getAbsoluteFile) | 173 | RDFoxUtil.loadQueriesFromFile( |
174 | config('queries).get[os.Path] | ||
175 | ) | ||
172 | 176 | ||
173 | val answers = rsa ask queries | 177 | val answers = rsa ask queries |
174 | 178 | ||
175 | /* Write answers to output file */ | 179 | /* Write answers to output file */ |
176 | val output = new PrintWriter(config('output).get[Path].toFile) | 180 | os.write( |
177 | output.write(ujson.write(ujson.Arr(answers.map(_.toJSON)), indent = 4)) | 181 | config('output).get[os.Path], |
178 | output.close() | 182 | ujson.write(ujson.Arr(answers.map(_.toJSON)), indent = 4), |
183 | createFolders = true | ||
184 | ) | ||
179 | 185 | ||
180 | // Logger.print(s"$answers", Logger.VERBOSE) | 186 | // Logger.print(s"$answers", Logger.VERBOSE) |
181 | // Logger print s"Number of answers: ${answers.length} (${answers.lengthWithMultiplicity})" | 187 | // Logger print s"Number of answers: ${answers.length} (${answers.lengthWithMultiplicity})" |