aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/rsacomb/RDFoxUtil.scala
blob: 9be7a2dcca846fc9da209730c7ec7a76e08acac0 (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
package rsacomb

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

object RDFoxUtil {

  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("equality", "noUNA")
    server.createDataStore(dataStore, "seq", parameters)
    val data = server.newDataStoreConnection(dataStore)

    (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
  ): Unit = {
    server.close();
    data.close();
  }

} // object RDFox