←
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
15
using namespace
std;
16
17
19
// Construction/Destruction
21
22
KnowledgeElement::KnowledgeElement
()
23
{
24
this->
m_negation
=
false
;
25
this->
m_ID_Type
= 401;
26
this->
m_ID_sent
=
""
;
27
}
28
29
KnowledgeElement::~KnowledgeElement
()
30
{
31
//delete (this->m_SentenceUnit_pt);
32
33
}
34
35
void
KnowledgeElement::ReadThisKEFromFile
(ifstream &fin)
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
92
void
KnowledgeElement::ErrorMessage
(
string
str)
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
100
void
KnowledgeElement::PrintThisKE
()
101
{
102
cout << this->
m_ID
<<
'\n'
;
103
}
104
105
void
KnowledgeElement::ConvertKEinfoToStringForm
()
106
{
107
this->
m_ID_sent
= this->
m_SentenceUnit_pt
->
m_ID
;
108
}
109
110
void
KnowledgeElement::CopyStaticKEinfoFromAnother
(
KnowledgeElement
* _KE_pt)
111
{
112
this->
CopyIDElementToRestartInfo
((
IDElement
*)_KE_pt);
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
118
void
KnowledgeElement::BuildTheConnectionsToThisKE
(
void
* _pt)
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
}
KnowledgeElement.h
ReasonMachine.h
Diagnostic reasoning engine — knowledge representation, mental model, and inference.
g_sim
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
Definition:
SimulationContext.cpp:7
IDElement
Definition:
IDElement.h:12
IDElement::CopyIDElementToRestartInfo
void CopyIDElementToRestartInfo(IDElement *)
Definition:
IDElement.cpp:23
IDElement::m_ID_Type
int m_ID_Type
Definition:
IDElement.h:15
IDElement::m_ID
std::string m_ID
Definition:
IDElement.h:16
KnowledgeElement
Definition:
KnowledgeElement.h:13
KnowledgeElement::ErrorMessage
void ErrorMessage(std::string)
Definition:
KnowledgeElement.cpp:92
KnowledgeElement::m_operator
int m_operator
Definition:
KnowledgeElement.h:21
KnowledgeElement::PrintThisKE
void PrintThisKE()
Definition:
KnowledgeElement.cpp:100
KnowledgeElement::m_SentenceUnit_pt
SentenceUnit * m_SentenceUnit_pt
Definition:
KnowledgeElement.h:25
KnowledgeElement::CopyStaticKEinfoFromAnother
void CopyStaticKEinfoFromAnother(KnowledgeElement *)
Definition:
KnowledgeElement.cpp:110
KnowledgeElement::~KnowledgeElement
virtual ~KnowledgeElement()
Definition:
KnowledgeElement.cpp:29
KnowledgeElement::KnowledgeElement
KnowledgeElement()
Definition:
KnowledgeElement.cpp:22
KnowledgeElement::ReadThisKEFromFile
void ReadThisKEFromFile(std::ifstream &)
Definition:
KnowledgeElement.cpp:35
KnowledgeElement::m_negation
bool m_negation
Definition:
KnowledgeElement.h:22
KnowledgeElement::BuildTheConnectionsToThisKE
void BuildTheConnectionsToThisKE(void *)
Definition:
KnowledgeElement.cpp:118
KnowledgeElement::ConvertKEinfoToStringForm
void ConvertKEinfoToStringForm()
Definition:
KnowledgeElement.cpp:105
KnowledgeElement::m_ID_sent
std::string m_ID_sent
Definition:
KnowledgeElement.h:24
Operator::m_RM
std::unique_ptr< ReasonMachine > m_RM
Definition:
Operator.h:55
ReasonMachine
Definition:
ReasonMachine.h:45
ReasonMachine::SearchSentenceByID
SentenceUnit * SearchSentenceByID(std::string)
Definition:
ReasonMachine.cpp:2518
ReasonMachine::FindKnowledgeElementByID
KnowledgeElement * FindKnowledgeElementByID(std::string)
Definition:
ReasonMachine.cpp:2931
r5pars_
struct @0 r5pars_
sim::Operator::ODM
constexpr int ODM
Definition:
SimConstants.h:145
sim::Operator::OAT
constexpr int OAT
Definition:
SimConstants.h:144
SimulationContext::Action_Taker
OperatorAT Action_Taker
Crew action execution model.
Definition:
SimulationContext.h:47
SimulationContext::Decision_Maker
OperatorDM Decision_Maker
Crew decision-making model.
Definition:
SimulationContext.h:46
src
ADSIDAC
ReasonMachine
KnowledgeElement.cpp
Generated by
1.9.4