← Documentation
ADS-IDAC Engine 5.0.0
SentenceUnit.cpp
Go to the documentation of this file.
1// SentenceUnit.cpp: implementation of the SentenceUnit class.
2//
4
5#include <algorithm>
6#include <math.h>
7
8#include "../Crew/OperatorDM.h"
9#include "../Crew/OperatorAT.h"
10#include "ReasonMachine.h"
11#include "SentenceUnit.h"
12#include "../Global/SimulationContext.h"
13using namespace std;
14
15
17// Construction/Destruction
19
21{
22 this->m_Negation_bl = false;
23 this->m_ID_Type =100;
24 this->m_subject_pt = NULL;
25 this->m_process_pt = NULL;
26 this->m_state_pt = NULL;
27 this->m_comparison_pt = NULL;
28 this->m_object_pt = NULL;
29 this->m_attribute_pt = NULL;
30 this->m_delta_value = 0;
31 this->m_value = 0;
32 this->m_sentence_type = 0; // deterministic default
33 this->m_ID_subject = "";
34 this->m_ID_process = "";
35 this->m_ID_object = "";
36 this->m_ID_attribute = "";
37 this->m_ID_comparison = "";
38 this->m_ID_state = "";
39}
40
42{
43/* delete this->m_state_pt; //this is not used??
44 delete this->m_comparison_pt;
45 delete this->m_process_pt;
46 delete this->m_attribute_pt;
47 delete this->m_subject_pt;
48 delete this->m_object_pt;
49*/
50}
51
53{
54 bool match = true;
55 if(this->m_sentence_type != _sent_pt->m_sentence_type)
56 {
57 match = false;
58 return match;
59 }
60 if(this->m_subject_pt->m_ID != _sent_pt->m_subject_pt->m_ID)
61 {
62 match = false;
63 return match;
64 }
65
66 switch (this->m_sentence_type)
67 {
68 case 1: //process sentence
69 if(this->m_process_pt->m_ID != _sent_pt->m_process_pt->m_ID)
70 {match = false;}
71 break;
72 case 2: //state sentence
73 if(this->m_state_pt->m_ID != _sent_pt->m_state_pt->m_ID)
74 {match = false;}
75 break;
76 case 3: //comparison sentence //note: maybe more flexible way to compare?
77 if(this->m_comparison_pt->m_ID != _sent_pt->m_comparison_pt->m_ID)
78 {match = false;}
79 if(this->m_value != _sent_pt->m_value)
80 {match = false;}
81 break;
82 case 4: //comparison with the object
83 if(this->m_comparison_pt->m_ID != _sent_pt->m_comparison_pt->m_ID)
84 {match = false;}
85 if(this->m_object_pt->m_ID != _sent_pt->m_object_pt->m_ID)
86 {match = false;}
87 if(this->m_delta_value != _sent_pt->m_delta_value)
88 {match = false;}
89 break;
90 case 5://attributive sentence
91 if(this->m_attribute_pt->m_ID != _sent_pt->m_attribute_pt->m_ID)
92 {match = false;}
93 break;
94 default:
95 //warning message, unrecoganized sentence type
96 break;
97 }
98 return match;
99}
100
102{
103 this->m_ID_Type = _sent_pt->m_ID_Type;
104 this->m_sentence_type = _sent_pt->m_sentence_type;
105 this->m_subject_pt = _sent_pt->m_subject_pt;
106 // 1--process sentence, subject + process SG_A_Pressure increase
107 // 2--subject + "is" + state word
108 // 3--comparison sentence, subject + ">/=/<" + value
109 // 4--comparison sentence, subject + ">/=/<" + object
110 // 5--attributive sentence, subject + "is" + attributive word
111 // 6--definition or declaration, low_Tav + "is" + 563?
112 switch (this->m_sentence_type)
113 {
114 case 1:
115 this->m_process_pt = _sent_pt->m_process_pt;
116 break;
117 case 2:
118 this->m_state_pt = _sent_pt->m_state_pt;
119 break;
120 case 3:
121 this->m_comparison_pt = _sent_pt->m_comparison_pt;
122 this->m_value = _sent_pt->m_value;
123 break;
124 case 4:
125 this->m_comparison_pt = _sent_pt->m_comparison_pt;
126 this->m_object_pt = _sent_pt->m_object_pt;
127 this->m_delta_value = _sent_pt->m_delta_value;
128 break;
129 case 5:
130 this->m_attribute_pt = _sent_pt->m_attribute_pt;
131 break;
132 }
133
134}
135
137{
138 // 1--process sentence, subject + process SG_A_Pressure increase
139 // 2--subject + "is" + state word
140 // 3--comparison sentence, subject + ">/=/<" + value
141 // 4--comparison sentence, subject + ">/=/<" + object
142 // 5--attributive sentence, subject + "is" + attributive word
143 // 6--definition or declaration, low_Tav + "is" + 563?
144 ReasonMachine * RM_pt;
145 if (_operator == sim::Operator::ODM)
146 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
147 else if (_operator == sim::Operator::OAT)
148 {RM_pt = g_sim.Action_Taker.m_RM.get();}
149 else
150 {}//add error message
151
152 this->m_old_activation = this->m_activation;
153
154 double ratio = 1;
155 ratio = ratio * this->GetActivationChangeRatioByID(this->m_subject_pt);
156 switch (this->m_sentence_type)
157 {
158 case 1:
159 ratio = ratio * pow(this->GetActivationChangeRatioByID(this->m_process_pt), float(1/2.0));
160 break;
161 case 2:
162 ratio = ratio * pow(this->GetActivationChangeRatioByID(this->m_state_pt), float(1/2.0));
163 break;
164 case 3:
165 ratio = ratio * pow(this->GetActivationChangeRatioByID(this->m_comparison_pt), float(1/3.0));
166 break;
167 case 4:
168 ratio = ratio * pow(this->GetActivationChangeRatioByID(this->m_comparison_pt),float(1/3.0));
169 ratio = ratio * pow(this->GetActivationChangeRatioByID(this->m_object_pt),float(1/3.0));
170 break;
171 case 5:
172 break;
173 ratio = ratio * pow(this->GetActivationChangeRatioByID(this->m_attribute_pt),float(1/2.0));
174 default:
175 //error message
176 break;
177 }
178 this->ChangeActivationByRatio((float)ratio);
180}
181
183{
184 double ratio = 1;
185 ConceptBasicUnit * B_pt;
186 ConceptComposedUnit * C_pt;
187 switch (_ID_pt->m_ID_Type)
188 {
189 case 1:
190 //ConceptBasicUnit
191 B_pt = (ConceptBasicUnit *)_ID_pt;
192 ratio = B_pt->m_change_ratio;
193 case 2:
194 //ConceptComposedUnit
195 C_pt = (ConceptComposedUnit *)_ID_pt;
196 ratio = C_pt->m_change_ratio;
197 break;
198 default:
199 //error message
200 break;
201 }
202 return ratio;
203}
204
206{
207
208 double ratio1, ratio2;
209 float n=1;
210
211 // 1--process sentence, subject + process SG_A_Pressure increase
212 // 2--subject + "is" + state word
213 // 3--comparison sentence, subject + ">/=/<" + value
214 // 4--comparison sentence, subject + ">/=/<" + object
215 // 5--attributive sentence, subject + "is" + attributive word
216 // 6--definition or declaration, low_Tav + "is" + 563?
217 ratio1 = this->m_change_ratio;
218 switch (this->m_sentence_type)
219 {
220 case 1:
221 n=2;
222 ratio2 = pow(ratio1, float(1/n));
223 this->ChangActivationOfConceptByID(this->m_subject_pt, ratio2, _operator);
224 this->ChangActivationOfConceptByID(this->m_process_pt, ratio2, _operator);
225 break;
226 case 2:
227 n=2;
228 ratio2 = pow(ratio1, float(1/n));
229 this->ChangActivationOfConceptByID(this->m_subject_pt, ratio2, _operator);
230 this->ChangActivationOfConceptByID(this->m_state_pt, ratio2, _operator);
231 break;
232 case 3:
233 n=3;
234 ratio2 = pow(ratio1, float(1/n));
235 this->ChangActivationOfConceptByID(this->m_subject_pt, ratio2, _operator);
236 this->ChangActivationOfConceptByID(this->m_comparison_pt, ratio2, _operator);
237 break;
238 case 4:
239 n=3;
240 ratio2 = pow(ratio1, float(1/n));
241 this->ChangActivationOfConceptByID(this->m_subject_pt, ratio2, _operator);
242 this->ChangActivationOfConceptByID(this->m_comparison_pt, ratio2, _operator);
243 this->ChangActivationOfConceptByID(this->m_object_pt, ratio2, _operator);
244 break;
245 case 5:
246 n=2;
247 ratio2 = pow(ratio1, float(1/n));
248 this->ChangActivationOfConceptByID(this->m_subject_pt, ratio2, _operator);
249 this->ChangActivationOfConceptByID(this->m_attribute_pt, ratio2, _operator);
250 break;
251 default:
252 //error message
253 break;
254 }
255}
256
257void SentenceUnit::ChangActivationOfConceptByID(IDElement * _ID_pt, double _ratio, int _operator)
258{
259 ReasonMachine * RM_pt;
260 if (_operator == sim::Operator::ODM)
261 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
262 else if (_operator == sim::Operator::OAT)
263 {RM_pt = g_sim.Action_Taker.m_RM.get();}
264 else
265 {}//add error message
266
267 ConceptBasicUnit * B_pt;
268 ConceptComposedUnit * C_pt;
269 switch (_ID_pt->m_ID_Type)
270 {
271 case 001:
272 B_pt = (ConceptBasicUnit *)_ID_pt;
273 B_pt->ChangeActivationByRatio((float)_ratio);
274 RM_pt->m_Concept_Base->m_BasicConcept_updated_list.push_back(B_pt);
275 break;
276 case 002:
277 C_pt = (ConceptComposedUnit *)_ID_pt;
278 C_pt->ChangeActivationByRatio((float)_ratio);
279 RM_pt->m_Concept_Base->m_ComposedConcept_updated_list.push_back(C_pt);
280 break;
281 default:
282 //error message
283 break;
284 }
285}
286
288{
289 cout << "\n";
290 cout << "Time: " << r5pars_.timesno << ":\n" << str << '\n';
291
292 //test
293 ofstream fout("RMI.txt", ios::app);
294 fout <<"\n" << "Time: " << r5pars_.timesno << ":\n" << str << '\n';
295 fout.close();
296}
297
298//DEL void SentenceUnit::PrintThisSentence()
299//DEL {
300//DEL cout << this->m_ID << '\n';
301//DEL }
302
304{
305 IDElement * label_sub_pt = NULL;
306 IDElement * label_obj_pt = NULL;
307 ConceptComposedUnit * CC_pt;
308 if(this->m_subject_pt->m_ID_Type == 002)
309 {
310 CC_pt = (ConceptComposedUnit *)(this->m_subject_pt);
311 label_sub_pt = CC_pt->m_label_ID_pt;
312 }
313 if(this->m_object_pt != NULL){
314 if(this->m_object_pt->m_ID_Type == 002)
315 {
316 CC_pt = (ConceptComposedUnit *)(this->m_object_pt);
317 label_obj_pt = CC_pt->m_label_ID_pt;
318 }
319 }
320 if(label_sub_pt != NULL && label_obj_pt == NULL)
321 {
322 return label_sub_pt;
323 }
324 else if(label_sub_pt == NULL && label_obj_pt != NULL)
325 {
326 return label_obj_pt;
327 }
328 else if(label_sub_pt == NULL && label_obj_pt == NULL)
329 {
330 return NULL;
331 }
332 else if(label_sub_pt == label_obj_pt)
333 {
334 return label_sub_pt;
335 }
336 else
337 {
338 this->ErrorMessage(this->m_ID + " has two labels, which is beyond the current source codes!");
339 return NULL;
340 }
341}
342
344{
345 cout << r5pars_.timesno << " " << str << " in SentenceUnit.cpp" << '\n';
346 ofstream fout("err messages.txt", ios::app);
347 fout << r5pars_.timesno << " " << str << '\n';
348 fout.close();
349 //r5pars_.terminateall = true;
350}
351
352
353
355{
356 bool BiState_bl = true;
357 IDElement * ID_pt;
358 ConceptBasicUnit * CB_pt;
359 switch (this->m_sentence_type)
360 {
361 case 1:
362 ID_pt = this->m_process_pt;
363 break;
364 case 2:
365 ID_pt = this->m_state_pt;
366 break;
367 case 3:
368 ID_pt = this->m_comparison_pt;
369 break;
370 case 4:
371 ID_pt = this->m_comparison_pt;
372 break;
373 case 5:
374 ID_pt = this->m_attribute_pt;
375 break;
376 }
377 if(ID_pt->m_ID_Type == 001)
378 {
379 CB_pt = (ConceptBasicUnit *)ID_pt;
380 if(CB_pt->m_antonym_list.size() < 2)
381 {
382 BiState_bl = true;
383 }
384 else
385 {
386 BiState_bl = false;
387 }
388 }
389 return BiState_bl;
390}
391
393{
394 this->m_ID_subject = this->m_subject_pt->m_ID;
395
396 if(this->m_process_pt != NULL)
397 {this->m_ID_process = this->m_process_pt->m_ID;}
398
399 if(this->m_object_pt != NULL)
400 {this->m_ID_object = this->m_object_pt->m_ID;}
401
402 if(this->m_comparison_pt != NULL)
403 {this->m_ID_comparison = this->m_comparison_pt->m_ID;}
404
405 if(this->m_attribute_pt != NULL)
406 {this->m_ID_attribute = this->m_attribute_pt->m_ID;}
407
408 if(this->m_state_pt != NULL)
409 {this->m_ID_state = this->m_state_pt->m_ID;}
410}
411
413{
414 this->CopyActivationToRestartInfo((Activation*) _sent_pt);
415 this->CopyIDElementToRestartInfo((IDElement*)_sent_pt);
416
417 this->m_ID_subject = _sent_pt->m_ID_subject;
418 this->m_ID_process = _sent_pt->m_ID_process;
419 this->m_ID_object = _sent_pt->m_ID_object;
420 this->m_ID_comparison = _sent_pt->m_ID_comparison;
421 this->m_ID_attribute = _sent_pt->m_ID_attribute;
422 this->m_ID_state = _sent_pt->m_ID_state;
423/*
424 double m_value;
425 bool m_Negation_bl;
426 float m_delta_value;
427 int m_sentence_type;
428*/
429
430 this->m_delta_value = _sent_pt->m_delta_value;
431 this->m_value = _sent_pt->m_value;
432 this->m_sentence_type = _sent_pt->m_sentence_type;
433 this->m_Negation_bl = _sent_pt->m_Negation_bl;
434
435}
436
438{
439 ReasonMachine * RM_pt;
440 RM_pt = (ReasonMachine *)_pt;
441
442/*
443 IDElement * m_state_pt; //this is not used??
444 IDElement * m_comparison_pt;
445 IDElement * m_process_pt;
446 IDElement * m_attribute_pt;
447 IDElement * m_subject_pt;
448 IDElement * m_object_pt;
449
450 string m_ID_state;
451 string m_ID_subject;
452 string m_ID_process;
453 string m_ID_object;
454 string m_ID_comparison;
455 string m_ID_attribute;
456*/
457 this->m_subject_pt = RM_pt->m_Concept_Base->FindConceptByID(this->m_ID_subject);
458 if(this->m_subject_pt == NULL)
459 {this->ErrorMessage("could not find the subject" + this->m_ID_subject); return;}
460
461 if(this->m_ID_process.compare("") != 0)
462 {
463 this->m_process_pt = RM_pt->m_Concept_Base->FindConceptByID(this->m_ID_process);
464 if(this->m_process_pt == NULL)
465 {this->ErrorMessage("could not find the process concept" + this->m_ID_process); return;}
466 }
467
468 if(this->m_ID_state.compare("") != 0)
469 {
470 this->m_state_pt = RM_pt->m_Concept_Base->FindConceptByID(this->m_ID_state);
471 if(this->m_state_pt == NULL)
472 {this->ErrorMessage("could not find the state concept" + this->m_ID_state); return;}
473 }
474
475 if(this->m_ID_object.compare("") != 0)
476 {
477 this->m_object_pt = RM_pt->m_Concept_Base->FindConceptByID(this->m_ID_object);
478 if(this->m_object_pt == NULL)
479 {this->ErrorMessage("could not find the object concept" + this->m_ID_object); return;}
480 }
481
482 if(this->m_ID_comparison.compare("") != 0)
483 {
484 this->m_comparison_pt = RM_pt->m_Concept_Base->FindConceptByID(this->m_ID_comparison);
485 if(this->m_comparison_pt == NULL)
486 {this->ErrorMessage("could not find the comparison concept" + this->m_ID_comparison); return;}
487 }
488
489 if(this->m_ID_attribute.compare("") != 0)
490 {
491 this->m_attribute_pt = RM_pt->m_Concept_Base->FindConceptByID(this->m_ID_attribute);
492 if(this->m_attribute_pt == NULL)
493 {this->ErrorMessage("could not find the attribute concept" + this->m_ID_attribute); return;}
494 }
495}
Diagnostic reasoning engine — knowledge representation, mental model, and inference.
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
double m_change_ratio
Definition: Activation.h:19
void ChangeActivationByRatio(float)
Definition: Activation.cpp:55
void UpdateTheBaseLineValueAfterAChange(float _decay_lamda)
Definition: Activation.cpp:75
double m_old_activation
Definition: Activation.h:23
double m_activation
Definition: Activation.h:22
void CopyActivationToRestartInfo(Activation *)
Definition: Activation.cpp:48
std::vector< IDElement * > m_antonym_list
void CopyIDElementToRestartInfo(IDElement *)
Definition: IDElement.cpp:23
int m_ID_Type
Definition: IDElement.h:15
std::string m_ID
Definition: IDElement.h:16
std::unique_ptr< ReasonMachine > m_RM
Definition: Operator.h:55
std::unique_ptr< KBConcept > m_Concept_Base
double m_decay_lamda
IDElement * m_object_pt
Definition: SentenceUnit.h:41
std::string m_ID_comparison
Definition: SentenceUnit.h:47
IDElement * m_process_pt
Definition: SentenceUnit.h:38
void CopyStaticInfoFromAnotherSentence(SentenceUnit *)
int m_sentence_type
Definition: SentenceUnit.h:34
std::string m_ID_process
Definition: SentenceUnit.h:45
virtual ~SentenceUnit()
double m_value
Definition: SentenceUnit.h:31
std::string m_ID_object
Definition: SentenceUnit.h:46
void PrintMessage(std::string)
std::string m_ID_attribute
Definition: SentenceUnit.h:48
IDElement * m_state_pt
Definition: SentenceUnit.h:36
bool m_Negation_bl
Definition: SentenceUnit.h:32
bool CheckMatchBySentence(SentenceUnit *)
float m_delta_value
Definition: SentenceUnit.h:33
bool WhetherItIsBiState()
double GetActivationChangeRatioByID(IDElement *)
void BuildTheConnectionsToThisSentence(void *)
IDElement * m_comparison_pt
Definition: SentenceUnit.h:37
void ErrorMessage(std::string)
std::string m_ID_state
Definition: SentenceUnit.h:43
void ActivationPropagationFromConceptBottomUp(int)
IDElement * GetLabelOfThisSentence()
void ConvertSentenceInfoToStringForm()
void ChangActivationOfConceptByID(IDElement *, double, int)
void CopyFromAnotherSentence(SentenceUnit *)
std::string m_ID_subject
Definition: SentenceUnit.h:44
IDElement * m_attribute_pt
Definition: SentenceUnit.h:39
IDElement * m_subject_pt
Definition: SentenceUnit.h:40
void PropagateActivationToConceptUnitsTopDown(int)
struct @0 r5pars_
constexpr int ODM
Definition: SimConstants.h:145
constexpr int OAT
Definition: SimConstants.h:144
OperatorAT Action_Taker
Crew action execution model.
OperatorDM Decision_Maker
Crew decision-making model.