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