|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
DynamicInterpreter | Line # 43 | 258 | 83 | 70.2% |
0.70153064
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
(90) | |||
Result | |||
0.46173468
|
org.qedeq.kernel.bo.logic.model.CalculateTruthDynamicThreeModelTest.testTautology44 org.qedeq.kernel.bo.logic.model.CalculateTruthDynamicThreeModelTest.testTautology44 | 1 PASS | |
0.4515306
|
org.qedeq.kernel.bo.logic.model.CalculateTruthDynamicThreeModelTest.testTautology44b org.qedeq.kernel.bo.logic.model.CalculateTruthDynamicThreeModelTest.testTautology44b | 1 PASS | |
0.4107143
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology40 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology40 | 1 PASS | |
0.4005102
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology40 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology40 | 1 PASS | |
0.35714287
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology43 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology43 | 1 PASS | |
0.3265306
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology32 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology32 | 1 PASS | |
0.31632653
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology32 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology32 | 1 PASS | |
0.30357143
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology39 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology39 | 1 PASS | |
0.2984694
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology38 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology38 | 1 PASS | |
0.29336736
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology39 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology39 | 1 PASS | |
0.29081634
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology33 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology33 | 1 PASS | |
0.28826532
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology34 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology34 | 1 PASS | |
0.28826532
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology38 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology38 | 1 PASS | |
0.2857143
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology41 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology41 | 1 PASS | |
0.28061223
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology33 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology33 | 1 PASS | |
0.2780612
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology34 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology34 | 1 PASS | |
0.2755102
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology35 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology35 | 1 PASS | |
0.2755102
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology41 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology41 | 1 PASS | |
0.27295917
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology28 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology28 | 1 PASS | |
0.27295917
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology42 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology42 | 1 PASS | |
0.27040815
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology52 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology52 | 1 PASS | |
0.26785713
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology27 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology27 | 1 PASS | |
0.26785713
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology29 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology29 | 1 PASS | |
0.26530612
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology35 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology35 | 1 PASS | |
0.2627551
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology42 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology42 | 1 PASS | |
0.2627551
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology28 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology28 | 1 PASS | |
0.26020408
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology31 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology31 | 1 PASS | |
0.25765306
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology27 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology27 | 1 PASS | |
0.25765306
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology29 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology29 | 1 PASS | |
0.25510204
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology30 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology30 | 1 PASS | |
0.25
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology31 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology31 | 1 PASS | |
0.24489796
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology36 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology36 | 1 PASS | |
0.24489796
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology30 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology30 | 1 PASS | |
0.24489796
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology37 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology37 | 1 PASS | |
0.24234694
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology51 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology51 | 1 PASS | |
0.23469388
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology37 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology37 | 1 PASS | |
0.23469388
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology36 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology36 | 1 PASS | |
0.2244898
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology23 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology23 | 1 PASS | |
0.2244898
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology20 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology20 | 1 PASS | |
0.2244898
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology21 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology21 | 1 PASS | |
0.2244898
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology19 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology19 | 1 PASS | |
0.2244898
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology22 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology22 | 1 PASS | |
0.21938775
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology18 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology18 | 1 PASS | |
0.21683674
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology17 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology17 | 1 PASS | |
0.21428572
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology22 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology22 | 1 PASS | |
0.21428572
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology23 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology23 | 1 PASS | |
0.21428572
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology20 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology20 | 1 PASS | |
0.21428572
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology21 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology21 | 1 PASS | |
0.21428572
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology19 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology19 | 1 PASS | |
0.2117347
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology26 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology26 | 1 PASS | |
0.20918368
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology18 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology18 | 1 PASS | |
0.20663266
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology17 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology17 | 1 PASS | |
0.20408164
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology16 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology16 | 1 PASS | |
0.2015306
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology26 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology26 | 1 PASS | |
0.19387755
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology16 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology16 | 1 PASS | |
0.19132653
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology11 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology11 | 1 PASS | |
0.19132653
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology12 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology12 | 1 PASS | |
0.19132653
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology10 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology10 | 1 PASS | |
0.18112245
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology08 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology08 | 1 PASS | |
0.18112245
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology12 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology12 | 1 PASS | |
0.18112245
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology10 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology10 | 1 PASS | |
0.18112245
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology15 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology15 | 1 PASS | |
0.18112245
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology11 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology11 | 1 PASS | |
0.18112245
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology14 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology14 | 1 PASS | |
0.1734694
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology13 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology13 | 1 PASS | |
0.1734694
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology09 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology09 | 1 PASS | |
0.1734694
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology04 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology04 | 1 PASS | |
0.1734694
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology07 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology07 | 1 PASS | |
0.17091836
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology14 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology14 | 1 PASS | |
0.17091836
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology08 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology08 | 1 PASS | |
0.17091836
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology15 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology15 | 1 PASS | |
0.16836734
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology05 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology05 | 1 PASS | |
0.16836734
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology24 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology24 | 1 PASS | |
0.1632653
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology02 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology02 | 1 PASS | |
0.1632653
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology07 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology07 | 1 PASS | |
0.1632653
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology04 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology04 | 1 PASS | |
0.1632653
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology09 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology09 | 1 PASS | |
0.1632653
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology13 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology13 | 1 PASS | |
0.15816326
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology03 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology03 | 1 PASS | |
0.15816326
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology05 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology05 | 1 PASS | |
0.15816326
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology24 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology24 | 1 PASS | |
0.15561225
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology25 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology25 | 1 PASS | |
0.15561225
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology06 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology06 | 1 PASS | |
0.15306123
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology02 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology02 | 1 PASS | |
0.15306123
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology50 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology50 | 1 PASS | |
0.14795919
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology03 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology03 | 1 PASS | |
0.14540817
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology06 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology06 | 1 PASS | |
0.14540817
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology25 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology25 | 1 PASS | |
0.14030612
|
org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology01 org.qedeq.kernel.bo.logic.model.CalculateTruthTestCase.testTautology01 | 1 PASS | |
0.13010204
|
org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology01 org.qedeq.kernel.bo.logic.model.DynamicInterpreterTest.testTautology01 | 1 PASS | |
1 | /* This file is part of the project "Hilbert II" - http://www.qedeq.org | |
2 | * | |
3 | * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>. | |
4 | * | |
5 | * "Hilbert II" is free software; you can redistribute | |
6 | * it and/or modify it under the terms of the GNU General Public | |
7 | * License as published by the Free Software Foundation; either | |
8 | * version 2 of the License, or (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
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.se.base.list.Element; | |
31 | import org.qedeq.kernel.se.base.list.ElementList; | |
32 | import org.qedeq.kernel.se.base.module.FunctionDefinition; | |
33 | import org.qedeq.kernel.se.base.module.PredicateDefinition; | |
34 | import org.qedeq.kernel.se.common.DefaultModuleAddress; | |
35 | import org.qedeq.kernel.se.common.ModuleContext; | |
36 | ||
37 | ||
38 | /** | |
39 | * This class calculates a new truth value for a given formula for a given interpretation. | |
40 | * | |
41 | * @author Michael Meyling | |
42 | */ | |
43 | public class DynamicInterpreter { | |
44 | ||
45 | /** This class. */ | |
46 | private static final Class CLASS = DynamicInterpreter.class; | |
47 | ||
48 | /** Model contains entities, functions, predicates. */ | |
49 | private final DynamicModel model; | |
50 | ||
51 | /** Interpret subject variables. */ | |
52 | private final SubjectVariableInterpreter subjectVariableInterpreter; | |
53 | ||
54 | /** Interpret predicate variables. */ | |
55 | private final PredicateVariableInterpreter predicateVariableInterpreter; | |
56 | ||
57 | /** Interpret function variables. */ | |
58 | private final FunctionVariableInterpreter functionVariableInterpreter; | |
59 | ||
60 | /** Module context. Here were are currently. */ | |
61 | private ModuleContext moduleContext; | |
62 | ||
63 | /** For formatting debug trace output. */ | |
64 | private final StringBuffer deepness = new StringBuffer(); | |
65 | ||
66 | /** QEDEQ module we check. */ | |
67 | private final KernelQedeqBo qedeq; | |
68 | ||
69 | /** | |
70 | * Constructor. | |
71 | * | |
72 | * @param model We work with this model. | |
73 | * @param qedeq And we work within this module. | |
74 | */ | |
75 | 93 | public DynamicInterpreter(final DynamicModel model, final KernelQedeqBo qedeq) { |
76 | 93 | this.model = model; |
77 | 93 | subjectVariableInterpreter = new SubjectVariableInterpreter(model); |
78 | 93 | predicateVariableInterpreter = new PredicateVariableInterpreter(model); |
79 | 93 | functionVariableInterpreter = new FunctionVariableInterpreter(model); |
80 | 93 | this.qedeq = qedeq; |
81 | } | |
82 | ||
83 | /** | |
84 | * Get model. | |
85 | * | |
86 | * @return Model we work with. | |
87 | */ | |
88 | 0 | public DynamicModel getModel() { |
89 | 0 | return model; |
90 | } | |
91 | ||
92 | /** | |
93 | * Add new predicate constant to this model. | |
94 | * | |
95 | * @param constant This is the predicate constant. | |
96 | * @param variables Variables to use. | |
97 | * @param formula Formula to evaluate for that predicate. | |
98 | */ | |
99 | 3 | public void addPredicateConstant(final ModelPredicateConstant constant, |
100 | final List variables, final ElementList formula) { | |
101 | 3 | model.addPredicateConstant(constant, new Predicate(constant.getArgumentNumber(), |
102 | constant.getArgumentNumber(), "", "") { | |
103 | 55 | public boolean calculate(final Entity[] entities) { |
104 | 108 | for (int i = 0; i < entities.length; i++) { |
105 | 53 | final SubjectVariable var = (SubjectVariable) variables.get(i); |
106 | 53 | subjectVariableInterpreter.forceAddSubjectVariable(var, entities[i].getValue()); |
107 | } | |
108 | 55 | boolean result; |
109 | 55 | try { |
110 | 55 | result = calculateValue(new ModuleContext(new DefaultModuleAddress()), formula); |
111 | } catch (HeuristicException e) { | |
112 | 0 | throw new RuntimeException(e); // LATER 20101014 m31: improve error handling |
113 | } | |
114 | 108 | for (int i = entities.length - 1; i >= 0; i--) { |
115 | 53 | final SubjectVariable var = (SubjectVariable) variables.get(i); |
116 | 53 | subjectVariableInterpreter.forceRemoveSubjectVariable(var); |
117 | } | |
118 | // System.out.print(constant.getName() + "("); | |
119 | // for (int i = 0; i < entities.length; i++) { | |
120 | // if (i > 0) { | |
121 | // System.out.print(", "); | |
122 | // } | |
123 | // System.out.print(entities[i]); | |
124 | // } | |
125 | // System.out.println(") = " + result); | |
126 | 55 | return result; |
127 | } | |
128 | }); | |
129 | } | |
130 | ||
131 | /** | |
132 | * Calculate predicate value. | |
133 | * | |
134 | * @param qedeq Predicate constant is defined in this QEDEQ module. | |
135 | * @param constant This is the predicate definition. | |
136 | * @param entities Predicate arguments. | |
137 | * @return Result of calculation; | |
138 | * @throws HeuristicException Calculation failed. | |
139 | */ | |
140 | 0 | public boolean calculatPredicateValue(final KernelQedeqBo qedeq, final PredicateDefinition constant, |
141 | final Entity[] entities) throws HeuristicException { | |
142 | 0 | DynamicDirectInterpreter inter = new DynamicDirectInterpreter(qedeq, model, |
143 | subjectVariableInterpreter, predicateVariableInterpreter, functionVariableInterpreter); | |
144 | 0 | return inter.calculatePredicateValue( |
145 | new PredicateConstant(new PredicateKey(constant.getName(), constant.getName()), | |
146 | constant.getFormula().getElement().getList(), | |
147 | new ModuleContext(qedeq.getModuleAddress())), entities); | |
148 | } | |
149 | ||
150 | /** | |
151 | * Add new function constant to this model. | |
152 | * | |
153 | * @param constant This is the predicate constant. | |
154 | * @param variables Subject variables to use. | |
155 | * @param term Formula to evaluate for that predicate. | |
156 | */ | |
157 | 0 | public void addFunctionConstant(final ModelFunctionConstant constant, |
158 | final List variables, final ElementList term) { | |
159 | 0 | model.addFunctionConstant(constant, new Function(constant.getArgumentNumber(), |
160 | constant.getArgumentNumber(), "", "") { | |
161 | 0 | public Entity map(final Entity[] entities) { |
162 | 0 | for (int i = 0; i < entities.length; i++) { |
163 | 0 | final SubjectVariable var = (SubjectVariable) variables.get(i); |
164 | 0 | subjectVariableInterpreter.forceAddSubjectVariable(var, entities[i].getValue()); |
165 | } | |
166 | 0 | Entity result; |
167 | 0 | try { |
168 | 0 | result = calculateTerm(new ModuleContext(new DefaultModuleAddress()), term); |
169 | } catch (HeuristicException e) { | |
170 | 0 | throw new RuntimeException(e); // LATER 20101014 m31: improve error handling |
171 | } | |
172 | 0 | for (int i = entities.length - 1; i >= 0; i--) { |
173 | 0 | final SubjectVariable var = (SubjectVariable) variables.get(i); |
174 | 0 | subjectVariableInterpreter.forceRemoveSubjectVariable(var); |
175 | } | |
176 | 0 | return result; |
177 | } | |
178 | }); | |
179 | } | |
180 | ||
181 | /** | |
182 | * Calculate function value. | |
183 | * | |
184 | * @param qedeq Function constant is defined in this QEDEQ module. | |
185 | * @param constant This is the function definition. | |
186 | * @param entities Function arguments. | |
187 | * @return Result of calculation; | |
188 | * @throws HeuristicException Calculation failed. | |
189 | */ | |
190 | 0 | public Entity calculateFunctionValue(final KernelQedeqBo qedeq, final FunctionDefinition constant, |
191 | final Entity[] entities) throws HeuristicException { | |
192 | 0 | DynamicDirectInterpreter inter = new DynamicDirectInterpreter(qedeq, model, |
193 | subjectVariableInterpreter, predicateVariableInterpreter, functionVariableInterpreter); | |
194 | 0 | return inter.calculateFunctionValue( |
195 | new FunctionConstant(new FunctionKey(constant.getName(), constant.getName()), | |
196 | constant.getFormula().getElement().getList(), | |
197 | new ModuleContext(qedeq.getModuleAddress())), entities); | |
198 | } | |
199 | ||
200 | /** | |
201 | * Is the given predicate constant already defined? | |
202 | * | |
203 | * @param constant Predicate constant to check for. | |
204 | * @return Is the given predicate constant already defined? | |
205 | */ | |
206 | 0 | public boolean hasPredicateConstant(final ModelPredicateConstant constant) { |
207 | 0 | return null != model.getPredicateConstant(constant); |
208 | } | |
209 | ||
210 | /** | |
211 | * Is the given function constant already defined? | |
212 | * | |
213 | * @param constant Function constant to check for. | |
214 | * @return Is the given function constant already defined? | |
215 | */ | |
216 | 0 | public boolean hasFunctionConstant(final ModelFunctionConstant constant) { |
217 | 0 | return null != model.getFunctionConstant(constant); |
218 | } | |
219 | ||
220 | /** | |
221 | * Calculate the truth value of a given formula is a tautology. This is done by checking with | |
222 | * a model and certain variable values. | |
223 | * | |
224 | * @param moduleContext Where we are within an module. | |
225 | * @param formula Formula. | |
226 | * @return Truth value of formula. | |
227 | * @throws HeuristicException We couldn't calculate the value. | |
228 | */ | |
229 | 5280 | public boolean calculateValue(final ModuleContext moduleContext, final Element formula) |
230 | throws HeuristicException { | |
231 | // this.startElement = formula; | |
232 | 5280 | this.moduleContext = moduleContext; |
233 | // this.startContext = new ModuleContext(moduleContext); | |
234 | 5280 | return calculateValue(formula); |
235 | } | |
236 | ||
237 | /** | |
238 | * Calculate the truth value of a given formula is a tautology. This is done by checking with | |
239 | * a model and certain variable values. | |
240 | * | |
241 | * @param formula Formula. | |
242 | * @return Truth value of formula. | |
243 | * @throws HeuristicException We couldn't calculate the value. | |
244 | */ | |
245 | 483041 | private boolean calculateValue(final Element formula) throws HeuristicException { |
246 | 483041 | final String method = "calculateValue(Element)"; |
247 | // System.out.println(deepness.toString() + Latex2Utf8Parser.transform(null, | |
248 | // qedeq.getElement2Latex().getLatex(formula), 0)); | |
249 | // deepness.append("-"); | |
250 | 483041 | if (Trace.isDebugEnabled(CLASS)) { |
251 | 0 | Trace.param(CLASS, this, method, deepness.toString() + "formula", formula); |
252 | 0 | deepness.append("-"); |
253 | } | |
254 | 483041 | if (formula.isAtom()) { |
255 | 0 | throw new HeuristicException(HeuristicErrorCodes.WRONG_CALLING_CONVENTION_CODE, |
256 | HeuristicErrorCodes.WRONG_CALLING_CONVENTION_TEXT, moduleContext); | |
257 | } | |
258 | 483041 | final String context = getLocationWithinModule(); |
259 | 483041 | setLocationWithinModule(context + ".getList()"); |
260 | 483041 | final ElementList list = formula.getList(); |
261 | 483041 | final String op = list.getOperator(); |
262 | 483041 | boolean result; |
263 | 483041 | if (Operators.CONJUNCTION_OPERATOR.equals(op)) { |
264 | 20372 | result = true; |
265 | 83964 | for (int i = 0; i < list.size(); i++) { |
266 | 63592 | setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
267 | 63592 | result &= calculateValue(list.getElement(i)); |
268 | } | |
269 | 462669 | } else if (Operators.DISJUNCTION_OPERATOR.equals(op)) { |
270 | 22184 | result = false; |
271 | 82936 | for (int i = 0; i < list.size(); i++) { |
272 | 60752 | setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
273 | 60752 | result |= calculateValue(list.getElement(i)); |
274 | } | |
275 | 440485 | } else if (Operators.EQUIVALENCE_OPERATOR.equals(op)) { |
276 | 26592 | result = true; |
277 | 26592 | boolean value = false; |
278 | 79776 | for (int i = 0; i < list.size(); i++) { |
279 | 53184 | if (i > 0) { |
280 | 26592 | setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
281 | 26592 | if (value != calculateValue(list.getElement(i))) { |
282 | 4708 | result = false; |
283 | } | |
284 | } else { | |
285 | 26592 | setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
286 | 26592 | value = calculateValue(list.getElement(i)); |
287 | } | |
288 | } | |
289 | 413893 | } else if (Operators.IMPLICATION_OPERATOR.equals(op)) { |
290 | 49890 | result = false; |
291 | 149670 | for (int i = 0; i < list.size(); i++) { |
292 | 99780 | setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
293 | 99780 | if (i < list.size() - 1) { |
294 | 49890 | result |= !calculateValue(list.getElement(i)); |
295 | } else { | |
296 | 49890 | result |= calculateValue(list.getElement(i)); |
297 | } | |
298 | } | |
299 | 364003 | } else if (Operators.NEGATION_OPERATOR.equals(op)) { |
300 | 372 | result = true; |
301 | 744 | for (int i = 0; i < list.size(); i++) { |
302 | 372 | setLocationWithinModule(context + ".getList().getElement(" + i + ")"); |
303 | 372 | result &= !calculateValue(list.getElement(i)); |
304 | } | |
305 | 363631 | } else if (Operators.PREDICATE_VARIABLE.equals(op)) { |
306 | 283599 | final PredicateVariable var = new PredicateVariable(list.getElement(0).getAtom().getString(), |
307 | list.size() - 1); | |
308 | 283599 | setLocationWithinModule(context + ".getList()"); |
309 | 283599 | result = predicateVariableInterpreter.getPredicate(var) |
310 | .calculate(getEntities(list)); | |
311 | 80032 | } else if (Operators.UNIVERSAL_QUANTIFIER_OPERATOR.equals(op)) { |
312 | 52071 | result = handleUniversalQuantifier(list); |
313 | 27961 | } else if (Operators.EXISTENTIAL_QUANTIFIER_OPERATOR.equals(op)) { |
314 | 27194 | result = handleExistentialQuantifier(list); |
315 | 767 | } else if (Operators.UNIQUE_EXISTENTIAL_QUANTIFIER_OPERATOR.equals(op)) { |
316 | 11 | result = handleUniqueExistentialQuantifier(list); |
317 | 756 | } else if (Operators.PREDICATE_CONSTANT.equals(op)) { |
318 | 756 | final String text = stripReference(list.getElement(0).getAtom().getString()); |
319 | 756 | final ModelPredicateConstant var = new ModelPredicateConstant(text, |
320 | list.size() - 1); | |
321 | 756 | Predicate predicate = model.getPredicateConstant(var); |
322 | 756 | if (predicate == null) { |
323 | ||
324 | 0 | setLocationWithinModule(context + ".getList().getOperator()"); |
325 | 0 | throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_PREDICATE_CONSTANT_CODE, |
326 | HeuristicErrorCodes.UNKNOWN_PREDICATE_CONSTANT_TEXT + var, moduleContext); | |
327 | } | |
328 | 756 | setLocationWithinModule(context + ".getList()"); |
329 | 756 | result = predicate.calculate(getEntities(list)); |
330 | } else { | |
331 | 0 | setLocationWithinModule(context + ".getList().getOperator()"); |
332 | 0 | throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_OPERATOR_CODE, |
333 | HeuristicErrorCodes.UNKNOWN_OPERATOR_TEXT + op, moduleContext); | |
334 | } | |
335 | 483041 | setLocationWithinModule(context); |
336 | 483041 | if (Trace.isDebugEnabled(CLASS)) { |
337 | 0 | deepness.setLength(deepness.length() > 0 ? deepness.length() - 1 : 0); |
338 | 0 | Trace.param(CLASS, this, method, deepness.toString() + "result ", result); |
339 | } | |
340 | // deepness.setLength(deepness.length() > 0 ? deepness.length() - 1 : 0); | |
341 | // System.out.print(deepness.toString() + Latex2Utf8Parser.transform(null, | |
342 | // qedeq.getElement2Latex().getLatex(formula), 0)); | |
343 | // System.out.println("=" + result); | |
344 | 483041 | return result; |
345 | } | |
346 | ||
347 | /** | |
348 | * Handle universal quantifier operator. | |
349 | * | |
350 | * @param list Work on this formula. | |
351 | * @return result Calculated truth value. | |
352 | * @throws HeuristicException Calculation not possible. | |
353 | */ | |
354 | 52071 | private boolean handleUniversalQuantifier(final ElementList list) throws HeuristicException { |
355 | 52071 | final String context = getLocationWithinModule(); |
356 | 52071 | boolean result = true; |
357 | 52071 | final ElementList variable = list.getElement(0).getList(); |
358 | 52071 | final SubjectVariable var = new SubjectVariable(variable.getElement(0).getAtom().getString()); |
359 | 52071 | subjectVariableInterpreter.addSubjectVariable(var); |
360 | 127735 | for (int i = 0; i < model.getEntitiesSize(); i++) { |
361 | // System.out.print(deepness.toString() + Latex2Utf8Parser.transform(null, | |
362 | // qedeq.getElement2Latex().getLatex(variable), 0)); | |
363 | // System.out.println("=" + model.getEntity(i)); | |
364 | ||
365 | 115901 | if (list.size() == 2) { |
366 | 115330 | setLocationWithinModule(context + ".getList().getElement(1)"); |
367 | 115330 | result &= calculateValue(list.getElement(1)); |
368 | } else { // must be 3 | |
369 | 571 | setLocationWithinModule(context + ".getList().getElement(1)"); |
370 | 571 | final boolean result1 = calculateValue(list.getElement(1)); |
371 | 571 | setLocationWithinModule(context + ".getList().getElement(2)"); |
372 | 571 | final boolean result2 = calculateValue(list.getElement(2)); |
373 | 571 | result &= !result1 || result2; |
374 | } | |
375 | 115901 | if (!result) { |
376 | 40237 | break; |
377 | } | |
378 | 75664 | subjectVariableInterpreter.increaseSubjectVariableSelection(var); |
379 | } | |
380 | 52071 | subjectVariableInterpreter.removeSubjectVariable(var); |
381 | 52071 | return result; |
382 | } | |
383 | ||
384 | /** | |
385 | * Handle existential quantifier operator. | |
386 | * | |
387 | * @param list Work on this formula. | |
388 | * @return result Calculated truth value. | |
389 | * @throws HeuristicException Calculation not possible. | |
390 | */ | |
391 | 27194 | private boolean handleExistentialQuantifier(final ElementList list) throws HeuristicException { |
392 | 27194 | final String context = getLocationWithinModule(); |
393 | 27194 | boolean result = false; |
394 | 27194 | final ElementList variable = list.getElement(0).getList(); |
395 | 27194 | final SubjectVariable var = new SubjectVariable(variable.getElement(0).getAtom().getString()); |
396 | 27194 | subjectVariableInterpreter.addSubjectVariable(var); |
397 | 91792 | for (int i = 0; i < model.getEntitiesSize(); i++) { |
398 | // System.out.print(deepness.toString() + Latex2Utf8Parser.transform(null, | |
399 | // qedeq.getElement2Latex().getLatex(variable), 0)); | |
400 | // System.out.println("=" + model.getEntity(i)); | |
401 | 83521 | if (list.size() == 2) { |
402 | 83521 | setLocationWithinModule(context + ".getList().getElement(1)"); |
403 | 83521 | result |= calculateValue(list.getElement(1)); |
404 | } else { // must be 3 | |
405 | 0 | setLocationWithinModule(context + ".getList().getElement(1)"); |
406 | 0 | final boolean result1 = calculateValue(list.getElement(1)); |
407 | 0 | setLocationWithinModule(context + ".getList().getElement(2)"); |
408 | 0 | final boolean result2 = calculateValue(list.getElement(2)); |
409 | 0 | result |= result1 && result2; |
410 | } | |
411 | 83521 | if (result) { |
412 | 18923 | break; |
413 | } | |
414 | 64598 | subjectVariableInterpreter.increaseSubjectVariableSelection(var); |
415 | } | |
416 | 27194 | subjectVariableInterpreter.removeSubjectVariable(var); |
417 | 27194 | return result; |
418 | } | |
419 | ||
420 | /** | |
421 | * Handle unique existential quantifier operator. | |
422 | * | |
423 | * @param list Work on this formula. | |
424 | * @return result Calculated truth value. | |
425 | * @throws HeuristicException Calculation not possible. | |
426 | */ | |
427 | 11 | private boolean handleUniqueExistentialQuantifier(final ElementList list) throws HeuristicException { |
428 | 11 | final String context = getLocationWithinModule(); |
429 | 11 | boolean result = false; |
430 | 11 | final ElementList variable = list.getElement(0).getList(); |
431 | 11 | final SubjectVariable var = new SubjectVariable(variable.getElement(0).getAtom().getString()); |
432 | 11 | subjectVariableInterpreter.addSubjectVariable(var); |
433 | 58 | for (int i = 0; i < model.getEntitiesSize(); i++) { |
434 | 49 | boolean val; |
435 | 49 | if (list.size() == 2) { |
436 | 49 | setLocationWithinModule(context + ".getList().getElement(1)"); |
437 | 49 | val = calculateValue(list.getElement(1)); |
438 | } else { // must be 3 | |
439 | 0 | setLocationWithinModule(context + ".getList().getElement(1)"); |
440 | 0 | final boolean result1 = calculateValue(list.getElement(1)); |
441 | 0 | setLocationWithinModule(context + ".getList().getElement(2)"); |
442 | 0 | final boolean result2 = calculateValue(list.getElement(2)); |
443 | 0 | val = result1 && result2; |
444 | } | |
445 | 49 | if (val) { |
446 | 13 | if (result) { |
447 | 2 | result = false; |
448 | 2 | break; |
449 | } | |
450 | 11 | result = true; |
451 | } | |
452 | 47 | subjectVariableInterpreter.increaseSubjectVariableSelection(var); |
453 | } | |
454 | 11 | subjectVariableInterpreter.removeSubjectVariable(var); |
455 | 11 | return result; |
456 | } | |
457 | ||
458 | /** | |
459 | * Interpret terms. | |
460 | * | |
461 | * @param terms Interpret these terms. The first entry is stripped. | |
462 | * @return Values. | |
463 | * @throws HeuristicException evaluation failed. | |
464 | */ | |
465 | 284723 | private Entity[] getEntities(final ElementList terms) |
466 | throws HeuristicException { | |
467 | 284723 | final String context = getLocationWithinModule(); |
468 | 284723 | final Entity[] result = new Entity[terms.size() - 1]; // strip first argument |
469 | 561547 | for (int i = 0; i < result.length; i++) { |
470 | 276824 | setLocationWithinModule(context + ".getElement(" + (i + 1) + ")"); |
471 | 276824 | result[i] = calculateTerm(terms.getElement(i + 1)); |
472 | } | |
473 | 284723 | setLocationWithinModule(context); |
474 | 284723 | return result; |
475 | } | |
476 | ||
477 | /** | |
478 | * Calculate the term value of a given term. This is done by checking with | |
479 | * a model and certain variable values. | |
480 | * | |
481 | * @param moduleContext Where we are within an module. | |
482 | * @param term Term. | |
483 | * @return Entity of model. | |
484 | * @throws HeuristicException We couldn't calculate the value. | |
485 | */ | |
486 | 0 | public Entity calculateTerm(final ModuleContext moduleContext, final Element term) |
487 | throws HeuristicException { | |
488 | // this.startElement = formula; | |
489 | 0 | this.moduleContext = moduleContext; |
490 | // this.startContext = new ModuleContext(moduleContext); | |
491 | 0 | return calculateTerm(term); |
492 | } | |
493 | ||
494 | /** | |
495 | * Interpret term. | |
496 | * | |
497 | * @param term Interpret this term. | |
498 | * @return Value. | |
499 | * @throws HeuristicException evaluation failed. | |
500 | */ | |
501 | 276824 | private Entity calculateTerm(final Element term) |
502 | throws HeuristicException { | |
503 | 276824 | final String method = "calculateTerm(Element) "; |
504 | 276824 | if (Trace.isDebugEnabled(CLASS)) { |
505 | 0 | Trace.param(CLASS, this, method, deepness.toString() + "term ", term); |
506 | 0 | deepness.append("-"); |
507 | } | |
508 | 276824 | if (!term.isList()) { |
509 | 0 | throw new RuntimeException("a term should be a list: " + term); |
510 | } | |
511 | 276824 | final String context = getLocationWithinModule(); |
512 | 276824 | final ElementList termList = term.getList(); |
513 | 276824 | final String op = termList.getOperator(); |
514 | 276824 | Entity result = null; |
515 | 276824 | if (Operators.SUBJECT_VARIABLE.equals(op)) { |
516 | 276443 | final String text = termList.getElement(0).getAtom().getString(); |
517 | 276443 | final SubjectVariable var = new SubjectVariable(text); |
518 | 276443 | result = subjectVariableInterpreter.getEntity(var); |
519 | 381 | } else if (Operators.FUNCTION_VARIABLE.equals(op)) { |
520 | 368 | final FunctionVariable var = new FunctionVariable(termList.getElement(0).getAtom().getString(), |
521 | termList.size() - 1); | |
522 | 368 | Function function = functionVariableInterpreter.getFunction(var); |
523 | 368 | setLocationWithinModule(context + ".getList()"); |
524 | 368 | result = function.map(getEntities(termList)); |
525 | 13 | } else if (Operators.FUNCTION_CONSTANT.equals(op)) { |
526 | 0 | final String label = termList.getElement(0).getAtom().getString(); |
527 | 0 | if (label.indexOf(".") >= 0) { |
528 | 0 | final String shortName = label.substring(label.indexOf(".") + 1); |
529 | 0 | final String external = label.substring(0, label.indexOf(".")); |
530 | 0 | if (qedeq.getKernelRequiredModules() != null) { |
531 | 0 | final DefaultKernelQedeqBo newProp = (DefaultKernelQedeqBo) |
532 | qedeq.getKernelRequiredModules().getQedeqBo(external); | |
533 | 0 | if (newProp != null) { |
534 | 0 | FunctionDefinition definition = newProp.getLabels().getFunction(shortName, |
535 | termList.size() - 1); | |
536 | 0 | if (definition != null) { |
537 | 0 | setLocationWithinModule(context + ".getList()"); |
538 | 0 | result = calculateFunctionValue(qedeq, definition, getEntities(termList)); |
539 | } | |
540 | } else { | |
541 | 0 | setLocationWithinModule(context + ".getList().getOperator()"); |
542 | 0 | throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_FUNCTION_CONSTANT_CODE, |
543 | HeuristicErrorCodes.UNKNOWN_FUNCTION_CONSTANT_TEXT + shortName, moduleContext); | |
544 | } | |
545 | } else { | |
546 | 0 | setLocationWithinModule(context + ".getList().getOperator()"); |
547 | 0 | throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_FUNCTION_CONSTANT_CODE, |
548 | HeuristicErrorCodes.UNKNOWN_FUNCTION_CONSTANT_TEXT + label, moduleContext); | |
549 | } | |
550 | } else { | |
551 | 0 | final ModelFunctionConstant var = new ModelFunctionConstant(label, |
552 | termList.size() - 1); | |
553 | 0 | Function function = model.getFunctionConstant(var); |
554 | 0 | if (function == null) { |
555 | 0 | setLocationWithinModule(context + ".getList().getOperator()"); |
556 | 0 | throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_FUNCTION_CONSTANT_CODE, |
557 | HeuristicErrorCodes.UNKNOWN_FUNCTION_CONSTANT_TEXT + var, moduleContext); | |
558 | } | |
559 | 0 | setLocationWithinModule(context + ".getList()"); |
560 | 0 | result = function.map(getEntities(termList)); |
561 | } | |
562 | 13 | } else if (Operators.CLASS_OP.equals(op)) { |
563 | 13 | List fullfillers = new ArrayList(); |
564 | 13 | ElementList variable = termList.getElement(0).getList(); |
565 | 13 | final SubjectVariable var = new SubjectVariable(variable.getElement(0).getAtom().getString()); |
566 | 13 | subjectVariableInterpreter.addSubjectVariable(var); |
567 | 13 | final ModelPredicateConstant isSetPredicate = new ModelPredicateConstant("isSet", 1); |
568 | 13 | Predicate isSet = model.getPredicateConstant(isSetPredicate); |
569 | 13 | if (isSet == null) { |
570 | 0 | throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_TERM_OPERATOR_CODE, |
571 | HeuristicErrorCodes.UNKNOWN_TERM_OPERATOR_TEXT + "isSet(*)", moduleContext); | |
572 | } | |
573 | 52 | for (int i = 0; i < model.getEntitiesSize(); i++) { |
574 | 39 | setLocationWithinModule(context + ".getList().getElement(1)"); |
575 | 39 | if (calculateValue(termList.getElement(1)) |
576 | && isSet.calculate(new Entity[] {model.getEntity(i)})) { | |
577 | 13 | fullfillers.add(model.getEntity(i)); |
578 | } | |
579 | 39 | subjectVariableInterpreter.increaseSubjectVariableSelection(var); |
580 | } | |
581 | 13 | result = model.comprehension((Entity[]) fullfillers.toArray(new Entity[] {})); |
582 | 13 | subjectVariableInterpreter.removeSubjectVariable(var); |
583 | } else { | |
584 | 0 | setLocationWithinModule(context + ".getList().getOperator()"); |
585 | 0 | throw new HeuristicException(HeuristicErrorCodes.UNKNOWN_TERM_OPERATOR_CODE, |
586 | HeuristicErrorCodes.UNKNOWN_TERM_OPERATOR_TEXT + op, moduleContext); | |
587 | } | |
588 | 276824 | setLocationWithinModule(context); |
589 | 276824 | if (Trace.isDebugEnabled(CLASS)) { |
590 | 0 | deepness.setLength(deepness.length() > 0 ? deepness.length() - 1 : 0); |
591 | 0 | Trace.param(CLASS, this, method, deepness.toString() + "result ", result); |
592 | } | |
593 | 276824 | return result; |
594 | } | |
595 | ||
596 | 1123864 | private String getLocationWithinModule() { |
597 | 1123864 | return moduleContext.getLocationWithinModule(); |
598 | } | |
599 | ||
600 | 2566937 | private void setLocationWithinModule(final String localContext) { |
601 | 2566937 | moduleContext.setLocationWithinModule(localContext); |
602 | // if (localContext.equals(startContext.getLocationWithinModule())) { | |
603 | // return; | |
604 | // } | |
605 | // String position | |
606 | // = moduleContext.getLocationWithinModule().substring(startContext.getLocationWithinModule().length()); | |
607 | // if (position.startsWith(".")) { | |
608 | // position = position.substring(1); | |
609 | // } | |
610 | // try { | |
611 | // DynamicGetter.get(startElement, position); | |
612 | // } catch (IllegalAccessException e) { | |
613 | // System.out.println(position); | |
614 | // e.printStackTrace(System.out); | |
615 | // } catch (InvocationTargetException e) { | |
616 | // System.out.println(position); | |
617 | // e.printStackTrace(System.out); | |
618 | // } catch (RuntimeException e) { | |
619 | // System.out.println(position); | |
620 | // e.printStackTrace(System.out); | |
621 | // throw e; | |
622 | // } | |
623 | } | |
624 | ||
625 | /** | |
626 | * Change to next valuation. | |
627 | * | |
628 | * @return Is there a next new valuation? | |
629 | */ | |
630 | 5185 | public boolean next() { |
631 | 5185 | return subjectVariableInterpreter.next() || predicateVariableInterpreter.next() |
632 | || functionVariableInterpreter.next(); | |
633 | } | |
634 | ||
635 | 0 | public String toString() { |
636 | 0 | final StringBuffer buffer = new StringBuffer(); |
637 | 0 | buffer.append("Current interpretation:\n"); |
638 | 0 | buffer.append("\t" + predicateVariableInterpreter + "\n"); |
639 | 0 | buffer.append("\t" + subjectVariableInterpreter + "\n"); |
640 | 0 | buffer.append("\t" + functionVariableInterpreter); |
641 | 0 | return buffer.toString(); |
642 | } | |
643 | ||
644 | /** | |
645 | * Strips the reference to external modules. | |
646 | * | |
647 | * @param operator Might have reference to an external module. | |
648 | * @return Operator as local reference. | |
649 | */ | |
650 | 756 | public String stripReference(final String operator) { |
651 | 756 | final int index = operator.lastIndexOf("."); |
652 | 756 | if (index >= 0 && index + 1 < operator.length()) { |
653 | 9 | return operator.substring(index + 1); |
654 | } | |
655 | 747 | return operator; |
656 | } | |
657 | ||
658 | /** | |
659 | * Clear all variable settings. | |
660 | */ | |
661 | 45 | public void clearVariables() { |
662 | 45 | subjectVariableInterpreter.clear(); |
663 | 45 | predicateVariableInterpreter.clear(); |
664 | 45 | functionVariableInterpreter.clear(); |
665 | } | |
666 | ||
667 | } |
|