From c782cacac113f3f0b7fe39add68382d82d2eca2c Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Mon, 17 Aug 2020 11:29:51 +0100 Subject: Automate query evaluation in RDFoxUtil --- src/main/scala/rsacomb/RDFoxUtil.scala | 22 ++++++++++++++++++++++ src/main/scala/rsacomb/RSAOntology.scala | 26 ++++++++++++-------------- 2 files changed, 34 insertions(+), 14 deletions(-) (limited to 'src') 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 /* Java imports */ import java.util.HashMap +import tech.oxfordsemantic.jrdfox.Prefixes import tech.oxfordsemantic.jrdfox.client.{ ConnectionFactory, ServerConnection, @@ -31,6 +32,27 @@ object RDFoxUtil { (server, data) } + def query( + data: DataStoreConnection, + prefixes: Prefixes, + query: String + ): Unit = { + println(s"\n{ $query }") + val cursor = data.createCursor( + prefixes, + query, + new HashMap[String, String]() + ); + var mul = cursor.open() + while (mul > 0) { + val res0 = cursor.getResource(0) + val res1 = cursor.getResource(1) + println(s"Answer: $res0 $res1") + mul = cursor.advance() + } + cursor.close(); + } + def closeConnection( server: ServerConnection, 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 { .asScala val unsafe = ontology.getUnsafeRoles - /* DEBUG: print rules in DL syntax */ + /* DEBUG: print rules in DL syntax and unsafe roles */ val renderer = new DLSyntaxObjectRenderer() println("\nDL rules:") tbox.foreach(x => println(renderer.render(x))) + println(s"Unsafe roles: $unsafe") /* Ontology convertion into LP rules */ val datalog = for { @@ -111,20 +112,17 @@ trait RSAOntology { ) // Retrieve all instances of PE - println("\nQuery results:") - val cursor = data.createCursor( + println("\nQueries:") + RDFoxUtil.query( + data, + prefixes, + "SELECT ?X ?Y WHERE { ?X ?Y }" + ) + RDFoxUtil.query( + data, prefixes, - "SELECT ?X ?Y WHERE { ?X ?Y }", - new HashMap[String, String]() - ); - var mul = cursor.open() - while (mul > 0) { - val res0 = cursor.getResource(0) - val res1 = cursor.getResource(1) - println(s"Answer: $res0 $res1") - mul = cursor.advance() - } - cursor.close(); + "SELECT ?X ?Y WHERE { ?X ?Y }" + ) // Close connection to RDFox RDFoxUtil.closeConnection(server, data) -- cgit v1.2.3