Menu

[r12]: / trunk / libtop_engine / rule_explain_why.cpp  Maximize  Restore  History

Download this file

153 lines (115 with data), 4.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include "rule_explain_why.h"
namespace rule {
/////////////////////////////////////////////////////////////////////////////////////////
// rule_event_base::initialize_body_triples
//
/////////////////////////////////////////////////////////////////////////////////////////
void
rule_event_base::initialize_body_triples(rule_session * rule_session_p)
{
if(m_body_triples_initialized) return;
rdf::index_type t3[3];
if(m_krule_p->has_explain_info()) {
knowledge_rule::rule_term_ptr_const_iterator rule_terms_itor = m_krule_p->get_explain_terms_begin();
knowledge_rule::rule_term_ptr_const_iterator rule_terms_end = m_krule_p->get_explain_terms_end();
for(; rule_terms_itor != rule_terms_end; ++rule_terms_itor) {
(*rule_terms_itor)->get_inferred_triples(rule_session_p, t3, *m_relation_row_p);
m_body_triples.push_back(std::make_pair( rdf::index_triple(t3),
(*rule_terms_itor)->is_assertion_term()));
}
}
m_body_triples_initialized = true;
};
/////////////////////////////////////////////////////////////////////////////////////////
// rule_event_infer::print_event
//
/////////////////////////////////////////////////////////////////////////////////////////
void
rule_event_infer::print_event(std::ostream& out)const
{
char * label;
if(m_is_inferred) label = "inferred";
else label = "retracted";
out << std::endl;
out << "Triple(s) " << label << " from rule "
<< m_krule_p->get_rule_name()
<< "[salience "
<< m_krule_p->get_rule_salience()
<< "]: ";
if(m_krule_p->has_explain_info()) {
array_body_triples_type::const_iterator itor = body_triples_begin();
array_body_triples_type::const_iterator end = body_triples_end();
rdf::index_triple triple;
bool is_assertion;
while(itor!=end) {
boost::tie(triple, is_assertion) = *itor;
if(!is_assertion) out << "not ";
out << triple;
if(++itor != end) out << ", ";
}
out << " -> ";
}
array_triples_type::const_iterator itor = consequent_triples_begin();
array_triples_type::const_iterator end = consequent_triples_end();
for(; itor!=end; ++itor) out << *itor << " ";
out << std::endl;
}
/////////////////////////////////////////////////////////////////////////////////////////
// explain_info_triple::print_node
//
/////////////////////////////////////////////////////////////////////////////////////////
void
explain_info_triple::print_node(std::ostream& out)const
{
out << "triple: " << m_triple << " was ";
if(m_is_asserted) {
out << "asserted.";
} else {
out << "inferred;";
}
};
/////////////////////////////////////////////////////////////////////////////////////////
// explain_info_triple::print_closing
//
/////////////////////////////////////////////////////////////////////////////////////////
void
explain_info_triple::print_closing(std::ostream& out)const
{
//out << "end triple\n";
};
/////////////////////////////////////////////////////////////////////////////////////////
// explain_info_rule::print_node
//
/////////////////////////////////////////////////////////////////////////////////////////
void
explain_info_rule::print_node(std::ostream& out)const
{
knowledge_rule const* krule_p = m_rule_event_p->get_knowledge_rule_p();
out << "from rule: " << krule_p->get_rule_name() << ": ";
if(krule_p->has_explain_info()) {
rule_event_base::array_body_triples_type::const_iterator itor = m_rule_event_p->body_triples_begin();
rule_event_base::array_body_triples_type::const_iterator end = m_rule_event_p->body_triples_end();
rdf::index_triple triple;
bool is_assertion;
while(itor!=end) {
boost::tie(triple, is_assertion) = *itor;
if(!is_assertion) out << "not ";
out << triple;
if(++itor != end) out << ", ";
}
out << " -> ";
}
rule_event_base::array_triples_type::const_iterator itor = m_rule_event_p->consequent_triples_begin();
rule_event_base::array_triples_type::const_iterator end = m_rule_event_p->consequent_triples_end();
for(; itor!=end; ++itor) out << *itor << " ";
};
/////////////////////////////////////////////////////////////////////////////////////////
// explain_info_rule::print_closing
//
/////////////////////////////////////////////////////////////////////////////////////////
void
explain_info_rule::print_closing(std::ostream& out)const
{
//out << "end rule\n";
};
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.