aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/rsacomb/RDFoxUtil.scala
blob: d5a4dbbd7590f442abeb736e6d31a32675fde53d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package rsacomb

/* Java imports */
import java.util.HashMap
import tech.oxfordsemantic.jrdfox.Prefixes
import tech.oxfordsemantic.jrdfox.logic.IRI
import tech.oxfordsemantic.jrdfox.client.{
  ConnectionFactory,
  ServerConnection,
  DataStoreConnection
}
object RDFoxUtil {

  implicit def owlapi2rdfox(iri: org.semanticweb.owlapi.model.IRI): IRI = {
    IRI.create(iri.getIRIString())
  }

  implicit def owlapi2rdfox(iri: String): IRI = {
    IRI.create(iri)
  }

  def openConnection(
      dataStore: String
  ): (ServerConnection, DataStoreConnection) = {
    /* Create local server connection
     */
    val serverUrl = "rdfox:local"
    val role = ""
    val password = ""
    val server =
      ConnectionFactory.newServerConnection(serverUrl, role, password)

    /* Create datastore connection
     */
    val parameters = new HashMap[String, String]()
    parameters.put("owl-in-rdf-support", "relaxed")
    //parameters.put("equality", "noUNA")
    server.createDataStore(dataStore, "par-complex-nn", parameters)
    val data = server.newDataStoreConnection(dataStore)

    (server, data)
  }

  def submitQuery(
      data: DataStoreConnection,
      prefixes: Prefixes,
      query: String,
      answers: Int
  ): Unit = {
    println(s"\nQUERY { $query }")
    val cursor = data.createCursor(
      prefixes,
      query,
      new HashMap[String, String]()
    );
    var mul = cursor.open()
    while (mul > 0) {
      print("Answer: ")
      for (i <- 0 until answers) {
        val res = cursor.getResource(i)
        print(s"$res ")
      }
      println()
      mul = cursor.advance()
    }
    cursor.close();
    println(s"QUERY END")
  }

  def closeConnection(
      server: ServerConnection,
      data: DataStoreConnection
  ): Unit = {
    server.close();
    data.close();
  }

} // object RDFoxUtil