1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.qedeq.kernel.bo.module;
17
18 import org.qedeq.kernel.bo.common.NodeBo;
19 import org.qedeq.kernel.bo.common.QedeqBo;
20 import org.qedeq.kernel.se.base.list.Element;
21 import org.qedeq.kernel.se.base.module.ConditionalProof;
22 import org.qedeq.kernel.se.base.module.FormalProofLineList;
23 import org.qedeq.kernel.se.base.module.FormalProofList;
24 import org.qedeq.kernel.se.base.module.NodeType;
25 import org.qedeq.kernel.se.base.module.Proposition;
26 import org.qedeq.kernel.se.base.module.Reason;
27 import org.qedeq.kernel.se.common.CheckLevel;
28 import org.qedeq.kernel.se.common.ModuleContext;
29 import org.qedeq.kernel.se.dto.module.NodeVo;
30 import org.qedeq.kernel.se.visitor.QedeqNumbers;
31
32
33
34
35
36
37 public class KernelNodeBo implements NodeBo, CheckLevel {
38
39
40 private final NodeVo node;
41
42
43 private final ModuleContext context;
44
45
46 private final KernelQedeqBo qedeq;
47
48
49 private final QedeqNumbers data;
50
51
52
53 private int wellFormedCheck = UNCHECKED;
54
55
56
57 private int provedCheck = UNCHECKED;
58
59
60
61
62
63
64
65
66
67
68 public KernelNodeBo(final NodeVo node, final ModuleContext context, final KernelQedeqBo qedeq,
69 final QedeqNumbers data) {
70 this.node = node;
71 this.context = new ModuleContext(context);
72 this.qedeq = qedeq;
73 this.data = new QedeqNumbers(data);
74 }
75
76
77
78
79
80
81 public NodeVo getNodeVo() {
82 return node;
83 }
84
85
86
87
88
89
90 public ModuleContext getModuleContext() {
91 return context;
92 }
93
94
95
96
97
98
99 public QedeqBo getParentQedeqBo() {
100 return qedeq;
101 }
102
103
104
105
106
107
108 public KernelQedeqBo getQedeqBo() {
109 return qedeq;
110 }
111
112
113
114
115
116
117 public QedeqNumbers getNumbers() {
118 return data;
119 }
120
121
122
123
124
125
126
127
128 public boolean isProofLineLabel(final String label) {
129 if (label == null || label.length() == 0) {
130 return false;
131 }
132 final Proposition theorem = getNodeVo().getNodeType().getProposition();
133 if (theorem == null) {
134 return false;
135 }
136 final FormalProofList proofs = theorem.getFormalProofList();
137 if (proofs == null) {
138 return false;
139 }
140
141 for (int i = 0; i < proofs.size(); i++) {
142 final FormalProofLineList list = proofs.get(i).getFormalProofLineList();
143 if (hasProofLineLabel(label, list)) {
144 return true;
145 }
146 }
147
148 return false;
149 }
150
151 private boolean hasProofLineLabel(final String label, final FormalProofLineList list) {
152 if (list == null) {
153 return false;
154 }
155 for (int j = 0; j < list.size(); j++) {
156 if (label.equals(list.get(j).getLabel())) {
157 return true;
158 }
159 final Reason reason = list.get(j).getReason();
160 if (reason instanceof ConditionalProof) {
161 final ConditionalProof conditionalProof = (ConditionalProof) reason;
162 if (conditionalProof.getHypothesis() != null) {
163 if (label.equals(conditionalProof.getHypothesis().getLabel())) {
164 return true;
165 }
166 }
167 final FormalProofLineList list2 = conditionalProof.getFormalProofLineList();
168 if (hasProofLineLabel(label, list2)) {
169 return true;
170 }
171 }
172 }
173 return false;
174 }
175
176
177
178
179
180
181
182 public void setWellFormed(final int wellFormedCheck) {
183 this.wellFormedCheck = wellFormedCheck;
184 }
185
186 public boolean isWellFormed() {
187 return wellFormedCheck >= SUCCESS;
188 }
189
190 public boolean isNotWellFormed() {
191 return wellFormedCheck < SUCCESS && wellFormedCheck > UNCHECKED;
192 }
193
194
195
196
197
198
199
200 public void setProved(final int provedCheck) {
201 this.provedCheck = provedCheck;
202 }
203
204 public boolean isProved() {
205 return provedCheck >= SUCCESS;
206 }
207
208 public boolean isNotProved() {
209 return provedCheck < SUCCESS && provedCheck > UNCHECKED;
210 }
211
212 public boolean hasFormula() {
213 return null != getFormula();
214 }
215
216 public Element getFormula() {
217 if (getNodeVo() == null || getNodeVo().getNodeType() == null) {
218 return null;
219 }
220 final NodeType nodeType = getNodeVo().getNodeType();
221 if (nodeType.getProposition() != null) {
222 if (nodeType.getProposition().getFormula() != null) {
223 return nodeType.getProposition().getFormula().getElement();
224 }
225 return null;
226 } else if (nodeType.getPredicateDefinition() != null) {
227 if (nodeType.getPredicateDefinition().getFormula() != null) {
228 return nodeType.getPredicateDefinition().getFormula().getElement();
229 }
230 return null;
231 } else if (nodeType.getFunctionDefinition() != null) {
232 if (nodeType.getFunctionDefinition().getFormula() != null) {
233 return nodeType.getFunctionDefinition().getFormula().getElement();
234 }
235 return null;
236 } else if (nodeType.getAxiom() != null) {
237 if (nodeType.getAxiom().getFormula() != null) {
238 return nodeType.getAxiom().getFormula().getElement();
239 }
240 return null;
241 }
242 return null;
243 }
244 }