aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala
diff options
context:
space:
mode:
authorFederico Igne <federico.igne@cs.ox.ac.uk>2021-04-09 12:48:17 +0100
committerFederico Igne <federico.igne@cs.ox.ac.uk>2021-04-09 12:48:17 +0100
commite6048bd85da50a8f40538b968fe7ac3b957fdd97 (patch)
treead893fdac19b84d0f1d8603527616a2c89dd54c6 /src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala
parent6f5c82982248e823f2dd6f9eaf87f552d1616ca4 (diff)
downloadRSAComb-e6048bd85da50a8f40538b968fe7ac3b957fdd97.tar.gz
RSAComb-e6048bd85da50a8f40538b968fe7ac3b957fdd97.zip
Streamline RSA approximation
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.scala100
1 files changed, 24 insertions, 76 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 2e7f586..ed491a9 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala
@@ -29,11 +29,9 @@ object RSAConfig {
29 -h | -? | --help 29 -h | -? | --help
30 print this help message 30 print this help message
31 31
32 --rsacheck-only
33 only perform the RSA check without performing any query answering.
34
35 -q <file> | --query <file> 32 -q <file> | --query <file>
36 path to a file containing a single SPARQL query 33 path to a file containing a single SPARQL query. If no query
34 is provided, only the approximation to RSA will be performed.
37 35
38 <ontology> 36 <ontology>
39 file containing the ontology 37 file containing the ontology
@@ -44,9 +42,7 @@ object RSAConfig {
44 """ 42 """
45 43
46 /** Default config values */ 44 /** Default config values */
47 private val default = Map( 45 private val default: Config = Map.empty
48 'rsacheckonly -> RSAOption[Boolean](false)
49 )
50 46
51 /** Utility to exit the program with a custom message on stderr. 47 /** Utility to exit the program with a custom message on stderr.
52 * 48 *
@@ -79,8 +75,6 @@ object RSAConfig {
79 println(help) 75 println(help)
80 sys.exit(0) 76 sys.exit(0)
81 } 77 }
82 case "--rsacheck-only" :: tail =>
83 parse(tail, config ++ Map('rsacheckonly -> true))
84 case flag @ ("-q" | "--query") :: _query :: tail => { 78 case flag @ ("-q" | "--query") :: _query :: tail => {
85 val query = new File(_query) 79 val query = new File(_query)
86 if (!query.isFile) 80 if (!query.isFile)
@@ -101,80 +95,34 @@ object RSAConfig {
101 } 95 }
102 96
103 /** Perform final checks on parsed options */ 97 /** Perform final checks on parsed options */
104 private def finalise(config: Config): Config = { 98 private def finalise(config: Config): Config = config
105 // Query file is mandatory unless only the RSA check is required.
106 if (!config('rsacheckonly).get[Boolean] && !config.contains('query))
107 exit(s"Query file was not provided.")
108
109 config
110 }
111} 99}
112 100
113/** Entry point of the program. 101/** Main entry point to the program */
114 *
115 * The executable expects a SPARQL query and a non-empty sequence of
116 * ontology files as arguments. The query file is expected to contain
117 * exactly one query, while the ontology files will be programmatically
118 * merged in a single ontology.
119 *
120 * @todo better arguments handling is needed. Look into some library
121 * for this.
122 * @todo at the moment the input ontology is assumed to be Horn-ALCHOIQ.
123 * This might not be the case.
124 */
125object RSAComb extends App { 102object RSAComb extends App {
126 103
104 /* Command-line options */
127 val config = RSAConfig.parse(args.toList) 105 val config = RSAConfig.parse(args.toList)
128 106
129 val ontology = 107 val ontology = RSAOntology(
130 RSAOntology(config('ontology).get[File], config('data).get[List[File]]: _*) 108 config('ontology).get[File],
131 109 config('data).get[List[File]]: _*
132 if (ontology.isRSA) { 110 )
133 111 val rsa = ontology.toRSA()
134 Logger print "Ontology is RSA!" 112 ontology.statistics()
135 113
136 if (!config('rsacheckonly).get[Boolean]) { 114 if (config contains 'query) {
137 val query = 115 val query =
138 RDFoxUtil.loadQueryFromFile(config('query).get[File].getAbsoluteFile) 116 RDFoxUtil.loadQueryFromFile(config('query).get[File].getAbsoluteFile)
139 117
140 ConjunctiveQuery.parse(query) match { 118 ConjunctiveQuery.parse(query) match {
141 case Some(query) => { 119 case Some(query) => {
142 val answers = ontology ask query 120 val answers = rsa ask query
143 //Logger.print(s"$answers", Logger.QUIET) 121 Logger.print(s"$answers", Logger.VERBOSE)
144 Logger print s"Number of answers: ${answers.length} (${answers.lengthWithMultiplicity})" 122 Logger print s"Number of answers: ${answers.length} (${answers.lengthWithMultiplicity})"
145
146 // /* Additional DEBUG information */
147 // if (Logger.level >= Logger.DEBUG) {
148 // /* Unfiltered rules */
149 // val unfiltered = ontology askUnfiltered query
150 // unfiltered map { u =>
151 // Logger print s"Number of unfiltered answers: ${u.length} (${u.map(_._1).sum})."
152
153 // /* Spurious answers */
154 // val spurious = {
155 // val variables = query.variables.length
156 // val sp = RDFoxUtil.buildDescriptionQuery("SP", variables)
157 // ontology.queryDataStore(query, sp, RSA.Prefixes)
158 // }
159 // spurious map { s =>
160 // Logger print s"Number of spurious answers: ${s.length} (${s.map(_._1).sum})"
161
162 // /* Spurious/unfiltered percentage */
163 // val perc =
164 // if (u.length > 0) (s.length / u.length.toFloat) * 100 else 0
165 // Logger print s"Percentage of spurious answers: $perc%"
166 // }
167 // }
168 // }
169 }
170 case None =>
171 throw new RuntimeException("Submitted query is not conjunctive")
172 } 123 }
124 case None =>
125 throw new RuntimeException("Submitted query is not conjunctive")
173 } 126 }
174
175 } else {
176
177 Logger print "Ontology is not RSA!"
178
179 } 127 }
180} 128}