1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.kernel.bo.logic.model; |
17 |
|
|
18 |
|
import java.util.ArrayList; |
19 |
|
import java.util.List; |
20 |
|
|
21 |
|
import org.qedeq.base.trace.Trace; |
22 |
|
import org.qedeq.kernel.bo.logic.common.FunctionConstant; |
23 |
|
import org.qedeq.kernel.bo.logic.common.FunctionKey; |
24 |
|
import org.qedeq.kernel.bo.logic.common.Operators; |
25 |
|
import org.qedeq.kernel.bo.logic.common.PredicateConstant; |
26 |
|
import org.qedeq.kernel.bo.logic.common.PredicateKey; |
27 |
|
import org.qedeq.kernel.bo.logic.common.SubjectVariable; |
28 |
|
import org.qedeq.kernel.bo.module.KernelQedeqBo; |
29 |
|
import org.qedeq.kernel.bo.service.unicode.Latex2UnicodeParser; |
30 |
|
import org.qedeq.kernel.se.base.list.Element; |
31 |
|
import org.qedeq.kernel.se.base.list.ElementList; |
32 |
|
import org.qedeq.kernel.se.common.ModuleContext; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
@author |
39 |
|
|
|
|
| 76.6% |
Uncovered Elements: 112 (479) |
Complexity: 97 |
Complexity Density: 0.3 |
|
40 |
|
public class DynamicDirectInterpreter { |
41 |
|
|
42 |
|
|
43 |
|
private static final Class CLASS = DynamicDirectInterpreter.class; |
44 |
|
|
45 |
|
|
46 |
|
private KernelQedeqBo qedeq; |
47 |
|
|
48 |
|
|
49 |
|
private ModuleContext moduleContext; |
50 |
|
|
51 |
|
|
52 |
|
private final StringBuffer deepness = new StringBuffer(); |
53 |
|
|
54 |
|
|
55 |
|
private final DynamicModel model; |
56 |
|
|
57 |
|
|
58 |
|
private final SubjectVariableInterpreter subjectVariableInterpreter; |
59 |
|
|
60 |
|
|
61 |
|
private final PredicateVariableInterpreter predicateVariableInterpreter; |
62 |
|
|
63 |
|
|
64 |
|
private final FunctionVariableInterpreter functionVariableInterpreter; |
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
|
69 |
|
@param |
70 |
|
@param |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
72 |
52
|
public DynamicDirectInterpreter(final KernelQedeqBo qedeq, final DynamicModel model) {... |
73 |
52
|
this(qedeq, model, new SubjectVariableInterpreter(model), new PredicateVariableInterpreter( |
74 |
|
model), new FunctionVariableInterpreter(model)); |
75 |
|
} |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
@param |
81 |
|
@param |
82 |
|
@param |
83 |
|
@param |
84 |
|
@param |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
86 |
52
|
public DynamicDirectInterpreter(final KernelQedeqBo qedeq, final DynamicModel model,... |
87 |
|
final SubjectVariableInterpreter subjectVariableInterpreter, |
88 |
|
final PredicateVariableInterpreter predicateVariableInterpreter, |
89 |
|
final FunctionVariableInterpreter functionVariableInterpreter) { |
90 |
52
|
this.qedeq = qedeq; |
91 |
52
|
this.model = model; |
92 |
52
|
this.subjectVariableInterpreter = subjectVariableInterpreter; |
93 |
52
|
this.predicateVariableInterpreter = predicateVariableInterpreter; |
94 |
52
|
this.functionVariableInterpreter = functionVariableInterpreter; |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
@param |
101 |
|
@param |
102 |
|
@return |
103 |
|
@throws |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
105 |
6504
|
public Entity calculateFunctionValue(final FunctionConstant constant,... |
106 |
|
final Entity[] entities) throws HeuristicException { |
107 |
6504
|
final List params = constant.getSubjectVariables(); |
108 |
17404
|
for (int i = 0; i < entities.length; i++) { |
109 |
10900
|
final SubjectVariable var = (SubjectVariable) params.get(i); |
110 |
10900
|
subjectVariableInterpreter.forceAddSubjectVariable(var, entities[i].getValue()); |
111 |
|
} |
112 |
6504
|
Entity result; |
113 |
6504
|
try { |
114 |
6504
|
result = calculateTerm(constant.getDefiningTerm()); |
115 |
|
} finally { |
116 |
17404
|
for (int i = entities.length - 1; i >= 0; i--) { |
117 |
10900
|
final SubjectVariable var = (SubjectVariable) params.get(i); |
118 |
10900
|
subjectVariableInterpreter.forceRemoveSubjectVariable(var); |
119 |
|
} |
120 |
|
} |
121 |
6504
|
return result; |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
@param |
128 |
|
@param |
129 |
|
@return |
130 |
|
@throws |
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 3 |
Complexity Density: 0.27 |
|
132 |
12842
|
public boolean calculatePredicateValue(final PredicateConstant constant,... |
133 |
|
final Entity[] entities) throws HeuristicException { |
134 |
12842
|
final List params = constant.getSubjectVariables(); |
135 |
31646
|
for (int i = 0; i < entities.length; i++) { |
136 |
18804
|
final SubjectVariable var = (SubjectVariable) params.get(i); |
137 |
18804
|
subjectVariableInterpreter.forceAddSubjectVariable(var, entities[i].getValue()); |
138 |
|
} |
139 |
12842
|
boolean result; |
140 |
12842
|
try { |
141 |
12842
|
result = calculateValue(constant.getDefiningFormula()); |
142 |
|
} finally { |
143 |
31646
|
for (int i = entities.length - 1; i >= 0; i--) { |
144 |
18804
|
final SubjectVariable var = (SubjectVariable) params.get(i); |
145 |
18804
|
subjectVariableInterpreter.forceRemoveSubjectVariable(var); |
146 |
|
} |
147 |
|
} |
148 |
12842
|
return result; |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
@param |
156 |
|
@param |
157 |
|
@return |
158 |
|
@throws |
159 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
160 |
1583
|
public boolean calculateValue(final ModuleContext moduleContext, final Element formula)... |
161 |
|
throws HeuristicException { |
162 |
|
|
163 |
1583
|
this.moduleContext = new ModuleContext(moduleContext); |
164 |
|
|
165 |
1583
|
return calculateValue(formula); |
166 |
|
} |
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
@param |
173 |
|
@return |
174 |
|
@throws |
175 |
|
|
|
|
| 84% |
Uncovered Elements: 25 (156) |
Complexity: 35 |
Complexity Density: 0.35 |
|
176 |
236342
|
private boolean calculateValue(final Element formula) throws HeuristicException {... |
177 |
236342
|
final String method = "calculateValue(Element)"; |
178 |
236342
|
if (Trace.isDebugEnabled(CLASS)) { |
179 |
0
|
Trace.param(CLASS, this, method, deepness.toString() + "formula", |
180 |
|
Latex2UnicodeParser.transform(null, qedeq.getElement2Latex().getLatex(formula), 0)); |
181 |
0
|
deepness.append("-"); |
182 |
|
} |
183 |
236342
|
if (formula.isAtom()) { |
184 |
0
|
throw new HeuristicException(HeuristicErrorCodes.WRONG_CALLING_CONVENTION_CODE, |
185 |
|
HeuristicErrorCodes.WRONG_CALLING_CONVENTION_TEXT, moduleContext); |
186 |
|
} |
187 |
236342
|
final KernelQedeqBo qedeqOld = qedeq; |
188 |
236342
|
final ModuleContext moduleContextOld = new ModuleContext(moduleContext); |
189 |
236342
|
final String context = getLocationWithinModule(); |
190 |
236342
|
boolean result; |
191 |
236342
|
try { |
192 |
236342
|
final ElementList list = formula.getList(); |
193 |
236342
|
setLocationWithinModule(context + ".getList()"); |
194 |
236342
|
final String op = list.getOperator(); |
195 |
236342
|
if (Operators.CONJUNCTION_OPERATOR.equals(op)) { |
196 |
28721
|
result = true; |
197 |
77925
|
for (int i = 0; i < list.size() && result; i++) { |
198 |
49204
|
setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
199 |
49204
|
result &= calculateValue(list.getElement(i)); |
200 |
|
} |
201 |
207621
|
} else if (Operators.DISJUNCTION_OPERATOR.equals(op)) { |
202 |
8254
|
result = false; |
203 |
21658
|
for (int i = 0; i < list.size() && !result; i++) { |
204 |
13404
|
setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
205 |
13404
|
result |= calculateValue(list.getElement(i)); |
206 |
|
} |
207 |
199367
|
} else if (Operators.EQUIVALENCE_OPERATOR.equals(op)) { |
208 |
11079
|
result = true; |
209 |
11079
|
boolean value = false; |
210 |
33237
|
for (int i = 0; i < list.size() && result; i++) { |
211 |
22158
|
setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
212 |
22158
|
if (i > 0) { |
213 |
11079
|
if (value != calculateValue(list.getElement(i))) { |
214 |
1601
|
result = false; |
215 |
|
} |
216 |
|
} else { |
217 |
11079
|
value = calculateValue(list.getElement(i)); |
218 |
|
} |
219 |
|
} |
220 |
188288
|
} else if (Operators.IMPLICATION_OPERATOR.equals(op)) { |
221 |
19572
|
result = false; |
222 |
45950
|
for (int i = 0; i < list.size() && !result; i++) { |
223 |
26378
|
setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
224 |
26378
|
if (i < list.size() - 1) { |
225 |
19572
|
result |= !calculateValue(list.getElement(i)); |
226 |
|
} else { |
227 |
6806
|
result |= calculateValue(list.getElement(i)); |
228 |
|
} |
229 |
|
} |
230 |
168716
|
} else if (Operators.NEGATION_OPERATOR.equals(op)) { |
231 |
1847
|
result = true; |
232 |
3694
|
for (int i = 0; i < list.size() && result; i++) { |
233 |
1847
|
setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
234 |
1847
|
result &= !calculateValue(list.getElement(i)); |
235 |
|
} |
236 |
166869
|
} else if (Operators.PREDICATE_VARIABLE.equals(op)) { |
237 |
70997
|
setLocationWithinModule(context + ".getList()"); |
238 |
70997
|
final Entity[] arguments = getEntities(list); |
239 |
70997
|
final PredicateVariable var = new PredicateVariable( |
240 |
|
list.getElement(0).getAtom().getString(), list.size() - 1); |
241 |
70997
|
result = predicateVariableInterpreter.getPredicate(var) |
242 |
|
.calculate(arguments); |
243 |
95872
|
} else if (Operators.UNIVERSAL_QUANTIFIER_OPERATOR.equals(op)) { |
244 |
18502
|
result = handleUniversalQuantifier(list); |
245 |
77370
|
} else if (Operators.EXISTENTIAL_QUANTIFIER_OPERATOR.equals(op)) { |
246 |
16913
|
result = handleExistentialQuantifier(list); |
247 |
60457
|
} else if (Operators.UNIQUE_EXISTENTIAL_QUANTIFIER_OPERATOR.equals(op)) { |
248 |
5
|
result = handleUniqueExistentialQuantifier(list); |
249 |
60452
|
} else if (Operators.PREDICATE_CONSTANT.equals(op)) { |
250 |
60452
|
final String label = list.getElement(0).getAtom().getString(); |
251 |
60452
|
String name = label; |
252 |
|
|
253 |
60452
|
KernelQedeqBo newProp = qedeq; |
254 |
66944
|
while (name.indexOf(".") >= 0) { |
255 |
6492
|
name = name.substring(label.indexOf(".") + 1); |
256 |
6492
|
final String external = label.substring(0, label.indexOf(".")); |
257 |
6492
|
newProp = null; |
258 |
6492
|
if (qedeq.getKernelRequiredModules() != null) { |
259 |
6492
|
newProp = qedeq.getKernelRequiredModules().getKernelQedeqBo(external); |
260 |
|
} |
261 |
6492
|
if (newProp == null) { |
262 |
0
|
setLocationWithinModule(context + ".getList().getOperator()"); |
263 |
0
|
throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_IMPORT_MODULE_CODE, |
264 |
|
HeuristicErrorCodes.UNKNOWN_IMPORT_MODULE_TEXT + "\"" + external + "\"" |
265 |
|
+ HeuristicErrorCodes.UNKNOWN_IMPORT_MODULE_TEXT_2 + "\"" + external |
266 |
|
+ "." + name + "\"", |
267 |
|
moduleContext); |
268 |
|
} |
269 |
|
} |
270 |
60452
|
final PredicateKey predicateKey = new PredicateKey(name, "" + (list.size() - 1)); |
271 |
60452
|
final PredicateConstant constant = (newProp.getExistenceChecker() != null |
272 |
|
? newProp.getExistenceChecker().get(predicateKey) : null); |
273 |
60452
|
if (constant != null) { |
274 |
6478
|
setLocationWithinModule(context + ".getList()"); |
275 |
6478
|
final Entity[] arguments = getEntities(list); |
276 |
6478
|
setModuleContext(newProp); |
277 |
6478
|
moduleContext = new ModuleContext(constant.getContext()); |
278 |
|
|
279 |
6478
|
moduleContext.setLocationWithinModule(moduleContext.getLocationWithinModule() |
280 |
|
+ ".getElement(1)"); |
281 |
6478
|
try { |
282 |
6478
|
result = calculatePredicateValue(constant, arguments); |
283 |
|
} catch (HeuristicException e) { |
284 |
0
|
setModuleContext(qedeqOld); |
285 |
0
|
moduleContext = moduleContextOld; |
286 |
0
|
setLocationWithinModule(context + ".getList().getElement(1)"); |
287 |
0
|
throw new HeuristicException( |
288 |
|
HeuristicErrorCodes.PREDICATE_CALCULATION_FAILED_CODE, |
289 |
|
HeuristicErrorCodes.PREDICATE_CALCULATION_FAILED_TEXT + predicateKey, |
290 |
|
moduleContext, e.getContext()); |
291 |
|
} |
292 |
|
} else { |
293 |
53974
|
final ModelPredicateConstant var = new ModelPredicateConstant(name, list.size() |
294 |
|
- 1); |
295 |
53974
|
final Predicate predicate = model.getPredicateConstant(var); |
296 |
53974
|
if (predicate == null) { |
297 |
0
|
setLocationWithinModule(context + ".getList().getOperator()"); |
298 |
0
|
throw new HeuristicException( |
299 |
|
HeuristicErrorCodes.UNKNOWN_PREDICATE_CONSTANT_CODE, |
300 |
|
HeuristicErrorCodes.UNKNOWN_PREDICATE_CONSTANT_TEXT + var, |
301 |
|
moduleContext); |
302 |
|
} |
303 |
53974
|
setLocationWithinModule(context + ".getList()"); |
304 |
53974
|
final Entity[] arguments = getEntities(list); |
305 |
53974
|
result = predicate.calculate(arguments); |
306 |
|
} |
307 |
|
} else { |
308 |
0
|
setLocationWithinModule(context + ".getList().getOperator()"); |
309 |
0
|
throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_OPERATOR_CODE, |
310 |
|
HeuristicErrorCodes.UNKNOWN_OPERATOR_TEXT + op, moduleContext); |
311 |
|
} |
312 |
|
} finally { |
313 |
|
|
314 |
236342
|
setModuleContext(qedeqOld); |
315 |
236342
|
moduleContext = moduleContextOld; |
316 |
236342
|
setLocationWithinModule(context); |
317 |
|
} |
318 |
236342
|
if (Trace.isDebugEnabled(CLASS)) { |
319 |
0
|
deepness.setLength(deepness.length() > 0 ? deepness.length() - 1 : 0); |
320 |
0
|
Trace.param(CLASS, this, method, deepness.toString() + Latex2UnicodeParser.transform( |
321 |
|
null, qedeq.getElement2Latex().getLatex(formula), 0), result); |
322 |
|
} |
323 |
236342
|
return result; |
324 |
|
} |
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
@param |
330 |
|
@return |
331 |
|
@throws |
332 |
|
|
|
|
| 93.3% |
Uncovered Elements: 2 (30) |
Complexity: 5 |
Complexity Density: 0.23 |
|
333 |
18502
|
private boolean handleUniversalQuantifier(final ElementList list)... |
334 |
|
throws HeuristicException { |
335 |
18502
|
final String method = "handleUniversalQuantifier(ElementList)"; |
336 |
18502
|
final String context = getLocationWithinModule(); |
337 |
18502
|
boolean result = true; |
338 |
18502
|
final ElementList variable = list.getElement(0).getList(); |
339 |
18502
|
final SubjectVariable var = new SubjectVariable(variable.getElement(0).getAtom().getString()); |
340 |
18502
|
subjectVariableInterpreter.addSubjectVariable(var); |
341 |
42311
|
for (int i = 0; i < model.getEntitiesSize(); i++) { |
342 |
37704
|
if (Trace.isDebugEnabled(CLASS)) { |
343 |
0
|
Trace.param(CLASS, this, method, deepness.toString() |
344 |
|
+ Latex2UnicodeParser.transform(null, qedeq.getElement2Latex() |
345 |
|
.getLatex(variable), 0), model.getEntity(i)); |
346 |
|
} |
347 |
37704
|
if (list.size() == 2) { |
348 |
37478
|
setLocationWithinModule(context + ".getElement(1)"); |
349 |
37478
|
result &= calculateValue(list.getElement(1)); |
350 |
|
} else { |
351 |
226
|
setLocationWithinModule(context + ".getElement(1)"); |
352 |
226
|
final boolean result1 = calculateValue(list.getElement(1)); |
353 |
226
|
setLocationWithinModule(context + ".getElement(2)"); |
354 |
226
|
final boolean result2 = calculateValue(list.getElement(2)); |
355 |
226
|
result &= !result1 || result2; |
356 |
|
} |
357 |
37704
|
if (!result) { |
358 |
13895
|
break; |
359 |
|
} |
360 |
23809
|
subjectVariableInterpreter.increaseSubjectVariableSelection(var); |
361 |
|
} |
362 |
18502
|
subjectVariableInterpreter.removeSubjectVariable(var); |
363 |
18502
|
return result; |
364 |
|
} |
365 |
|
|
366 |
|
|
367 |
|
|
368 |
|
|
369 |
|
@param |
370 |
|
@return |
371 |
|
@throws |
372 |
|
|
|
|
| 73.3% |
Uncovered Elements: 8 (30) |
Complexity: 5 |
Complexity Density: 0.23 |
|
373 |
16913
|
private boolean handleExistentialQuantifier(final ElementList list)... |
374 |
|
throws HeuristicException { |
375 |
16913
|
final String method = "handleExistentialQuantifier(ElementList)"; |
376 |
16913
|
final String context = getLocationWithinModule(); |
377 |
16913
|
boolean result = false; |
378 |
16913
|
final ElementList variable = list.getElement(0).getList(); |
379 |
16913
|
final SubjectVariable var = new SubjectVariable(variable.getElement(0).getAtom().getString()); |
380 |
16913
|
subjectVariableInterpreter.addSubjectVariable(var); |
381 |
49952
|
for (int i = 0; i < model.getEntitiesSize(); i++) { |
382 |
44834
|
if (Trace.isDebugEnabled(CLASS)) { |
383 |
0
|
Trace.param(CLASS, this, method, deepness.toString() + Latex2UnicodeParser |
384 |
|
.transform(null, qedeq.getElement2Latex().getLatex(variable), 0), |
385 |
|
model.getEntity(i)); |
386 |
|
} |
387 |
44834
|
if (list.size() == 2) { |
388 |
44834
|
setLocationWithinModule(context + ".getElement(1)"); |
389 |
44834
|
result |= calculateValue(list.getElement(1)); |
390 |
|
} else { |
391 |
0
|
setLocationWithinModule(context + ".getElement(1)"); |
392 |
0
|
final boolean result1 = calculateValue(list.getElement(1)); |
393 |
0
|
setLocationWithinModule(context + ".getElement(2)"); |
394 |
0
|
final boolean result2 = calculateValue(list.getElement(2)); |
395 |
0
|
result |= result1 && result2; |
396 |
|
} |
397 |
44834
|
if (result) { |
398 |
11795
|
break; |
399 |
|
} |
400 |
33039
|
subjectVariableInterpreter.increaseSubjectVariableSelection(var); |
401 |
|
} |
402 |
16913
|
subjectVariableInterpreter.removeSubjectVariable(var); |
403 |
16913
|
return result; |
404 |
|
} |
405 |
|
|
406 |
|
|
407 |
|
|
408 |
|
|
409 |
|
@param |
410 |
|
@return |
411 |
|
@throws |
412 |
|
|
|
|
| 77.8% |
Uncovered Elements: 8 (36) |
Complexity: 6 |
Complexity Density: 0.23 |
|
413 |
5
|
private boolean handleUniqueExistentialQuantifier(final ElementList list)... |
414 |
|
throws HeuristicException { |
415 |
5
|
final String method = "handleUniqueExistentialQuantifier(ElementList)"; |
416 |
5
|
final String context = getLocationWithinModule(); |
417 |
5
|
boolean result = false; |
418 |
5
|
final ElementList variable = list.getElement(0).getList(); |
419 |
5
|
final SubjectVariable var = new SubjectVariable(variable.getElement(0).getAtom().getString()); |
420 |
5
|
subjectVariableInterpreter.addSubjectVariable(var); |
421 |
22
|
for (int i = 0; i < model.getEntitiesSize(); i++) { |
422 |
18
|
if (Trace.isDebugEnabled(CLASS)) { |
423 |
0
|
Trace.param(CLASS, this, method, deepness.toString() + Latex2UnicodeParser.transform(null, |
424 |
|
qedeq.getElement2Latex().getLatex(variable), 0), model.getEntity(i)); |
425 |
|
} |
426 |
18
|
boolean val; |
427 |
18
|
if (list.size() == 2) { |
428 |
18
|
setLocationWithinModule(context + ".getList().getElement(1)"); |
429 |
18
|
val = calculateValue(list.getElement(1)); |
430 |
|
} else { |
431 |
0
|
setLocationWithinModule(context + ".getList().getElement(1)"); |
432 |
0
|
final boolean result1 = calculateValue(list.getElement(1)); |
433 |
0
|
setLocationWithinModule(context + ".getList().getElement(2)"); |
434 |
0
|
final boolean result2 = calculateValue(list.getElement(2)); |
435 |
0
|
val = result1 && result2; |
436 |
|
} |
437 |
18
|
if (val) { |
438 |
6
|
if (result) { |
439 |
1
|
result = false; |
440 |
1
|
break; |
441 |
|
} |
442 |
5
|
result = true; |
443 |
|
} |
444 |
17
|
subjectVariableInterpreter.increaseSubjectVariableSelection(var); |
445 |
|
} |
446 |
5
|
subjectVariableInterpreter.removeSubjectVariable(var); |
447 |
5
|
return result; |
448 |
|
} |
449 |
|
|
450 |
|
|
451 |
|
|
452 |
|
|
453 |
|
@param |
454 |
|
@return |
455 |
|
@throws |
456 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
457 |
138097
|
private Entity[] getEntities(final ElementList terms)... |
458 |
|
throws HeuristicException { |
459 |
|
|
460 |
138097
|
final String context = getLocationWithinModule(); |
461 |
138097
|
final Entity[] result = new Entity[terms.size() - 1]; |
462 |
347464
|
for (int i = 0; i < result.length; i++) { |
463 |
|
|
464 |
209367
|
setLocationWithinModule(context + ".getElement(" + (i + 1) + ")"); |
465 |
209367
|
result[i] = calculateTerm(terms.getElement(i + 1)); |
466 |
|
} |
467 |
138097
|
setLocationWithinModule(context); |
468 |
138097
|
return result; |
469 |
|
} |
470 |
|
|
471 |
|
|
472 |
|
|
473 |
|
|
474 |
|
|
475 |
|
@param |
476 |
|
@param |
477 |
|
@return |
478 |
|
@throws |
479 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
480 |
0
|
public Entity calculateTerm(final ModuleContext moduleContext, final Element term)... |
481 |
|
throws HeuristicException { |
482 |
0
|
this.moduleContext = moduleContext; |
483 |
0
|
return calculateTerm(term); |
484 |
|
} |
485 |
|
|
486 |
|
|
487 |
|
|
488 |
|
|
489 |
|
@param |
490 |
|
@return |
491 |
|
@throws |
492 |
|
|
|
|
| 63.4% |
Uncovered Elements: 48 (131) |
Complexity: 21 |
Complexity Density: 0.22 |
|
493 |
215871
|
private Entity calculateTerm(final Element term)... |
494 |
|
throws HeuristicException { |
495 |
215871
|
final String method = "calculateTerm(Element) "; |
496 |
215871
|
if (Trace.isDebugEnabled(CLASS)) { |
497 |
0
|
Trace.param(CLASS, this, method, deepness.toString() + "term ", Latex2UnicodeParser.transform(null, |
498 |
|
qedeq.getElement2Latex().getLatex(term), 0)); |
499 |
0
|
deepness.append("-"); |
500 |
|
} |
501 |
215871
|
if (!term.isList()) { |
502 |
0
|
throw new RuntimeException("a term should be a list: " + term); |
503 |
|
} |
504 |
215871
|
final KernelQedeqBo qedeqOld = qedeq; |
505 |
215871
|
final ModuleContext moduleContextOld = new ModuleContext(moduleContext); |
506 |
215871
|
final String context = getLocationWithinModule(); |
507 |
215871
|
Entity result = null; |
508 |
215871
|
try { |
509 |
215871
|
final ElementList termList = term.getList(); |
510 |
215871
|
final String op = termList.getOperator(); |
511 |
215871
|
if (Operators.SUBJECT_VARIABLE.equals(op)) { |
512 |
202687
|
final String text = termList.getElement(0).getAtom().getString(); |
513 |
202687
|
final SubjectVariable var = new SubjectVariable(text); |
514 |
202687
|
result = subjectVariableInterpreter.getEntity(var); |
515 |
13184
|
} else if (Operators.FUNCTION_VARIABLE.equals(op)) { |
516 |
144
|
final FunctionVariable var = new FunctionVariable(termList.getElement(0).getAtom().getString(), |
517 |
|
termList.size() - 1); |
518 |
144
|
Function function = functionVariableInterpreter.getFunction(var); |
519 |
144
|
setLocationWithinModule(context + ".getList()"); |
520 |
144
|
result = function.map(getEntities(termList)); |
521 |
13040
|
} else if (Operators.FUNCTION_CONSTANT.equals(op)) { |
522 |
6504
|
final String label = termList.getElement(0).getAtom().getString(); |
523 |
6504
|
String name = label; |
524 |
6504
|
KernelQedeqBo newProp = qedeq; |
525 |
6504
|
if (label.indexOf(".") >= 0) { |
526 |
0
|
name = label.substring(label.indexOf(".") + 1); |
527 |
0
|
final String external = label.substring(0, label.indexOf(".")); |
528 |
0
|
newProp = null; |
529 |
0
|
if (qedeq.getKernelRequiredModules() != null) { |
530 |
0
|
newProp = qedeq.getKernelRequiredModules().getKernelQedeqBo(external); |
531 |
|
} |
532 |
0
|
if (newProp == null) { |
533 |
0
|
setLocationWithinModule(context + ".getList().getOperator()"); |
534 |
0
|
throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_IMPORT_MODULE_CODE, |
535 |
|
HeuristicErrorCodes.UNKNOWN_IMPORT_MODULE_TEXT + "\"" + external + "\"" |
536 |
|
+ HeuristicErrorCodes.UNKNOWN_IMPORT_MODULE_TEXT_2 + "\"" + label + "\"", |
537 |
|
moduleContext); |
538 |
|
} |
539 |
|
} |
540 |
6504
|
final FunctionKey functionKey = new FunctionKey(name, "" + (termList.size() - 1)); |
541 |
6504
|
FunctionConstant constant |
542 |
|
= newProp.getExistenceChecker().get(functionKey); |
543 |
6504
|
if (constant != null) { |
544 |
6504
|
setLocationWithinModule(context + ".getList()"); |
545 |
6504
|
final Entity[] arguments = getEntities(termList); |
546 |
6504
|
setModuleContext(newProp); |
547 |
6504
|
moduleContext = new ModuleContext(constant.getContext()); |
548 |
|
|
549 |
6504
|
moduleContext.setLocationWithinModule(moduleContext.getLocationWithinModule() + ".getElement(2)"); |
550 |
6504
|
try { |
551 |
6504
|
result = calculateFunctionValue(constant, arguments); |
552 |
|
} catch (HeuristicException e) { |
553 |
0
|
setModuleContext(qedeqOld); |
554 |
0
|
moduleContext = moduleContextOld; |
555 |
0
|
setLocationWithinModule(context + ".getList().getElement(1)"); |
556 |
0
|
throw new HeuristicException(HeuristicErrorCodes.PREDICATE_CALCULATION_FAILED_CODE, |
557 |
|
HeuristicErrorCodes.PREDICATE_CALCULATION_FAILED_TEXT + functionKey, |
558 |
|
moduleContext, e.getContext()); |
559 |
|
} |
560 |
|
} else { |
561 |
0
|
final ModelFunctionConstant var = new ModelFunctionConstant(name, |
562 |
|
termList.size() - 1); |
563 |
0
|
Function function = model.getFunctionConstant(var); |
564 |
0
|
if (function == null) { |
565 |
0
|
setLocationWithinModule(context + ".getList().getOperator()"); |
566 |
0
|
throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_FUNCTION_CONSTANT_CODE, |
567 |
|
HeuristicErrorCodes.UNKNOWN_FUNCTION_CONSTANT_TEXT + var, moduleContext); |
568 |
|
} |
569 |
0
|
setLocationWithinModule(context + ".getList()"); |
570 |
0
|
final Entity[] arguments = getEntities(termList); |
571 |
0
|
result = function.map(arguments); |
572 |
|
} |
573 |
6536
|
} else if (Operators.CLASS_OP.equals(op)) { |
574 |
6536
|
List fullfillers = new ArrayList(); |
575 |
6536
|
ElementList variable = termList.getElement(0).getList(); |
576 |
6536
|
final SubjectVariable var = new SubjectVariable(variable.getElement(0).getAtom().getString()); |
577 |
6536
|
subjectVariableInterpreter.addSubjectVariable(var); |
578 |
6536
|
KernelQedeqBo newProp = qedeq; |
579 |
6536
|
if (qedeq.getExistenceChecker() != null) { |
580 |
6536
|
newProp = qedeq.getExistenceChecker().getClassOperatorModule(); |
581 |
|
} |
582 |
6536
|
final PredicateConstant isSet = newProp.getExistenceChecker().getPredicate("isSet", 1); |
583 |
6536
|
if (isSet == null) { |
584 |
0
|
throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_TERM_OPERATOR_CODE, |
585 |
|
HeuristicErrorCodes.UNKNOWN_TERM_OPERATOR_TEXT + "isSet(*)", moduleContext); |
586 |
|
} |
587 |
32680
|
for (int i = 0; i < model.getEntitiesSize(); i++) { |
588 |
26144
|
setModuleContext(qedeqOld); |
589 |
26144
|
moduleContext = moduleContextOld; |
590 |
26144
|
setLocationWithinModule(context + ".getList().getElement(1)"); |
591 |
26144
|
if (calculateValue(termList.getElement(1))) { |
592 |
6364
|
setModuleContext(newProp); |
593 |
6364
|
moduleContext = newProp.getLabels().getPredicateContext("isSet", 1); |
594 |
6364
|
setLocationWithinModule(moduleContext.getLocationWithinModule() |
595 |
|
+ ".getFormula().getElement().getList().getElement(1)"); |
596 |
6364
|
try { |
597 |
6364
|
if (calculatePredicateValue(isSet, new Entity[] {model.getEntity(i)})) { |
598 |
4880
|
fullfillers.add(model.getEntity(i)); |
599 |
|
} |
600 |
|
} catch (HeuristicException e) { |
601 |
0
|
setModuleContext(qedeqOld); |
602 |
0
|
moduleContext = moduleContextOld; |
603 |
0
|
setLocationWithinModule(context + ".getList().getElement(1)"); |
604 |
0
|
throw new HeuristicException(HeuristicErrorCodes.PREDICATE_CALCULATION_FAILED_CODE, |
605 |
|
HeuristicErrorCodes.PREDICATE_CALCULATION_FAILED_TEXT + isSet, |
606 |
|
moduleContext, e.getContext()); |
607 |
|
} |
608 |
|
} |
609 |
26144
|
subjectVariableInterpreter.increaseSubjectVariableSelection(var); |
610 |
|
} |
611 |
6536
|
result = model.comprehension((Entity[]) fullfillers.toArray(new Entity[] {})); |
612 |
6536
|
subjectVariableInterpreter.removeSubjectVariable(var); |
613 |
|
} else { |
614 |
0
|
setLocationWithinModule(context + ".getList().getOperator()"); |
615 |
0
|
throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_TERM_OPERATOR_CODE, |
616 |
|
HeuristicErrorCodes.UNKNOWN_TERM_OPERATOR_TEXT + op, moduleContext); |
617 |
|
} |
618 |
|
} finally { |
619 |
|
|
620 |
215871
|
setModuleContext(qedeqOld); |
621 |
215871
|
moduleContext = moduleContextOld; |
622 |
|
|
623 |
215871
|
setLocationWithinModule(context); |
624 |
|
} |
625 |
215871
|
if (Trace.isDebugEnabled(CLASS)) { |
626 |
0
|
deepness.setLength(deepness.length() > 0 ? deepness.length() - 1 : 0); |
627 |
0
|
Trace.param(CLASS, this, method, deepness.toString() + Latex2UnicodeParser.transform(null, |
628 |
|
qedeq.getElement2Latex().getLatex(term), 0), result); |
629 |
|
} |
630 |
215871
|
return result; |
631 |
|
} |
632 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
633 |
625730
|
private String getLocationWithinModule() {... |
634 |
625730
|
return moduleContext.getLocationWithinModule(); |
635 |
|
} |
636 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
637 |
1397904
|
protected ModuleContext getModuleContext() {... |
638 |
1397904
|
return moduleContext; |
639 |
|
} |
640 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
641 |
497703
|
protected void setModuleContext(final KernelQedeqBo qedeq) {... |
642 |
497703
|
this.qedeq = qedeq; |
643 |
497703
|
moduleContext = new ModuleContext(qedeq.getModuleAddress()); |
644 |
|
} |
645 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
646 |
1402397
|
protected void setLocationWithinModule(final String localContext) {... |
647 |
1402397
|
moduleContext.setLocationWithinModule(localContext); |
648 |
|
} |
649 |
|
|
650 |
|
|
651 |
|
|
652 |
|
|
653 |
|
@return |
654 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
655 |
1564
|
public boolean next() {... |
656 |
1564
|
return subjectVariableInterpreter.next() || predicateVariableInterpreter.next() |
657 |
|
|| functionVariableInterpreter.next(); |
658 |
|
} |
659 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
660 |
0
|
public String toString() {... |
661 |
0
|
final StringBuffer buffer = new StringBuffer(); |
662 |
0
|
buffer.append("Current interpretation:\n"); |
663 |
0
|
buffer.append("\t" + predicateVariableInterpreter + "\n"); |
664 |
0
|
buffer.append("\t" + subjectVariableInterpreter + "\n"); |
665 |
0
|
buffer.append("\t" + functionVariableInterpreter); |
666 |
0
|
return buffer.toString(); |
667 |
|
} |
668 |
|
|
669 |
|
|
670 |
|
|
671 |
|
|
672 |
|
@param |
673 |
|
@return |
674 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
675 |
0
|
public String stripReference(final String operator) {... |
676 |
0
|
final int index = operator.lastIndexOf("."); |
677 |
0
|
if (index >= 0 && index + 1 < operator.length()) { |
678 |
0
|
return operator.substring(index + 1); |
679 |
|
} |
680 |
0
|
return operator; |
681 |
|
} |
682 |
|
|
683 |
|
|
684 |
|
|
685 |
|
|
686 |
|
|
687 |
|
@param |
688 |
|
@return |
689 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
690 |
1
|
public boolean hasPredicateConstant(final ModelPredicateConstant constant) {... |
691 |
1
|
return null != model.getPredicateConstant(constant); |
692 |
|
} |
693 |
|
|
694 |
|
|
695 |
|
|
696 |
|
|
697 |
|
@param |
698 |
|
@return |
699 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
700 |
0
|
public boolean hasFunctionConstant(final ModelFunctionConstant constant) {... |
701 |
0
|
return null != model.getFunctionConstant(constant); |
702 |
|
} |
703 |
|
|
704 |
|
|
705 |
|
|
706 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
707 |
3
|
public void clearVariables() {... |
708 |
3
|
subjectVariableInterpreter.clear(); |
709 |
3
|
predicateVariableInterpreter.clear(); |
710 |
3
|
functionVariableInterpreter.clear(); |
711 |
|
} |
712 |
|
|
713 |
|
|
714 |
|
|
715 |
|
|
716 |
|
@return |
717 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
718 |
0
|
public DynamicModel getModel() {... |
719 |
0
|
return model; |
720 |
|
} |
721 |
|
|
722 |
|
|
723 |
|
} |