aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala
blob: c7ace0fcc5bf9fe36ea852c57b31eaff4edcf3c4 (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
package uk.ac.ox.cs.rsacomb

/* Java imports */
import java.io.File
import java.util.HashMap
import scala.collection.JavaConverters._

import tech.oxfordsemantic.jrdfox.client.UpdateType
import tech.oxfordsemantic.jrdfox.logic.sparql.statement.SelectQuery
import tech.oxfordsemantic.jrdfox.logic.expression.{IRI, Term}

/* Local imports */
import util.{RDFoxUtil, RSA}
import sparql.ConjunctiveQuery

object RSAComb extends App {

  val help: String = """
  rsacomb - combined approach for CQ answering for RSA ontologies.

  USAGE
    rsacomb <query> <ontology> ...

  where
    - query: a (single) SPARQL query file.
    - ontology: one or more ontologies.

  """

  /* Simple arguments handling
   *
   * TODO: use something better later on
   */

  if (args.length < 2) {
    println(help)
    sys.exit;
  }

  val queryPath = new File(args(0))
  val ontoPaths = args.drop(1).map(new File(_))

  if (!queryPath.isFile || !ontoPaths.forall(_.isFile)) {
    println("The provided arguments are not regular files.\n\n")
    println(help)
    sys.exit;
  }

  /* TODO: It might be required to check if the ontology in input is
   * Horn-ALCHOIQ. At the moment we are assuming this is always the
   * case.
   */

  val ontology = RSAOntology(ontoPaths: _*)
  if (ontology.isRSA) {
    //println("ONTOLOGY IS RSA")

    /** Read SPARQL query from file */
    val source = io.Source.fromFile(queryPath.getAbsoluteFile)
    val query = source.getLines mkString "\n"
    source.close()

    /* Compute answers to query */
    val answers = ConjunctiveQuery.parse(query).map(ontology ask _)
    answers map (_.toString) foreach println
  }
}