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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
/*
* Copyright 2021,2022 KRR Oxford
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package uk.ac.ox.cs.acqua.reasoner
import java.util.Collection;
import scala.collection.JavaConverters._
import org.semanticweb.owlapi.model.OWLOntology
import uk.ac.ox.cs.rsacomb.approximation.{Approximation,Lowerbound}
import uk.ac.ox.cs.rsacomb.ontology.{Ontology,RSAOntology}
import uk.ac.ox.cs.pagoda.query.QueryRecord
import uk.ac.ox.cs.pagoda.reasoner.QueryReasoner
import uk.ac.ox.cs.acqua.approximation.Noop
class RSACombQueryReasoner(
val origin: Ontology,
val toRSA: Approximation[RSAOntology] = Noop
) extends QueryReasoner {
/* Implicit compatibility between PAGOdA and RSAComb types */
import uk.ac.ox.cs.acqua.implicits.PagodaConverters._
val rsa: RSAOntology = origin approximate toRSA
/** Doesn't perform any action.
*
* @note Implemented for compatibility with other reasoners.
*/
def loadOntology(ontology: OWLOntology): Unit = {
/* Nothing to do */
}
/** Force computation of canonical model for combined approach in RSA.
*
* @returns whether the original ontolgy is RSA.
*
* @note that it is not necessary to call this method since the
* preprocessing is performed "on demand" when evaluating a query.
*/
def preprocess(): Boolean = {
rsa.computeCanonicalModel()
origin.isRSA
}
/** Check consistency and returns whether the ontology is RSA.
*
* Preprocessing is performed on instance creation, along with
* consistency checking, so no actual work is being done here.
*
* @note Implemented for compatibility with other reasoners.
*/
def isConsistent(): Boolean = {
origin.isRSA
}
/** Evaluates a collection of queries.
*
* Uses RSAComb internally to reuse part of the computation of
* multiple calls to [[uk.ac.ox.cs.rsacomb.RSAOntology.ask]].
*
* TODO: perform logging of answers
*/
//override def evaluate(queries: Collection[QueryRecord]): Unit = {
// val answers = rsa ask queries
// /* Perform logging */
// // Logger write answers
// // Logger.generateSimulationScripts(datapath, queries)
//}
/** Evaluates a single query.
*
* Uses RSAComb internally to reuse part of the computation of
* multiple calls to [[uk.ac.ox.cs.rsacomb.RSAOntology.ask]].
*
* TODO: perform logging of answers
*/
def evaluate(query: QueryRecord): Unit = {
import uk.ac.ox.cs.acqua.implicits.RSACombAnswerTuples._
val answers = rsa ask query
query updateLowerBoundAnswers answers
if (toRSA == Noop) {
/* Perform logging
* In this case the engine is used as a standalone engine, meaning
* that it is time to print out query answers and other related
* logging routines.
*/
//Logger write answers
//Logger.generateSimulationScripts(datapath, queries)
}
}
/** Evaluates a single query.
*
* Uses RSAComb internally to reuse part of the computation of
* multiple calls to [[uk.ac.ox.cs.rsacomb.RSAOntology.ask]].
*
* @note the result of the computation is saved in the "upper bound"
* of the input query record.
*
* TODO: perform logging of answers
*/
def evaluateUpper(query: QueryRecord): Unit = {
import uk.ac.ox.cs.acqua.implicits.RSACombAnswerTuples._
val answers = rsa ask query
query updateUpperBoundAnswers answers
if (toRSA == Noop) {
/* Perform logging
* In this case the engine is used as a standalone engine, meaning
* that it is time to print out query answers and other related
* logging routines.
*/
//Logger write answers
//Logger.generateSimulationScripts(datapath, queries)
}
}
}
|