← Documentation
ADS-IDAC Engine 5.0.0
KnowledgeElement.cpp
Go to the documentation of this file.
1// KnowledgeElement.cpp: implementation of the KnowledgeElement class.
2//
4
5#include <string>
6#include <sstream>
7
8#include "KnowledgeElement.h"
9#include "ReasonMachine.h"
10#include "../Global/fmodule.h"
11#include "../Crew/OperatorDM.h"
12#include "../Crew/OperatorAT.h"
13#include "../Global/SimulationContext.h"
14
15using namespace std;
16
17
19// Construction/Destruction
21
23{
24 this->m_negation = false;
25 this->m_ID_Type = 401;
26 this->m_ID_sent = "";
27}
28
30{
31 //delete (this->m_SentenceUnit_pt);
32
33}
34
36{
37 string str, ID_name;
38 bool neg_bl;
39 string err_mes;
40
41 ReasonMachine * RM_pt;
42 if (this->m_operator == sim::Operator::ODM)
43 {RM_pt = g_sim.Decision_Maker.m_RM.get();}
44 else if (this->m_operator == sim::Operator::OAT)
45 {RM_pt = g_sim.Action_Taker.m_RM.get();}
46 else
47 { }
48
49 //read the ID name
50 fin >> str >> ID_name;
51 if(str.compare("Knowledge_Element_ID:") != 0)
52 {
53 err_mes = ID_name + "is not in a line that begins with Knowledge_Element_ID:";
54 this->ErrorMessage(err_mes);
55 return;
56 }
57 this->m_ID = ID_name;
58 if(RM_pt->FindKnowledgeElementByID(ID_name) != NULL)
59 {
60 err_mes = ID_name + "already exists in the KE pool, choose another name!";
61 this->ErrorMessage(err_mes);
62 return;
63 }
64
65 //read the semantic sentence name and find the link
66 fin >> str >> ID_name;
67 if(str.compare("Semantic_ID:") != 0)
68 {
69 err_mes = ID_name + " is not aligned in line that begins with Semantic_ID:";
70 this->ErrorMessage(err_mes);
71 return;
72 }
73 this->m_SentenceUnit_pt = RM_pt->SearchSentenceByID(ID_name);
74 if(this->m_SentenceUnit_pt == NULL)
75 {
76 err_mes = ID_name + "could not be found in the semantic pool. Check the KB_ODM_Knowledge_Node_Base.txt";
77 this->ErrorMessage(err_mes);
78 return;
79 }
80
81 //read the negation information
82 fin >> str >> neg_bl;
83 if(str.compare("Negation:") != 0)
84 {
85 err_mes = "Negation of " + ID_name + " is not in right position";
86 this->ErrorMessage(err_mes);
87 return;
88 }
89 this->m_negation = neg_bl;
90}
91
93{
94 cout << r5pars_.timesno << " " << str << " in KnowledgeElement.cpp" << '\n';
95 ofstream fout("err messages.txt", ios::app);
96 fout << r5pars_.timesno << " " << str << '\n';
97 fout.close();
98}
99
101{
102 cout << this->m_ID << '\n';
103}
104
106{
107 this->m_ID_sent = this->m_SentenceUnit_pt->m_ID;
108}
109
111{
113 this->m_ID_sent =_KE_pt->m_ID_sent;
114 this->m_negation = _KE_pt->m_negation;
115 this->m_operator = _KE_pt->m_operator;
116}
117
119{
120 ReasonMachine * RM_pt;
121 RM_pt = (ReasonMachine *)_pt;
122
123 this->m_SentenceUnit_pt = RM_pt->SearchSentenceByID(this->m_ID_sent);
124 if(this->m_SentenceUnit_pt == NULL)
125 {this->ErrorMessage("could not find the sentence for this KE" + this->m_ID_sent); return;}
126}
Diagnostic reasoning engine — knowledge representation, mental model, and inference.
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
void CopyIDElementToRestartInfo(IDElement *)
Definition: IDElement.cpp:23
int m_ID_Type
Definition: IDElement.h:15
std::string m_ID
Definition: IDElement.h:16
void ErrorMessage(std::string)
SentenceUnit * m_SentenceUnit_pt
void CopyStaticKEinfoFromAnother(KnowledgeElement *)
virtual ~KnowledgeElement()
void ReadThisKEFromFile(std::ifstream &)
void BuildTheConnectionsToThisKE(void *)
std::string m_ID_sent
std::unique_ptr< ReasonMachine > m_RM
Definition: Operator.h:55
SentenceUnit * SearchSentenceByID(std::string)
KnowledgeElement * FindKnowledgeElementByID(std::string)
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.