aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/uk/ac/ox/cs/rsacomb/util
diff options
context:
space:
mode:
authorFederico Igne <git@federicoigne.com>2021-09-30 12:32:25 +0100
committerFederico Igne <git@federicoigne.com>2021-09-30 12:32:25 +0100
commit1ef8a2502532dd1736c1e3d6a1ff78ed6b8b643c (patch)
treeeb3471b39e10f667650dbb415eb5d366465fa0c8 /src/main/scala/uk/ac/ox/cs/rsacomb/util
parent95a2e9e85e1783e1bf2b50ae37bd9eab003a6ca8 (diff)
downloadRSAComb-1ef8a2502532dd1736c1e3d6a1ff78ed6b8b643c.tar.gz
RSAComb-1ef8a2502532dd1736c1e3d6a1ff78ed6b8b643c.zip
Refactor query answering to use named graphs
Diffstat (limited to 'src/main/scala/uk/ac/ox/cs/rsacomb/util')
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/util/RDFoxUtil.scala38
1 files changed, 21 insertions, 17 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 620d2dd..6f5ff31 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
@@ -124,13 +124,14 @@ object RDFoxUtil {
124 def addRules(data: DataStoreConnection, rules: Seq[Rule]): Unit = 124 def addRules(data: DataStoreConnection, rules: Seq[Rule]): Unit =
125 Logger.timed( 125 Logger.timed(
126 if (rules.length > 0) { 126 if (rules.length > 0) {
127 data.importData( 127 data addRules rules
128 UpdateType.ADDITION, 128 // data.importData(
129 RSA.Prefixes, 129 // UpdateType.ADDITION,
130 rules 130 // RSA.Prefixes,
131 .map(_.toString(Prefixes.s_emptyPrefixes)) 131 // rules
132 .mkString("\n") 132 // .map(_.toString(Prefixes.s_emptyPrefixes))
133 ) 133 // .mkString("\n")
134 // )
134 }, 135 },
135 s"Loading ${rules.length} rules", 136 s"Loading ${rules.length} rules",
136 Logger.DEBUG 137 Logger.DEBUG
@@ -141,10 +142,15 @@ object RDFoxUtil {
141 * @param data datastore connection 142 * @param data datastore connection
142 * @param facts collection of facts to be added to the data store 143 * @param facts collection of facts to be added to the data store
143 */ 144 */
144 def addFacts(data: DataStoreConnection, facts: Seq[TupleTableAtom]): Unit = 145 def addFacts(
146 graph: String,
147 data: DataStoreConnection,
148 facts: Seq[TupleTableAtom]
149 ): Unit =
145 Logger.timed( 150 Logger.timed(
146 if (facts.length > 0) { 151 if (facts.length > 0) {
147 data.importData( 152 data.importData(
153 graph,
148 UpdateType.ADDITION, 154 UpdateType.ADDITION,
149 RSA.Prefixes, 155 RSA.Prefixes,
150 facts 156 facts
@@ -161,14 +167,10 @@ object RDFoxUtil {
161 * @param data datastore connection. 167 * @param data datastore connection.
162 * @param files sequence of files to upload. 168 * @param files sequence of files to upload.
163 */ 169 */
164 def addData(data: DataStoreConnection, files: File*): Unit = 170 def addData(graph: String, data: DataStoreConnection, files: File*): Unit =
165 Logger.timed( 171 Logger.timed(
166 files.foreach { 172 files.foreach {
167 data.importData( 173 data.importData(graph, UpdateType.ADDITION, RSA.Prefixes, _)
168 UpdateType.ADDITION,
169 RSA.Prefixes,
170 _
171 )
172 }, 174 },
173 "Loading data files", 175 "Loading data files",
174 Logger.DEBUG 176 Logger.DEBUG
@@ -315,11 +317,13 @@ object RDFoxUtil {
315 * compatible with RDFox engine. This helper allows to build a query 317 * compatible with RDFox engine. This helper allows to build a query
316 * to gather all instances of an internal predicate 318 * to gather all instances of an internal predicate
317 * 319 *
320 * @param graph named graph to query for the provided predicate
318 * @param pred name of the predicate to describe. 321 * @param pred name of the predicate to describe.
319 * @param arity arity of the predicate. 322 * @param arity arity of the predicate.
320 * @return a string containing a SPARQL query. 323 * @return a string containing a SPARQL query.
321 */ 324 */
322 def buildDescriptionQuery( 325 def buildDescriptionQuery(
326 graph: String,
323 pred: String, 327 pred: String,
324 arity: Int 328 arity: Int
325 ): String = { 329 ): String = {
@@ -328,12 +332,12 @@ object RDFoxUtil {
328 s""" 332 s"""
329 SELECT $variables 333 SELECT $variables
330 WHERE { 334 WHERE {
331 ?K a rsa:$pred. 335 GRAPH <$graph> { ?K a rsa:$pred }.
332 TT <http://oxfordsemantic.tech/RDFox#SKOLEM> { $variables ?K } . 336 TT <http://oxfordsemantic.tech/RDFox#SKOLEM> { $variables ?K } .
333 } 337 }
334 """ 338 """
335 } else { 339 } else {
336 "ASK { ?X a rsa:Ans }" 340 s"ASK { GRAPH <$graph> { ?X a rsa:Ans } }"
337 } 341 }
338 } 342 }
339 343