24 #include <opencog/util/Logger.h>
33 using namespace opencog;
36 _as(as), _rec(_as), _rbs(rbs), _configReader(as, rbs), _fcmem(&as)
49 setLogger(
new opencog::Logger(
"forward_chainer.log", Logger::FINE,
true));
73 _log->info(
"[ForwardChainer] No current source, step "
74 "forward chaining aborted.");
78 _log->info(
"[ForwardChainer] Next source %s",
83 _log->info(
"[ForwardChainer] Found matching rule");
89 if (matched_rules.empty()) {
90 _log->info(
"[ForwardChainer] No matching rule found. "
91 "Setting all rules as candidates.");
96 map<Rule*, float> rule_weight;
97 for (
Rule* r : matched_rules) {
98 rule_weight[r] = r->get_weight();
101 _log->info(
"[ForwardChainer] Selecting a rule from the set of "
105 _log->info(
"[ForwardChainer] Selected rule is %s", (r->
get_handle())->toShortString().c_str());
110 _log->info(
"[ForwardChainer] Applying chosen rule %s",
114 _log->info(
"PRODUCTS...");
115 for(
const auto& p:product)
117 _log->info(
"%s ", p->toShortString().c_str() );
120 _log->info(
"[ForwardChainer] updating premise list with the "
124 _log->info(
"[ForwardChainer] adding inference to history");
138 if (not var_nodes.empty())
139 return do_pm(hsource, var_nodes, fcb);
146 init_sources.push_back(hsource);
158 _log->info(
"[ForwardChainer] setting next source");
164 _log->info(
"[ForwardChainer] finished do_chain.");
181 for (
auto h : var_nodes)
201 for (
Rule* rule : rules) {
216 _log->info(
"Forward chaining on the rule-based system %s "
219 for (
Rule* rule : rules) {
220 _log->info(
"Applying rule %s on ", rule->get_name().c_str());
227 _log->info(
"OUTPUTS");
229 _log->info(
"%s", h->toString().c_str());
void add_rules_product(int iteration, HandleSeq product)
virtual Handle choose_next_source(FCMemory &fcmem)=0
ForwardChainer(AtomSpace &as, Handle rbs)
std::vector< Handle > HandleSeq
a list of handles
Handle get_cur_source(void)
#define createPatternLink
static BindLinkPtr BindLinkCast(const Handle &h)
int get_maximum_iterations() const
virtual std::string toString(std::string indent="")=0
Type tournament_select(map< Type, float > tfitnes_map)
UREConfigReader _configReader
virtual std::vector< Rule * > choose_rules(FCMemory &fcmem)=0
static const Handle UNDEFINED
void set_rules(const vector< Rule * > &rules)
std::shared_ptr< BindLink > BindLinkPtr
bool remove_atom(Handle h, bool recursive=false)
void setLogger(Logger *log)
UnorderedHandleSet get_outgoing_nodes(const Handle &hinput, const std::vector< Type > &types)
const std::vector< Rule > & get_rules() const
static LinkPtr LinkCast(const Handle &h)
void set_search_in_af(bool val)
bool get_attention_allocation() const
void set_cur_rule(Rule *r)
vector< Rule * > & get_rules()
virtual HandleSeq apply_rule(FCMemory &fcmem)=0
std::shared_ptr< PatternLink > PatternLinkPtr
void update_potential_sources(HandleSeq input)
void set_source(Handle source)
std::unordered_set< Handle, handle_hash > UnorderedHandleSet
a hash that associates the handle to its unique identificator
Handle add_link(Type t, const HandleSeq &outgoing, bool async=false)
HandleSeq get_chaining_result(void)
virtual HandleSeq get_result_list()
const HandleSeq & get_outgoing(Handle h) const
void do_step(ForwardChainerCallBack &fcb)
void do_chain(ForwardChainerCallBack &fcb, Handle hsource=Handle::UNDEFINED)