OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
opencog::DefaultForwardChainerCB Class Reference

#include <DefaultForwardChainerCB.h>

+ Inheritance diagram for opencog::DefaultForwardChainerCB:
+ Collaboration diagram for opencog::DefaultForwardChainerCB:

Public Member Functions

HandleSeq substitute_rule_part (AtomSpace &as, Handle hrule, const std::set< Handle > &vars, const std::vector< std::map< Handle, Handle >> &var_groundings)
 
 DefaultForwardChainerCB (AtomSpace &as, source_selection_mode ts_mode=TV_FITNESS_BASED)
 
virtual vector< Rule * > choose_rules (FCMemory &fcmem)
 
virtual HandleSeq choose_premises (FCMemory &fcmem)
 
virtual Handle choose_next_source (FCMemory &fcmem)
 
virtual HandleSeq apply_rule (FCMemory &fcmem)
 
- Public Member Functions inherited from opencog::ForwardChainerCallBack
 ForwardChainerCallBack (AtomSpace *as)
 
virtual ~ForwardChainerCallBack ()
 

Public Attributes

std::map< Handle, std::vector
< Handle > > 
rule_derivations
 

Private Member Functions

Handle gen_sub_varlist (const Handle &parent, const Handle &parent_varlist)
 
HandleSeq unify (Handle source, Handle target, Rule *rule)
 
HandleSeq subatom_unify (Handle source, Rule *rule)
 
bool is_valid_implicant (const Handle &h)
 

Private Attributes

AtomSpace_as
 
ForwardChainerPMCB _fcpm
 
source_selection_mode _ts_mode
 

Friends

class ::DefaultForwardChainerCBUTest
 

Detailed Description

Definition at line 36 of file DefaultForwardChainerCB.h.

Constructor & Destructor Documentation

DefaultForwardChainerCB::DefaultForwardChainerCB ( AtomSpace as,
source_selection_mode  ts_mode = TV_FITNESS_BASED 
)

Definition at line 41 of file DefaultForwardChainerCB.cc.

Member Function Documentation

HandleSeq DefaultForwardChainerCB::apply_rule ( FCMemory fcmem)
virtual

apply chosen rule. the default will wrap a custom PM callback class. i.e invokes _pattern_matcher.

Returns
a set of handles created as a result of applying current choosen rule

Make sure the inferences made are new.

Implements opencog::ForwardChainerCallBack.

Definition at line 255 of file DefaultForwardChainerCB.cc.

References _fcpm, opencog::BindLinkCast(), createBindLink, opencog::FCMemory::get_cur_rule(), opencog::Rule::get_handle(), opencog::ForwardChainerPMCB::get_products(), opencog::Implicator::implicand, opencog::FCMemory::isin_potential_sources(), opencog::LinkCast(), and opencog::ForwardChainerPMCB::set_fcmem().

Handle DefaultForwardChainerCB::choose_next_source ( FCMemory fcmem)
virtual

choose next source from the source list

Returns
a handle to the chosen source from source list

Choose a new source that has never been chosen before. xxx FIXME since same handle might be chosen multiple times the following code doesn't guarantee all sources have been exhaustively looked.

Implements opencog::ForwardChainerCallBack.

Definition at line 211 of file DefaultForwardChainerCB.cc.

References _as, _ts_mode, opencog::FCMemory::get_potential_sources(), opencog::FCMemory::isin_selected_sources(), opencog::STI_BASED, python.undocumented.blocksworld::t, opencog::URECommons::tournament_select(), opencog::URECommons::tv_fitness(), opencog::TV_FITNESS_BASED, and opencog::Handle::UNDEFINED.

HandleSeq DefaultForwardChainerCB::choose_premises ( FCMemory fcmem)
virtual

Choose additional premises for the rule. an object holding the current source/target and other inform ation of the forward chaining instance.

Returns
a set of Handles chosen as a result of applying fitness criteria with respect to the current source.

Implements opencog::ForwardChainerCallBack.

Definition at line 186 of file DefaultForwardChainerCB.cc.

References _as, opencog::FCMemory::get_cur_source(), opencog::get_distant_neighbors(), and opencog::URECommons::get_root_links().

