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.se.base.list.Element; |
30 |
|
import org.qedeq.kernel.se.base.list.ElementList; |
31 |
|
import org.qedeq.kernel.se.base.module.FunctionDefinition; |
32 |
|
import org.qedeq.kernel.se.base.module.PredicateDefinition; |
33 |
|
import org.qedeq.kernel.se.common.DefaultModuleAddress; |
34 |
|
import org.qedeq.kernel.se.common.ModuleContext; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@author |
41 |
|
|
|
|
| 70.2% |
Uncovered Elements: 117 (392) |
Complexity: 83 |
Complexity Density: 0.32 |
|
42 |
|
public class DynamicInterpreter { |
43 |
|
|
44 |
|
|
45 |
|
private static final Class CLASS = DynamicInterpreter.class; |
46 |
|
|
47 |
|
|
48 |
|
private final DynamicModel model; |
49 |
|
|
50 |
|
|
51 |
|
private final SubjectVariableInterpreter subjectVariableInterpreter; |
52 |
|
|
53 |
|
|
54 |
|
private final PredicateVariableInterpreter predicateVariableInterpreter; |
55 |
|
|
56 |
|
|
57 |
|
private final FunctionVariableInterpreter functionVariableInterpreter; |
58 |
|
|
59 |
|
|
60 |
|
private ModuleContext moduleContext; |
61 |
|
|
62 |
|
|
63 |
|
private final StringBuffer deepness = new StringBuffer(); |
64 |
|
|
65 |
|
|
66 |
|
private final KernelQedeqBo qedeq; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
@param |
72 |
|
@param |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
74 |
93
|
public DynamicInterpreter(final DynamicModel model, final KernelQedeqBo qedeq) {... |
75 |
93
|
this.model = model; |
76 |
93
|
subjectVariableInterpreter = new SubjectVariableInterpreter(model); |
77 |
93
|
predicateVariableInterpreter = new PredicateVariableInterpreter(model); |
78 |
93
|
functionVariableInterpreter = new FunctionVariableInterpreter(model); |
79 |
93
|
this.qedeq = qedeq; |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
@return |
86 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
87 |
0
|
public DynamicModel getModel() {... |
88 |
0
|
return model; |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
@param |
95 |
|
@param |
96 |
|
@param |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
3
|
public void addPredicateConstant(final ModelPredicateConstant constant, ... |
99 |
|
final List variables, final ElementList formula) { |
100 |
3
|
model.addPredicateConstant(constant, new Predicate(constant.getArgumentNumber(), |
101 |
|
constant.getArgumentNumber(), "", "") { |
|
|
| 93.3% |
Uncovered Elements: 1 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
102 |
55
|
public boolean calculate(final Entity[] entities) {... |
103 |
108
|
for (int i = 0; i < entities.length; i++) { |
104 |
53
|
final SubjectVariable var = (SubjectVariable) variables.get(i); |
105 |
53
|
subjectVariableInterpreter.forceAddSubjectVariable(var, entities[i].getValue()); |
106 |
|
} |
107 |
55
|
boolean result; |
108 |
55
|
try { |
109 |
55
|
result = calculateValue(new ModuleContext(new DefaultModuleAddress()), formula); |
110 |
|
} catch (HeuristicException e) { |
111 |
0
|
throw new RuntimeException(e); |
112 |
|
} |
113 |
108
|
for (int i = entities.length - 1; i >= 0; i--) { |
114 |
53
|
final SubjectVariable var = (SubjectVariable) variables.get(i); |
115 |
53
|
subjectVariableInterpreter.forceRemoveSubjectVariable(var); |
116 |
|
} |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
55
|
return result; |
126 |
|
} |
127 |
|
}); |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
@param |
134 |
|
@param |
135 |
|
@param |
136 |
|
@return |
137 |
|
@throws |
138 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
139 |
0
|
public boolean calculatPredicateValue(final KernelQedeqBo qedeq, final PredicateDefinition constant,... |
140 |
|
final Entity[] entities) throws HeuristicException { |
141 |
0
|
DynamicDirectInterpreter inter = new DynamicDirectInterpreter(qedeq, model, |
142 |
|
subjectVariableInterpreter, predicateVariableInterpreter, functionVariableInterpreter); |
143 |
0
|
return inter.calculatePredicateValue( |
144 |
|
new PredicateConstant(new PredicateKey(constant.getName(), constant.getName()), |
145 |
|
constant.getFormula().getElement().getList(), |
146 |
|
new ModuleContext(qedeq.getModuleAddress())), entities); |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
@param |
153 |
|
@param |
154 |
|
@param |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
0
|
public void addFunctionConstant(final ModelFunctionConstant constant,... |
157 |
|
final List variables, final ElementList term) { |
158 |
0
|
model.addFunctionConstant(constant, new Function(constant.getArgumentNumber(), |
159 |
|
constant.getArgumentNumber(), "", "") { |
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
160 |
0
|
public Entity map(final Entity[] entities) {... |
161 |
0
|
for (int i = 0; i < entities.length; i++) { |
162 |
0
|
final SubjectVariable var = (SubjectVariable) variables.get(i); |
163 |
0
|
subjectVariableInterpreter.forceAddSubjectVariable(var, entities[i].getValue()); |
164 |
|
} |
165 |
0
|
Entity result; |
166 |
0
|
try { |
167 |
0
|
result = calculateTerm(new ModuleContext(new DefaultModuleAddress()), term); |
168 |
|
} catch (HeuristicException e) { |
169 |
0
|
throw new RuntimeException(e); |
170 |
|
} |
171 |
0
|
for (int i = entities.length - 1; i >= 0; i--) { |
172 |
0
|
final SubjectVariable var = (SubjectVariable) variables.get(i); |
173 |
0
|
subjectVariableInterpreter.forceRemoveSubjectVariable(var); |
174 |
|
} |
175 |
0
|
return result; |
176 |
|
} |
177 |
|
}); |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
@param |
184 |
|
@param |
185 |
|
@param |
186 |
|
@return |
187 |
|
@throws |
188 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
189 |
0
|
public Entity calculateFunctionValue(final KernelQedeqBo qedeq, final FunctionDefinition constant,... |
190 |
|
final Entity[] entities) throws HeuristicException { |
191 |
0
|
DynamicDirectInterpreter inter = new DynamicDirectInterpreter(qedeq, model, |
192 |
|
subjectVariableInterpreter, predicateVariableInterpreter, functionVariableInterpreter); |
193 |
0
|
return inter.calculateFunctionValue( |
194 |
|
new FunctionConstant(new FunctionKey(constant.getName(), constant.getName()), |
195 |
|
constant.getFormula().getElement().getList(), |
196 |
|
new ModuleContext(qedeq.getModuleAddress())), entities); |
197 |
|
} |
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
|
@param |
203 |
|
@return |
204 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
205 |
0
|
public boolean hasPredicateConstant(final ModelPredicateConstant constant) {... |
206 |
0
|
return null != model.getPredicateConstant(constant); |
207 |
|
} |
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
@param |
213 |
|
@return |
214 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
215 |
0
|
public boolean hasFunctionConstant(final ModelFunctionConstant constant) {... |
216 |
0
|
return null != model.getFunctionConstant(constant); |
217 |
|
} |
218 |
|
|
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
@param |
224 |
|
@param |
225 |
|
@return |
226 |
|
@throws |
227 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
228 |
5280
|
public boolean calculateValue(final ModuleContext moduleContext, final Element formula)... |
229 |
|
throws HeuristicException { |
230 |
|
|
231 |
5280
|
this.moduleContext = moduleContext; |
232 |
|
|
233 |
5280
|
return calculateValue(formula); |
234 |
|
} |
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
@param |
241 |
|
@return |
242 |
|
@throws |
243 |
|
|
|
|
| 86.1% |
Uncovered Elements: 16 (115) |
Complexity: 24 |
Complexity Density: 0.35 |
|
244 |
483041
|
private boolean calculateValue(final Element formula) throws HeuristicException {... |
245 |
483041
|
final String method = "calculateValue(Element)"; |
246 |
|
|
247 |
|
|
248 |
|
|
249 |
483041
|
if (Trace.isDebugEnabled(CLASS)) { |
250 |
0
|
Trace.param(CLASS, this, method, deepness.toString() + "formula", formula); |
251 |
0
|
deepness.append("-"); |
252 |
|
} |
253 |
483041
|
if (formula.isAtom()) { |
254 |
0
|
throw new HeuristicException(HeuristicErrorCodes.WRONG_CALLING_CONVENTION_CODE, |
255 |
|
HeuristicErrorCodes.WRONG_CALLING_CONVENTION_TEXT, moduleContext); |
256 |
|
} |
257 |
483041
|
final String context = getLocationWithinModule(); |
258 |
483041
|
setLocationWithinModule(context + ".getList()"); |
259 |
483041
|
final ElementList list = formula.getList(); |
260 |
483041
|
final String op = list.getOperator(); |
261 |
483041
|
boolean result; |
262 |
483041
|
if (Operators.CONJUNCTION_OPERATOR.equals(op)) { |
263 |
20372
|
result = true; |
264 |
83964
|
for (int i = 0; i < list.size(); i++) { |
265 |
63592
|
setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
266 |
63592
|
result &= calculateValue(list.getElement(i)); |
267 |
|
} |
268 |
462669
|
} else if (Operators.DISJUNCTION_OPERATOR.equals(op)) { |
269 |
22184
|
result = false; |
270 |
82936
|
for (int i = 0; i < list.size(); i++) { |
271 |
60752
|
setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
272 |
60752
|
result |= calculateValue(list.getElement(i)); |
273 |
|
} |
274 |
440485
|
} else if (Operators.EQUIVALENCE_OPERATOR.equals(op)) { |
275 |
26592
|
result = true; |
276 |
26592
|
boolean value = false; |
277 |
79776
|
for (int i = 0; i < list.size(); i++) { |
278 |
53184
|
if (i > 0) { |
279 |
26592
|
setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
280 |
26592
|
if (value != calculateValue(list.getElement(i))) { |
281 |
4708
|
result = false; |
282 |
|
} |
283 |
|
} else { |
284 |
26592
|
setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
285 |
26592
|
value = calculateValue(list.getElement(i)); |
286 |
|
} |
287 |
|
} |
288 |
413893
|
} else if (Operators.IMPLICATION_OPERATOR.equals(op)) { |
289 |
49890
|
result = false; |
290 |
149670
|
for (int i = 0; i < list.size(); i++) { |
291 |
99780
|
setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
292 |
99780
|
if (i < list.size() - 1) { |
293 |
49890
|
result |= !calculateValue(list.getElement(i)); |
294 |
|
} else { |
295 |
49890
|
result |= calculateValue(list.getElement(i)); |
296 |
|
} |
297 |
|
} |
298 |
364003
|
} else if (Operators.NEGATION_OPERATOR.equals(op)) { |
299 |
372
|
result = true; |
300 |
744
|
for (int i = 0; i < list.size(); i++) { |
301 |
372
|
setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
302 |
372
|
result &= !calculateValue(list.getElement(i)); |
303 |
|
} |
304 |
363631
|
} else if (Operators.PREDICATE_VARIABLE.equals(op)) { |
305 |
283599
|
final PredicateVariable var = new PredicateVariable(list.getElement(0).getAtom().getString(), |
306 |
|
list.size() - 1); |
307 |
283599
|
setLocationWithinModule(context + ".getList()"); |
308 |
283599
|
result = predicateVariableInterpreter.getPredicate(var) |
309 |
|
.calculate(getEntities(list)); |
310 |
80032
|
} else if (Operators.UNIVERSAL_QUANTIFIER_OPERATOR.equals(op)) { |
311 |
52071
|
result = handleUniversalQuantifier(list); |
312 |
27961
|
} else if (Operators.EXISTENTIAL_QUANTIFIER_OPERATOR.equals(op)) { |
313 |
27194
|
result = handleExistentialQuantifier(list); |
314 |
767
|
} else if (Operators.UNIQUE_EXISTENTIAL_QUANTIFIER_OPERATOR.equals(op)) { |
315 |
11
|
result = handleUniqueExistentialQuantifier(list); |
316 |
756
|
} else if (Operators.PREDICATE_CONSTANT.equals(op)) { |
317 |
756
|
final String text = stripReference(list.getElement(0).getAtom().getString()); |
318 |
756
|
final ModelPredicateConstant var = new ModelPredicateConstant(text, |
319 |
|
list.size() - 1); |
320 |
756
|
Predicate predicate = model.getPredicateConstant(var); |
321 |
756
|
if (predicate == null) { |
322 |
|
|
323 |
0
|
setLocationWithinModule(context + ".getList().getOperator()"); |
324 |
0
|
throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_PREDICATE_CONSTANT_CODE, |
325 |
|
HeuristicErrorCodes.UNKNOWN_PREDICATE_CONSTANT_TEXT + var, moduleContext); |
326 |
|
} |
327 |
756
|
setLocationWithinModule(context + ".getList()"); |
328 |
756
|
result = predicate.calculate(getEntities(list)); |
329 |
|
} else { |
330 |
0
|
setLocationWithinModule(context + ".getList().getOperator()"); |
331 |
0
|
throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_OPERATOR_CODE, |
332 |
|
HeuristicErrorCodes.UNKNOWN_OPERATOR_TEXT + op, moduleContext); |
333 |
|
} |
334 |
483041
|
setLocationWithinModule(context); |
335 |
483041
|
if (Trace.isDebugEnabled(CLASS)) { |
336 |
0
|
deepness.setLength(deepness.length() > 0 ? deepness.length() - 1 : 0); |
337 |
0
|
Trace.param(CLASS, this, method, deepness.toString() + "result ", result); |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
483041
|
return result; |
344 |
|
} |
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
|
@param |
350 |
|
@return |
351 |
|
@throws |
352 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 4 |
Complexity Density: 0.21 |
|
353 |
52071
|
private boolean handleUniversalQuantifier(final ElementList list) throws HeuristicException {... |
354 |
52071
|
final String context = getLocationWithinModule(); |
355 |
52071
|
boolean result = true; |
356 |
52071
|
final ElementList variable = list.getElement(0).getList(); |
357 |
52071
|
final SubjectVariable var = new SubjectVariable(variable.getElement(0).getAtom().getString()); |
358 |
52071
|
subjectVariableInterpreter.addSubjectVariable(var); |
359 |
127735
|
for (int i = 0; i < model.getEntitiesSize(); i++) { |
360 |
|
|
361 |
|
|
362 |
|
|
363 |
|
|
364 |
115901
|
if (list.size() == 2) { |
365 |
115330
|
setLocationWithinModule(context + ".getList().getElement(1)"); |
366 |
115330
|
result &= calculateValue(list.getElement(1)); |
367 |
|
} else { |
368 |
571
|
setLocationWithinModule(context + ".getList().getElement(1)"); |
369 |
571
|
final boolean result1 = calculateValue(list.getElement(1)); |
370 |
571
|
setLocationWithinModule(context + ".getList().getElement(2)"); |
371 |
571
|
final boolean result2 = calculateValue(list.getElement(2)); |
372 |
571
|
result &= !result1 || result2; |
373 |
|
} |
374 |
115901
|
if (!result) { |
375 |
40237
|
break; |
376 |
|
} |
377 |
75664
|
subjectVariableInterpreter.increaseSubjectVariableSelection(var); |
378 |
|
} |
379 |
52071
|
subjectVariableInterpreter.removeSubjectVariable(var); |
380 |
52071
|
return result; |
381 |
|
} |
382 |
|
|
383 |
|
|
384 |
|
|
385 |
|
|
386 |
|
@param |
387 |
|
@return |
388 |
|
@throws |
389 |
|
|
|
|
| 76% |
Uncovered Elements: 6 (25) |
Complexity: 4 |
Complexity Density: 0.21 |
|
390 |
27194
|
private boolean handleExistentialQuantifier(final ElementList list) throws HeuristicException {... |
391 |
27194
|
final String context = getLocationWithinModule(); |
392 |
27194
|
boolean result = false; |
393 |
27194
|
final ElementList variable = list.getElement(0).getList(); |
394 |
27194
|
final SubjectVariable var = new SubjectVariable(variable.getElement(0).getAtom().getString()); |
395 |
27194
|
subjectVariableInterpreter.addSubjectVariable(var); |
396 |
91792
|
for (int i = 0; i < model.getEntitiesSize(); i++) { |
397 |
|
|
398 |
|
|
399 |
|
|
400 |
83521
|
if (list.size() == 2) { |
401 |
83521
|
setLocationWithinModule(context + ".getList().getElement(1)"); |
402 |
83521
|
result |= calculateValue(list.getElement(1)); |
403 |
|
} else { |
404 |
0
|
setLocationWithinModule(context + ".getList().getElement(1)"); |
405 |
0
|
final boolean result1 = calculateValue(list.getElement(1)); |
406 |
0
|
setLocationWithinModule(context + ".getList().getElement(2)"); |
407 |
0
|
final boolean result2 = calculateValue(list.getElement(2)); |
408 |
0
|
result |= result1 && result2; |
409 |
|
} |
410 |
83521
|
if (result) { |
411 |
18923
|
break; |
412 |
|
} |
413 |
64598
|
subjectVariableInterpreter.increaseSubjectVariableSelection(var); |
414 |
|
} |
415 |
27194
|
subjectVariableInterpreter.removeSubjectVariable(var); |
416 |
27194
|
return result; |
417 |
|
} |
418 |
|
|
419 |
|
|
420 |
|
|
421 |
|
|
422 |
|
@param |
423 |
|
@return |
424 |
|
@throws |
425 |
|
|
|
|
| 80.6% |
Uncovered Elements: 6 (31) |
Complexity: 5 |
Complexity Density: 0.22 |
|
426 |
11
|
private boolean handleUniqueExistentialQuantifier(final ElementList list) throws HeuristicException {... |
427 |
11
|
final String context = getLocationWithinModule(); |
428 |
11
|
boolean result = false; |
429 |
11
|
final ElementList variable = list.getElement(0).getList(); |
430 |
11
|
final SubjectVariable var = new SubjectVariable(variable.getElement(0).getAtom().getString()); |
431 |
11
|
subjectVariableInterpreter.addSubjectVariable(var); |
432 |
58
|
for (int i = 0; i < model.getEntitiesSize(); i++) { |
433 |
49
|
boolean val; |
434 |
49
|
if (list.size() == 2) { |
435 |
49
|
setLocationWithinModule(context + ".getList().getElement(1)"); |
436 |
49
|
val = calculateValue(list.getElement(1)); |
437 |
|
} else { |
438 |
0
|
setLocationWithinModule(context + ".getList().getElement(1)"); |
439 |
0
|
final boolean result1 = calculateValue(list.getElement(1)); |
440 |
0
|
setLocationWithinModule(context + ".getList().getElement(2)"); |
441 |
0
|
final boolean result2 = calculateValue(list.getElement(2)); |
442 |
0
|
val = result1 && result2; |
443 |
|
} |
444 |
49
|
if (val) { |
445 |
13
|
if (result) { |
446 |
2
|
result = false; |
447 |
2
|
break; |
448 |
|
} |
449 |
11
|
result = true; |
450 |
|
} |
451 |
47
|
subjectVariableInterpreter.increaseSubjectVariableSelection(var); |
452 |
|
} |
453 |
11
|
subjectVariableInterpreter.removeSubjectVariable(var); |
454 |
11
|
return result; |
455 |
|
} |
456 |
|
|
457 |
|
|
458 |
|
|
459 |
|
|
460 |
|
@param |
461 |
|
@return |
462 |
|
@throws |
463 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
464 |
284723
|
private Entity[] getEntities(final ElementList terms)... |
465 |
|
throws HeuristicException { |
466 |
284723
|
final String context = getLocationWithinModule(); |
467 |
284723
|
final Entity[] result = new Entity[terms.size() - 1]; |
468 |
561547
|
for (int i = 0; i < result.length; i++) { |
469 |
276824
|
setLocationWithinModule(context + ".getElement(" + (i + 1) + ")"); |
470 |
276824
|
result[i] = calculateTerm(terms.getElement(i + 1)); |
471 |
|
} |
472 |
284723
|
setLocationWithinModule(context); |
473 |
284723
|
return result; |
474 |
|
} |
475 |
|
|
476 |
|
|
477 |
|
|
478 |
|
|
479 |
|
|
480 |
|
@param |
481 |
|
@param |
482 |
|
@return |
483 |
|
@throws |
484 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
485 |
0
|
public Entity calculateTerm(final ModuleContext moduleContext, final Element term)... |
486 |
|
throws HeuristicException { |
487 |
|
|
488 |
0
|
this.moduleContext = moduleContext; |
489 |
|
|
490 |
0
|
return calculateTerm(term); |
491 |
|
} |
492 |
|
|
493 |
|
|
494 |
|
|
495 |
|
|
496 |
|
@param |
497 |
|
@return |
498 |
|
@throws |
499 |
|
|
|
|
| 50.5% |
Uncovered Elements: 48 (97) |
Complexity: 18 |
Complexity Density: 0.28 |
|
500 |
276824
|
private Entity calculateTerm(final Element term)... |
501 |
|
throws HeuristicException { |
502 |
276824
|
final String method = "calculateTerm(Element) "; |
503 |
276824
|
if (Trace.isDebugEnabled(CLASS)) { |
504 |
0
|
Trace.param(CLASS, this, method, deepness.toString() + "term ", term); |
505 |
0
|
deepness.append("-"); |
506 |
|
} |
507 |
276824
|
if (!term.isList()) { |
508 |
0
|
throw new RuntimeException("a term should be a list: " + term); |
509 |
|
} |
510 |
276824
|
final String context = getLocationWithinModule(); |
511 |
276824
|
final ElementList termList = term.getList(); |
512 |
276824
|
final String op = termList.getOperator(); |
513 |
276824
|
Entity result = null; |
514 |
276824
|
if (Operators.SUBJECT_VARIABLE.equals(op)) { |
515 |
276443
|
final String text = termList.getElement(0).getAtom().getString(); |
516 |
276443
|
final SubjectVariable var = new SubjectVariable(text); |
517 |
276443
|
result = subjectVariableInterpreter.getEntity(var); |
518 |
381
|
} else if (Operators.FUNCTION_VARIABLE.equals(op)) { |
519 |
368
|
final FunctionVariable var = new FunctionVariable(termList.getElement(0).getAtom().getString(), |
520 |
|
termList.size() - 1); |
521 |
368
|
Function function = functionVariableInterpreter.getFunction(var); |
522 |
368
|
setLocationWithinModule(context + ".getList()"); |
523 |
368
|
result = function.map(getEntities(termList)); |
524 |
13
|
} else if (Operators.FUNCTION_CONSTANT.equals(op)) { |
525 |
0
|
final String label = termList.getElement(0).getAtom().getString(); |
526 |
0
|
if (label.indexOf(".") >= 0) { |
527 |
0
|
final String shortName = label.substring(label.indexOf(".") + 1); |
528 |
0
|
final String external = label.substring(0, label.indexOf(".")); |
529 |
0
|
if (qedeq.getKernelRequiredModules() != null) { |
530 |
0
|
final KernelQedeqBo newProp = qedeq.getKernelRequiredModules().getKernelQedeqBo(external); |
531 |
0
|
if (newProp != null) { |
532 |
0
|
FunctionDefinition definition = newProp.getLabels().getFunction(shortName, |
533 |
|
termList.size() - 1); |
534 |
0
|
if (definition != null) { |
535 |
0
|
setLocationWithinModule(context + ".getList()"); |
536 |
0
|
result = calculateFunctionValue(qedeq, definition, getEntities(termList)); |
537 |
|
} |
538 |
|
} else { |
539 |
0
|
setLocationWithinModule(context + ".getList().getOperator()"); |
540 |
0
|
throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_FUNCTION_CONSTANT_CODE, |
541 |
|
HeuristicErrorCodes.UNKNOWN_FUNCTION_CONSTANT_TEXT + shortName, moduleContext); |
542 |
|
} |
543 |
|
} else { |
544 |
0
|
setLocationWithinModule(context + ".getList().getOperator()"); |
545 |
0
|
throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_FUNCTION_CONSTANT_CODE, |
546 |
|
HeuristicErrorCodes.UNKNOWN_FUNCTION_CONSTANT_TEXT + label, moduleContext); |
547 |
|
} |
548 |
|
} else { |
549 |
0
|
final ModelFunctionConstant var = new ModelFunctionConstant(label, |
550 |
|
termList.size() - 1); |
551 |
0
|
Function function = model.getFunctionConstant(var); |
552 |
0
|
if (function == null) { |
553 |
0
|
setLocationWithinModule(context + ".getList().getOperator()"); |
554 |
0
|
throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_FUNCTION_CONSTANT_CODE, |
555 |
|
HeuristicErrorCodes.UNKNOWN_FUNCTION_CONSTANT_TEXT + var, moduleContext); |
556 |
|
} |
557 |
0
|
setLocationWithinModule(context + ".getList()"); |
558 |
0
|
result = function.map(getEntities(termList)); |
559 |
|
} |
560 |
13
|
} else if (Operators.CLASS_OP.equals(op)) { |
561 |
13
|
List fullfillers = new ArrayList(); |
562 |
13
|
ElementList variable = termList.getElement(0).getList(); |
563 |
13
|
final SubjectVariable var = new SubjectVariable(variable.getElement(0).getAtom().getString()); |
564 |
13
|
subjectVariableInterpreter.addSubjectVariable(var); |
565 |
13
|
final ModelPredicateConstant isSetPredicate = new ModelPredicateConstant("isSet", 1); |
566 |
13
|
Predicate isSet = model.getPredicateConstant(isSetPredicate); |
567 |
13
|
if (isSet == null) { |
568 |
0
|
throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_TERM_OPERATOR_CODE, |
569 |
|
HeuristicErrorCodes.UNKNOWN_TERM_OPERATOR_TEXT + "isSet(*)", moduleContext); |
570 |
|
} |
571 |
52
|
for (int i = 0; i < model.getEntitiesSize(); i++) { |
572 |
39
|
setLocationWithinModule(context + ".getList().getElement(1)"); |
573 |
39
|
if (calculateValue(termList.getElement(1)) |
574 |
|
&& isSet.calculate(new Entity[] {model.getEntity(i)})) { |
575 |
13
|
fullfillers.add(model.getEntity(i)); |
576 |
|
} |
577 |
39
|
subjectVariableInterpreter.increaseSubjectVariableSelection(var); |
578 |
|
} |
579 |
13
|
result = model.comprehension((Entity[]) fullfillers.toArray(new Entity[] {})); |
580 |
13
|
subjectVariableInterpreter.removeSubjectVariable(var); |
581 |
|
} else { |
582 |
0
|
setLocationWithinModule(context + ".getList().getOperator()"); |
583 |
0
|
throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_TERM_OPERATOR_CODE, |
584 |
|
HeuristicErrorCodes.UNKNOWN_TERM_OPERATOR_TEXT + op, moduleContext); |
585 |
|
} |
586 |
276824
|
setLocationWithinModule(context); |
587 |
276824
|
if (Trace.isDebugEnabled(CLASS)) { |
588 |
0
|
deepness.setLength(deepness.length() > 0 ? deepness.length() - 1 : 0); |
589 |
0
|
Trace.param(CLASS, this, method, deepness.toString() + "result ", result); |
590 |
|
} |
591 |
276824
|
return result; |
592 |
|
} |
593 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
594 |
1123864
|
private String getLocationWithinModule() {... |
595 |
1123864
|
return moduleContext.getLocationWithinModule(); |
596 |
|
} |
597 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
598 |
2566937
|
private void setLocationWithinModule(final String localContext) {... |
599 |
2566937
|
moduleContext.setLocationWithinModule(localContext); |
600 |
|
|
601 |
|
|
602 |
|
|
603 |
|
|
604 |
|
|
605 |
|
|
606 |
|
|
607 |
|
|
608 |
|
|
609 |
|
|
610 |
|
|
611 |
|
|
612 |
|
|
613 |
|
|
614 |
|
|
615 |
|
|
616 |
|
|
617 |
|
|
618 |
|
|
619 |
|
|
620 |
|
|
621 |
|
} |
622 |
|
|
623 |
|
|
624 |
|
|
625 |
|
|
626 |
|
@return |
627 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
628 |
5185
|
public boolean next() {... |
629 |
5185
|
return subjectVariableInterpreter.next() || predicateVariableInterpreter.next() |
630 |
|
|| functionVariableInterpreter.next(); |
631 |
|
} |
632 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
633 |
0
|
public String toString() {... |
634 |
0
|
final StringBuffer buffer = new StringBuffer(); |
635 |
0
|
buffer.append("Current interpretation:\n"); |
636 |
0
|
buffer.append("\t" + predicateVariableInterpreter + "\n"); |
637 |
0
|
buffer.append("\t" + subjectVariableInterpreter + "\n"); |
638 |
0
|
buffer.append("\t" + functionVariableInterpreter); |
639 |
0
|
return buffer.toString(); |
640 |
|
} |
641 |
|
|
642 |
|
|
643 |
|
|
644 |
|
|
645 |
|
@param |
646 |
|
@return |
647 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
648 |
756
|
public String stripReference(final String operator) {... |
649 |
756
|
final int index = operator.lastIndexOf("."); |
650 |
756
|
if (index >= 0 && index + 1 < operator.length()) { |
651 |
9
|
return operator.substring(index + 1); |
652 |
|
} |
653 |
747
|
return operator; |
654 |
|
} |
655 |
|
|
656 |
|
|
657 |
|
|
658 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
659 |
45
|
public void clearVariables() {... |
660 |
45
|
subjectVariableInterpreter.clear(); |
661 |
45
|
predicateVariableInterpreter.clear(); |
662 |
45
|
functionVariableInterpreter.clear(); |
663 |
|
} |
664 |
|
|
665 |
|
} |