diff options
Diffstat (limited to 'src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala')
-rw-r--r-- | src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | 64 |
1 files changed, 45 insertions, 19 deletions
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala index 6e9a119..5a89bf9 100644 --- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala +++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala | |||
@@ -48,6 +48,7 @@ import tech.oxfordsemantic.jrdfox.Prefixes | |||
48 | import tech.oxfordsemantic.jrdfox.logic.datalog.{ | 48 | import tech.oxfordsemantic.jrdfox.logic.datalog.{ |
49 | Rule, | 49 | Rule, |
50 | TupleTableAtom, | 50 | TupleTableAtom, |
51 | TupleTableName, | ||
51 | Negation, | 52 | Negation, |
52 | BodyFormula | 53 | BodyFormula |
53 | } | 54 | } |
@@ -91,6 +92,20 @@ object RSAOntology { | |||
91 | /** Name of the RDFox data store used for CQ answering */ | 92 | /** Name of the RDFox data store used for CQ answering */ |
92 | private val DataStore = "answer_computation" | 93 | private val DataStore = "answer_computation" |
93 | 94 | ||
95 | /** Canonical model named graph */ | ||
96 | private val CanonGraph: IRI = | ||
97 | RDFoxUtil.getNamedGraph(DataStore, "CanonicalModel") | ||
98 | |||
99 | /** Filtering program named graph | ||
100 | * | ||
101 | * @param query query associated with the returned named graph. | ||
102 | * | ||
103 | * @return named graph for the filtering program associated with the | ||
104 | * input query. | ||
105 | */ | ||
106 | private def FilterGraph(query: ConjunctiveQuery): IRI = | ||
107 | RDFoxUtil.getNamedGraph(DataStore, s"Filter${query.id}") | ||
108 | |||
94 | /** Filtering program for a given query | 109 | /** Filtering program for a given query |
95 | * | 110 | * |
96 | * @param query the query to derive the filtering program | 111 | * @param query the query to derive the filtering program |
@@ -343,11 +358,12 @@ class RSAOntology(axioms: List[OWLLogicalAxiom], datafiles: List[File]) | |||
343 | private val topAxioms: List[Rule] = { | 358 | private val topAxioms: List[Rule] = { |
344 | val varX = Variable.create("X") | 359 | val varX = Variable.create("X") |
345 | val varY = Variable.create("Y") | 360 | val varY = Variable.create("Y") |
361 | val graph = TupleTableName.create(RSAOntology.CanonGraph.getIRI) | ||
346 | concepts | 362 | concepts |
347 | .map(c => { | 363 | .map(c => { |
348 | Rule.create( | 364 | Rule.create( |
349 | RSA.Thing(varX), | 365 | TupleTableAtom.create(graph, varX, IRI.RDF_TYPE, IRI.THING), |
350 | TupleTableAtom.rdf(varX, IRI.RDF_TYPE, c.getIRI) | 366 | TupleTableAtom.create(graph, varX, IRI.RDF_TYPE, c.getIRI) |
351 | ) | 367 | ) |
352 | }) ++ roles.map(r => { | 368 | }) ++ roles.map(r => { |
353 | val name = r match { | 369 | val name = r match { |
@@ -356,8 +372,11 @@ class RSAOntology(axioms: List[OWLLogicalAxiom], datafiles: List[File]) | |||
356 | x.getInverse.getNamedProperty.getIRI.getIRIString :: Inverse | 372 | x.getInverse.getNamedProperty.getIRI.getIRIString :: Inverse |
357 | } | 373 | } |
358 | Rule.create( | 374 | Rule.create( |
359 | List(RSA.Thing(varX), RSA.Thing(varY)), | 375 | List( |
360 | List(TupleTableAtom.rdf(varX, name, varY)) | 376 | TupleTableAtom.create(graph, varX, IRI.RDF_TYPE, IRI.THING), |
377 | TupleTableAtom.create(graph, varY, IRI.RDF_TYPE, IRI.THING) | ||
378 | ), | ||
379 | List(TupleTableAtom.create(graph, varX, name, varY)) | ||
361 | ) | 380 | ) |
362 | }) | 381 | }) |
363 | } | 382 | } |
@@ -382,23 +401,31 @@ class RSAOntology(axioms: List[OWLLogicalAxiom], datafiles: List[File]) | |||
382 | val varX = Variable.create("X") | 401 | val varX = Variable.create("X") |
383 | val varY = Variable.create("Y") | 402 | val varY = Variable.create("Y") |
384 | val varZ = Variable.create("Z") | 403 | val varZ = Variable.create("Z") |
385 | List( | 404 | val graph = TupleTableName.create(RSAOntology.CanonGraph.getIRI) |
405 | // Equality properties | ||
406 | val properties = List( | ||
386 | // Reflexivity | 407 | // Reflexivity |
387 | Rule.create(RSA.Congruent(varX, varX), RSA.Thing(varX)), | 408 | Rule.create( |
409 | TupleTableAtom.create(graph, varX, RSA.CONGRUENT, varX), | ||
410 | TupleTableAtom.create(graph, varX, IRI.RDF_TYPE, IRI.THING) | ||
411 | ), | ||
388 | // Simmetry | 412 | // Simmetry |
389 | Rule.create(RSA.Congruent(varY, varX), RSA.Congruent(varX, varY)), | 413 | Rule.create( |
414 | TupleTableAtom.create(graph, varY, RSA.CONGRUENT, varX), | ||
415 | TupleTableAtom.create(graph, varX, RSA.CONGRUENT, varY) | ||
416 | ), | ||
390 | // Transitivity | 417 | // Transitivity |
391 | Rule.create( | 418 | Rule.create( |
392 | RSA.Congruent(varX, varZ), | 419 | TupleTableAtom.create(graph, varX, RSA.CONGRUENT, varZ), |
393 | RSA.Congruent(varX, varY), | 420 | TupleTableAtom.create(graph, varX, RSA.CONGRUENT, varY), |
394 | RSA.Congruent(varY, varZ) | 421 | TupleTableAtom.create(graph, varY, RSA.CONGRUENT, varZ) |
395 | ) | 422 | ) |
396 | ) | 423 | ) |
397 | } | 424 | } |
398 | 425 | ||
399 | /** Canonical model of the ontology */ | 426 | /** Canonical model of the ontology */ |
400 | lazy val canonicalModel = Logger.timed( | 427 | lazy val canonicalModel = Logger.timed( |
401 | new CanonicalModel(this), | 428 | new CanonicalModel(this, RSAOntology.CanonGraph), |
402 | "Generating canonical model program", | 429 | "Generating canonical model program", |
403 | Logger.DEBUG | 430 | Logger.DEBUG |
404 | ) | 431 | ) |
@@ -505,19 +532,18 @@ class RSAOntology(axioms: List[OWLLogicalAxiom], datafiles: List[File]) | |||
505 | * @return a collection of answers for each query. | 532 | * @return a collection of answers for each query. |
506 | */ | 533 | */ |
507 | def ask(queries: Seq[ConjunctiveQuery]): Seq[ConjunctiveQueryAnswers] = { | 534 | def ask(queries: Seq[ConjunctiveQuery]): Seq[ConjunctiveQueryAnswers] = { |
535 | /* Open connection with RDFox server */ | ||
508 | val (server, data) = RDFoxUtil.openConnection(RSAOntology.DataStore) | 536 | val (server, data) = RDFoxUtil.openConnection(RSAOntology.DataStore) |
509 | val canonNamedGraph = "http://cs.ox.ac.uk/isg/RSAComb#CanonicalModel" | ||
510 | // Create a new NamedGraph for the canonical model | ||
511 | data.createTupleTable(canonNamedGraph, Map("type" -> "named-graph").asJava) | ||
512 | 537 | ||
513 | /* Upload data from data file */ | 538 | /* Upload data from data file */ |
514 | RDFoxUtil.addData(canonNamedGraph, data, datafiles: _*) | 539 | RDFoxUtil.addData(data, RSAOntology.CanonGraph, datafiles: _*) |
515 | /* Top / equality axiomatization */ | 540 | /* Top / equality axiomatization */ |
516 | RDFoxUtil.addRules(data, topAxioms ++ equalityAxioms) | 541 | RDFoxUtil.addRules(data, topAxioms ++ equalityAxioms) |
517 | /* Generate `named` predicates */ | 542 | /* Generate `named` predicates */ |
543 | // TODO: do I need both to generate all NAMED atoms? | ||
518 | RDFoxUtil.addFacts( | 544 | RDFoxUtil.addFacts( |
519 | canonNamedGraph, | ||
520 | data, | 545 | data, |
546 | RSAOntology.CanonGraph, | ||
521 | (individuals ++ literals) map RSA.Named | 547 | (individuals ++ literals) map RSA.Named |
522 | ) | 548 | ) |
523 | data.evaluateUpdate( | 549 | data.evaluateUpdate( |
@@ -525,9 +551,9 @@ class RSAOntology(axioms: List[OWLLogicalAxiom], datafiles: List[File]) | |||
525 | RSA.Prefixes, | 551 | RSA.Prefixes, |
526 | s""" | 552 | s""" |
527 | INSERT { | 553 | INSERT { |
528 | GRAPH <$canonNamedGraph> { ?X a rsa:Named } | 554 | GRAPH ${RSAOntology.CanonGraph} { ?X a ${RSA.NAMED} } |
529 | } WHERE { | 555 | } WHERE { |
530 | GRAPH <$canonNamedGraph> { ?X a owl:Thing } | 556 | GRAPH ${RSAOntology.CanonGraph} { ?X a ${IRI.THING} } |
531 | } | 557 | } |
532 | """, | 558 | """, |
533 | new java.util.HashMap[String, String] | 559 | new java.util.HashMap[String, String] |
@@ -538,7 +564,7 @@ class RSAOntology(axioms: List[OWLLogicalAxiom], datafiles: List[File]) | |||
538 | RDFoxUtil.addRules(data, this.canonicalModel.rules) | 564 | RDFoxUtil.addRules(data, this.canonicalModel.rules) |
539 | 565 | ||
540 | Logger print s"Canonical model facts: ${this.canonicalModel.facts.length}" | 566 | Logger print s"Canonical model facts: ${this.canonicalModel.facts.length}" |
541 | RDFoxUtil.addFacts(canonNamedGraph, data, this.canonicalModel.facts) | 567 | RDFoxUtil.addFacts(data, RSAOntology.CanonGraph, this.canonicalModel.facts) |
542 | 568 | ||
543 | queries map { query => | 569 | queries map { query => |
544 | { | 570 | { |