diff options
| author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-11-18 18:07:53 +0000 |
|---|---|---|
| committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2020-11-18 18:07:53 +0000 |
| commit | 4df351d3b1d11fc045005323c38ba3528de631ea (patch) | |
| tree | 35f809e3def7d55602ed124f7b194db29407ba33 /src/main/scala/rsacomb/RDFoxUtil.scala | |
| parent | e1a04294ed8737444e40323474f4084cb64c1d55 (diff) | |
| download | RSAComb-4df351d3b1d11fc045005323c38ba3528de631ea.tar.gz RSAComb-4df351d3b1d11fc045005323c38ba3528de631ea.zip | |
Rework RSA as a utility object
Diffstat (limited to 'src/main/scala/rsacomb/RDFoxUtil.scala')
| -rw-r--r-- | src/main/scala/rsacomb/RDFoxUtil.scala | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/src/main/scala/rsacomb/RDFoxUtil.scala b/src/main/scala/rsacomb/RDFoxUtil.scala deleted file mode 100644 index 653c51f..0000000 --- a/src/main/scala/rsacomb/RDFoxUtil.scala +++ /dev/null | |||
| @@ -1,113 +0,0 @@ | |||
| 1 | package rsacomb | ||
| 2 | |||
| 3 | /* Java imports */ | ||
| 4 | import java.util.HashMap | ||
| 5 | import java.io.StringReader | ||
| 6 | import tech.oxfordsemantic.jrdfox.Prefixes | ||
| 7 | import tech.oxfordsemantic.jrdfox.logic.sparql.statement.{Query, SelectQuery} | ||
| 8 | import tech.oxfordsemantic.jrdfox.client.{ | ||
| 9 | ConnectionFactory, | ||
| 10 | ServerConnection, | ||
| 11 | DataStoreConnection | ||
| 12 | } | ||
| 13 | import tech.oxfordsemantic.jrdfox.formats.SPARQLParser | ||
| 14 | |||
| 15 | import tech.oxfordsemantic.jrdfox.logic.expression.{IRI => RDFox_IRI} | ||
| 16 | import org.semanticweb.owlapi.model.{IRI => OWL_IRI} | ||
| 17 | |||
| 18 | import scala.collection.JavaConverters._ | ||
| 19 | |||
| 20 | object RDFoxUtil { | ||
| 21 | |||
| 22 | implicit def rdfox2owlapi(iri: RDFox_IRI): OWL_IRI = { | ||
| 23 | OWL_IRI.create(iri.getIRI) | ||
| 24 | } | ||
| 25 | |||
| 26 | implicit def owlapi2rdfox(iri: OWL_IRI): RDFox_IRI = { | ||
| 27 | RDFox_IRI.create(iri.getIRIString()) | ||
| 28 | } | ||
| 29 | |||
| 30 | implicit def stringToRDFoxIRI(iri: String): RDFox_IRI = { | ||
| 31 | RDFox_IRI.create(iri) | ||
| 32 | } | ||
| 33 | |||
| 34 | implicit def javaToScalaList[A](list: java.util.List[A]): List[A] = { | ||
| 35 | list.asScala.toList | ||
| 36 | } | ||
| 37 | |||
| 38 | implicit def scalaToJavaList[A](list: List[A]): java.util.List[A] = { | ||
| 39 | list.asJava | ||
| 40 | } | ||
| 41 | |||
| 42 | def openConnection( | ||
| 43 | dataStore: String | ||
| 44 | ): (ServerConnection, DataStoreConnection) = { | ||
| 45 | /* Create local server connection | ||
| 46 | */ | ||
| 47 | val serverUrl = "rdfox:local" | ||
| 48 | val role = "" | ||
| 49 | val password = "" | ||
| 50 | val server = | ||
| 51 | ConnectionFactory.newServerConnection(serverUrl, role, password) | ||
| 52 | |||
| 53 | /* Create datastore connection | ||
| 54 | */ | ||
| 55 | val parameters = new HashMap[String, String]() | ||
| 56 | parameters.put("owl-in-rdf-support", "relaxed") | ||
| 57 | //parameters.put("equality", "noUNA") | ||
| 58 | server.createDataStore(dataStore, "par-complex-nn", parameters) | ||
| 59 | val data = server.newDataStoreConnection(dataStore) | ||
| 60 | |||
| 61 | (server, data) | ||
| 62 | } | ||
| 63 | |||
| 64 | def parseQuery( | ||
| 65 | query: String, | ||
| 66 | prefixes: Prefixes = RSA.Prefixes | ||
| 67 | ): Option[SelectQuery] = { | ||
| 68 | val parser = new SPARQLParser( | ||
| 69 | prefixes, | ||
| 70 | new StringReader(query) | ||
| 71 | ) | ||
| 72 | // NOTE: return only conjunctive queries for now (SelectQuery) | ||
| 73 | parser.parseSingleQuery() match { | ||
| 74 | case q: SelectQuery => Some(q) | ||
| 75 | case _ => None | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | def submitQuery( | ||
| 80 | data: DataStoreConnection, | ||
| 81 | prefixes: Prefixes, | ||
| 82 | query: String, | ||
| 83 | answers: Int | ||
| 84 | ): Unit = { | ||
| 85 | println(s"\nQUERY {\n$query\n}") | ||
| 86 | val cursor = data.createCursor( | ||
| 87 | prefixes, | ||
| 88 | query, | ||
| 89 | new HashMap[String, String]() | ||
| 90 | ); | ||
| 91 | var mul = cursor.open() | ||
| 92 | while (mul > 0) { | ||
| 93 | print("Answer: ") | ||
| 94 | for (i <- 0 until answers) { | ||
| 95 | val res = cursor.getResource(i) | ||
| 96 | print(s"$res ") | ||
| 97 | } | ||
| 98 | println() | ||
| 99 | mul = cursor.advance() | ||
| 100 | } | ||
| 101 | cursor.close(); | ||
| 102 | println(s"QUERY END") | ||
| 103 | } | ||
| 104 | |||
| 105 | def closeConnection( | ||
| 106 | server: ServerConnection, | ||
| 107 | data: DataStoreConnection | ||
| 108 | ): Unit = { | ||
| 109 | server.close(); | ||
| 110 | data.close(); | ||
| 111 | } | ||
| 112 | |||
| 113 | } // object RDFoxUtil | ||
