diff options
author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-08-17 11:29:51 +0100 |
---|---|---|
committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-08-17 11:29:51 +0100 |
commit | c782cacac113f3f0b7fe39add68382d82d2eca2c (patch) | |
tree | b51d71721ef353a2767ef88b24a897dd402bf8a8 /src | |
parent | 4df0005e2b56a8d37ce449774aea2ab8c2808bcb (diff) | |
download | RSAComb-c782cacac113f3f0b7fe39add68382d82d2eca2c.tar.gz RSAComb-c782cacac113f3f0b7fe39add68382d82d2eca2c.zip |
Automate query evaluation in RDFoxUtil
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala/rsacomb/RDFoxUtil.scala | 22 | ||||
-rw-r--r-- | src/main/scala/rsacomb/RSAOntology.scala | 26 |
2 files changed, 34 insertions, 14 deletions
diff --git a/src/main/scala/rsacomb/RDFoxUtil.scala b/src/main/scala/rsacomb/RDFoxUtil.scala index 96710c4..9be7a2d 100644 --- a/src/main/scala/rsacomb/RDFoxUtil.scala +++ b/src/main/scala/rsacomb/RDFoxUtil.scala | |||
@@ -2,6 +2,7 @@ package rsacomb | |||
2 | 2 | ||
3 | /* Java imports */ | 3 | /* Java imports */ |
4 | import java.util.HashMap | 4 | import java.util.HashMap |
5 | import tech.oxfordsemantic.jrdfox.Prefixes | ||
5 | import tech.oxfordsemantic.jrdfox.client.{ | 6 | import tech.oxfordsemantic.jrdfox.client.{ |
6 | ConnectionFactory, | 7 | ConnectionFactory, |
7 | ServerConnection, | 8 | ServerConnection, |
@@ -31,6 +32,27 @@ object RDFoxUtil { | |||
31 | (server, data) | 32 | (server, data) |
32 | } | 33 | } |
33 | 34 | ||
35 | def query( | ||
36 | data: DataStoreConnection, | ||
37 | prefixes: Prefixes, | ||
38 | query: String | ||
39 | ): Unit = { | ||
40 | println(s"\n{ $query }") | ||
41 | val cursor = data.createCursor( | ||
42 | prefixes, | ||
43 | query, | ||
44 | new HashMap[String, String]() | ||
45 | ); | ||
46 | var mul = cursor.open() | ||
47 | while (mul > 0) { | ||
48 | val res0 = cursor.getResource(0) | ||
49 | val res1 = cursor.getResource(1) | ||
50 | println(s"Answer: $res0 $res1") | ||
51 | mul = cursor.advance() | ||
52 | } | ||
53 | cursor.close(); | ||
54 | } | ||
55 | |||
34 | def closeConnection( | 56 | def closeConnection( |
35 | server: ServerConnection, | 57 | server: ServerConnection, |
36 | data: DataStoreConnection | 58 | data: DataStoreConnection |
diff --git a/src/main/scala/rsacomb/RSAOntology.scala b/src/main/scala/rsacomb/RSAOntology.scala index 8303dd4..a3c1843 100644 --- a/src/main/scala/rsacomb/RSAOntology.scala +++ b/src/main/scala/rsacomb/RSAOntology.scala | |||
@@ -51,10 +51,11 @@ trait RSAOntology { | |||
51 | .asScala | 51 | .asScala |
52 | val unsafe = ontology.getUnsafeRoles | 52 | val unsafe = ontology.getUnsafeRoles |
53 | 53 | ||
54 | /* DEBUG: print rules in DL syntax */ | 54 | /* DEBUG: print rules in DL syntax and unsafe roles */ |
55 | val renderer = new DLSyntaxObjectRenderer() | 55 | val renderer = new DLSyntaxObjectRenderer() |
56 | println("\nDL rules:") | 56 | println("\nDL rules:") |
57 | tbox.foreach(x => println(renderer.render(x))) | 57 | tbox.foreach(x => println(renderer.render(x))) |
58 | println(s"Unsafe roles: $unsafe") | ||
58 | 59 | ||
59 | /* Ontology convertion into LP rules */ | 60 | /* Ontology convertion into LP rules */ |
60 | val datalog = for { | 61 | val datalog = for { |
@@ -111,20 +112,17 @@ trait RSAOntology { | |||
111 | ) | 112 | ) |
112 | 113 | ||
113 | // Retrieve all instances of PE | 114 | // Retrieve all instances of PE |
114 | println("\nQuery results:") | 115 | println("\nQueries:") |
115 | val cursor = data.createCursor( | 116 | RDFoxUtil.query( |
117 | data, | ||
118 | prefixes, | ||
119 | "SELECT ?X ?Y WHERE { ?X <internal:PE> ?Y }" | ||
120 | ) | ||
121 | RDFoxUtil.query( | ||
122 | data, | ||
116 | prefixes, | 123 | prefixes, |
117 | "SELECT ?X ?Y WHERE { ?X <internal:PE> ?Y }", | 124 | "SELECT ?X ?Y WHERE { ?X <internal:E> ?Y }" |
118 | new HashMap[String, String]() | 125 | ) |
119 | ); | ||
120 | var mul = cursor.open() | ||
121 | while (mul > 0) { | ||
122 | val res0 = cursor.getResource(0) | ||
123 | val res1 = cursor.getResource(1) | ||
124 | println(s"Answer: $res0 $res1") | ||
125 | mul = cursor.advance() | ||
126 | } | ||
127 | cursor.close(); | ||
128 | 126 | ||
129 | // Close connection to RDFox | 127 | // Close connection to RDFox |
130 | RDFoxUtil.closeConnection(server, data) | 128 | RDFoxUtil.closeConnection(server, data) |