vector< Rule * > DefaultForwardChainerCB::choose_rules ( FCMemory fcmem)
virtual

Choose rules based on implicant member of rule matching the source. Whenever a matching rule is found, it derives new rules by substituting bound variables of the rule with the source. All derived rules are then kept in the global variable

Parameters
rule_derivations.
fcmemForward chainer's working memory
Returns
A vector of chosen rules

Implements opencog::ForwardChainerCallBack.

Definition at line 59 of file DefaultForwardChainerCB.cc.

References opencog::FCMemory::get_cur_source(), opencog::FCMemory::get_rules(), rule_derivations, opencog::Handle::UNDEFINED, and unify().

Handle DefaultForwardChainerCB::gen_sub_varlist ( const Handle parent,
const Handle parent_varlist 
)
private
bool DefaultForwardChainerCB::is_valid_implicant ( const Handle h)
private

Checks whether an atom can be used to generate a bindLink or not.

Parameters
hThe atom handle to be validated.
Returns
A boolean result of the check.

Definition at line 372 of file DefaultForwardChainerCB.cc.

References opencog::Atom::getType(), opencog::FindAtoms::search_set(), and opencog::FindAtoms::varset.

+ Here is the caller graph for this function:

HandleSeq DefaultForwardChainerCB::subatom_unify ( Handle  source,
Rule rule 
)
private

Tries to unify sub atoms of implicant lists in

Parameters
rulewith
source.
sourceAn atom that might bind to variables in
rule.
ruleThe rule object whose implicants are to be sub atom unified.
Returns
HandleSeq of derived rules from sub atoms unification.

Definition at line 166 of file DefaultForwardChainerCB.cc.

References opencog::get_all_unique_atoms(), opencog::Rule::get_implicant_seq(), python.bindlink::result, and unify().

HandleSeq DefaultForwardChainerCB::substitute_rule_part ( AtomSpace as,
Handle  hrule,
const std::set< Handle > &  vars,
const std::vector< std::map< Handle, Handle >> &  var_groundings 
)

Derives new rules from

Parameters
hruleby replacing variables with their groundings.
asAn atomspace where the handles dwell.
hruleA handle to BindLink instance
varsThe grounded var list in
hrule
var_groundingsThe set of groundings to each var in
vars
Returns
A HandleSeq of all possible derived rules

Definition at line 320 of file DefaultForwardChainerCB.cc.

References opencog::BindLinkCast(), opencog::contains_atomtype(), createBindLink, gen_sub_varlist(), opencog::LinkCast(), and opencog::Substitutor::substitute().

+ Here is the caller graph for this function:

HandleSeq DefaultForwardChainerCB::unify ( Handle  source,
Handle  target,
Rule rule 
)
private

Tries to unify the

Parameters
sourcewith target and derives new rules using
ruleas a template.
sourceAn atom that might bind to variables in
rule.
targetAn atom to be unified with
sourcerule The rule object whose implicants are to be unified.
Returns
HandleSeq of possible derivation of rules by substituting variables in implicants members of
Parameters
rulewith their mapped bindings.

Definition at line 102 of file DefaultForwardChainerCB.cc.

References _as, opencog::AtomSpace::add_atom(), createBindLink, gen_sub_varlist(), opencog::Rule::get_handle(), opencog::Rule::get_vardecl(), is_valid_implicant(), opencog::FindAtoms::search_set(), substitute_rule_part(), and opencog::FindAtoms::varset.

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class ::DefaultForwardChainerCBUTest
friend

Definition at line 38 of file DefaultForwardChainerCB.h.

Member Data Documentation

AtomSpace& opencog::DefaultForwardChainerCB::_as
private

Definition at line 39 of file DefaultForwardChainerCB.h.

ForwardChainerPMCB opencog::DefaultForwardChainerCB::_fcpm
private

Definition at line 40 of file DefaultForwardChainerCB.h.

source_selection_mode opencog::DefaultForwardChainerCB::_ts_mode
private

Definition at line 41 of file DefaultForwardChainerCB.h.

std::map<Handle,std::vector<Handle> > opencog::DefaultForwardChainerCB::rule_derivations

Definition at line 60 of file DefaultForwardChainerCB.h.


The documentation for this class was generated from the following files: