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

#include <DefaultPatternMatchCB.h>

+ Inheritance diagram for opencog::DefaultPatternMatchCB:
+ Collaboration diagram for opencog::DefaultPatternMatchCB:

Public Member Functions

 DefaultPatternMatchCB (AtomSpace *)
 
virtual void set_pattern (const Variables &, const Pattern &)
 
virtual bool node_match (const Handle &, const Handle &)
 
virtual bool variable_match (const Handle &, const Handle &)
 
virtual bool link_match (const LinkPtr &, const LinkPtr &)
 
virtual bool post_link_match (const LinkPtr &, const LinkPtr &)
 
virtual bool clause_match (const Handle &, const Handle &)
 
virtual bool optional_clause_match (const Handle &pattrn, const Handle &grnd)
 
virtual bool evaluate_sentence (const Handle &pat, const std::map< Handle, Handle > &gnds)
 
virtual const std::set< Type > & get_connectives (void)
 
bool optionals_present (void)
 
- Public Member Functions inherited from opencog::PatternMatchCallback
virtual ~PatternMatchCallback ()
 
virtual bool fuzzy_match (const Handle &ph, const Handle &gh)
 
virtual bool grounding (const std::map< Handle, Handle > &var_soln, const std::map< Handle, Handle > &term_soln)=0
 
virtual IncomingSet get_incoming_set (const Handle &h)
 
virtual void push (void)
 
virtual void pop (void)
 
virtual bool initiate_search (PatternMatchEngine *)=0
 

Protected Member Functions

bool eval_term (const Handle &pat, const std::map< Handle, Handle > &gnds)
 
bool eval_sentence (const Handle &pat, const std::map< Handle, Handle > &gnds)
 

Protected Attributes

ClassServer_classserver
 
const VariableTypeMap_type_restrictions = NULL
 
const std::set< Handle > * _dynamic = NULL
 
bool _have_evaluatables = false
 
AtomSpace _temp_aspace
 
Instantiator _instor
 
std::set< Type_connectives
 
bool _optionals_present = false
 
AtomSpace_as
 

Detailed Description

Callback mixin class, used to provide a default node and link matching behaviour. This class is a pure virtual class, since it does not implement either the initiate_search() method, nor the solution() method.

It provides is node and link matching, assuming the canonical meaning of VariableNodes and QuoteLinks. It also implements crisp-logic handling of AndLink, OrLink, NotLink when these are combined with AbsentLink, EqualLink, GreaterThanLink, and other clear-box evaluatable link types.

It handles AbsentLink using standard intuitionist logic, and provides tracking of an _optionals_present flag, so that conversion to explicit classical logic can be performed at the conclusion of the search. The default implicator performs conversion; see the notes there for details.

Definition at line 54 of file DefaultPatternMatchCB.h.

Constructor & Destructor Documentation

DefaultPatternMatchCB::DefaultPatternMatchCB ( AtomSpace as)

Definition at line 42 of file DefaultPatternMatchCB.cc.

References _connectives.

Member Function Documentation

bool DefaultPatternMatchCB::clause_match ( const Handle ptrn,
const Handle grnd 
)
virtual

Called to accept of reject a top-level clause.

This is straight-forward, except when the pattern is a VariableNode, and the proposed grounding is evaluatable. In this case, we want to treat the grounding term as if it was a regular evaluatable clause, and evaluate it, and use that to determine if the match is accepted.

This allows a clause to implement a (pre-)condition on the match. If we didn't implement this here, the user could still work around this by saying (NotLink (NotLink (VariableNode $x))), thus forcing the "normal" path to evaluate_sentence(). So may as well do it here.

Reimplemented from opencog::PatternMatchCallback.

Definition at line 179 of file DefaultPatternMatchCB.cc.

References _temp_aspace, opencog::AtomSpace::clear(), dbgprt, opencog::EvaluationLink::do_evaluate(), opencog::Atom::getType(), opencog::LinkCast(), and opencog::Atom::toShortString().

bool DefaultPatternMatchCB::eval_sentence ( const Handle top,
const std::map< Handle, Handle > &  gnds 
)
protected

This implements the evaluation of a classical boolean-logic "sentence": a well-formed formula with no free variables, having a crisp true/false truth value. Here, "top" holds the sentence (with variables), 'gnds' holds the bindings of variables to values.

Definition at line 307 of file DefaultPatternMatchCB.cc.

References _classserver, dbgprt, eval_term(), opencog::Atom::getType(), opencog::ClassServer::isA(), opencog::LinkCast(), and opencog::Atom::toShortString().

+ Here is the caller graph for this function:

bool DefaultPatternMatchCB::eval_term ( const Handle pat,
const std::map< Handle, Handle > &  gnds 
)
protected
virtual bool opencog::DefaultPatternMatchCB::evaluate_sentence ( const Handle pat,
const std::map< Handle, Handle > &  gnds 
)
inlinevirtual

Called when a virtual link is encountered. Returns false to reject the match.

Implements opencog::PatternMatchCallback.

Definition at line 76 of file DefaultPatternMatchCB.h.

References eval_sentence().

virtual const std::set<Type>& opencog::DefaultPatternMatchCB::get_connectives ( void  )
inlinevirtual

Reimplemented from opencog::PatternMatchCallback.

Definition at line 80 of file DefaultPatternMatchCB.h.

References _connectives.

bool DefaultPatternMatchCB::link_match ( const LinkPtr lpat,
const LinkPtr lsoln 
)
virtual

Called when a link in the template pattern needs to be compared to a possibly matching link in the atomspace. The first argument is a link from the pattern, and the second is a possible solution link from the atomspace. Return true if the links should be compared, else return false.

By default, the search continues if the link arity and the link types match.

Implements opencog::PatternMatchCallback.

Reimplemented in opencog::ForwardChainerPMCB, opencog::FuzzyPatternMatchCB, and opencog::AttentionalFocusCB.

Definition at line 130 of file DefaultPatternMatchCB.cc.

+ Here is the caller graph for this function:

bool DefaultPatternMatchCB::node_match ( const Handle npat_h,
const Handle nsoln_h 
)
virtual

Called when a node in the template pattern needs to be compared to a possibly matching node in the atomspace. The first argument is a node from the pattern, and the second is a possible solution (grounding) node from the atomspace.

Return true if the nodes match, else return false. By default, the nodes must be identical.

Implements opencog::PatternMatchCallback.

Reimplemented in opencog::ForwardChainerPMCB, opencog::FuzzyPatternMatchCB, and opencog::AttentionalFocusCB.

Definition at line 75 of file DefaultPatternMatchCB.cc.

+ Here is the caller graph for this function:

bool DefaultPatternMatchCB::optional_clause_match ( const Handle ptrn,
const Handle grnd 
)
virtual

Typically called for AbsentLink

The default semantics here is to reject a match if the option clauses are detected. This is in keeping with the semantics AbsentLink: a match is possible only if the indicated clauses are absent!

Implements opencog::PatternMatchCallback.

Definition at line 229 of file DefaultPatternMatchCB.cc.

References _optionals_present, and opencog::Handle::UNDEFINED.

bool opencog::DefaultPatternMatchCB::optionals_present ( void  )
inline

Definition at line 85 of file DefaultPatternMatchCB.h.

References _optionals_present.

+ Here is the caller graph for this function:

bool DefaultPatternMatchCB::post_link_match ( const LinkPtr patt_link,
const LinkPtr grnd_link 
)
virtual

Called after a candidate grounding has been found for a link. This callback offers a final chance to reject the link match based on the actual grounding, or to perform post-match processing. Return true to reject the match.

That is, this callback is called after the two links have been fully compared, and have been found to match. It offers a chance to record the candidate grounding, or to reject it for some reason.

The first link is from the pattern, the second is from the proposed grounding.

Reimplemented from opencog::PatternMatchCallback.

Definition at line 149 of file DefaultPatternMatchCB.cc.

References _as, _dynamic, _have_evaluatables, opencog::EvaluationLink::do_evaluate(), and tv.

void DefaultPatternMatchCB::set_pattern ( const Variables vars,
const Pattern pat 
)
virtual

Called before search initiation, to indicate the pattern that will be searched for, and the variables to be grounded during the search.

Implements opencog::PatternMatchCallback.

Reimplemented in opencog::SatisfyingSet, opencog::AFImplicator, opencog::Satisfier, opencog::BackwardChainerPMCB, opencog::DefaultImplicator, opencog::ForwardChainerPMCB, and opencog::FuzzyPatternMatchCB.

Definition at line 54 of file DefaultPatternMatchCB.cc.

References _dynamic, _have_evaluatables, _type_restrictions, opencog::Pattern::evaluatable_terms, and opencog::Variables::typemap.

+ Here is the caller graph for this function:

bool DefaultPatternMatchCB::variable_match ( const Handle npat_h,
const Handle nsoln_h 
)
virtual

Called when a variable in the template pattern needs to be compared to a possible grounding node in the atomspace. The first argument is a variable from the pattern, and the second is a possible grounding node from the atomspace. Return true if the nodes match, else return false.

Implements opencog::PatternMatchCallback.

Reimplemented in opencog::UnifyPMCB.

Definition at line 90 of file DefaultPatternMatchCB.cc.

References _type_restrictions, and opencog::Atom::getType().

+ Here is the caller graph for this function:

Member Data Documentation

AtomSpace* opencog::DefaultPatternMatchCB::_as
protected

Definition at line 106 of file DefaultPatternMatchCB.h.

ClassServer& opencog::DefaultPatternMatchCB::_classserver
protected

Definition at line 88 of file DefaultPatternMatchCB.h.

std::set<Type> opencog::DefaultPatternMatchCB::_connectives
protected

Definition at line 99 of file DefaultPatternMatchCB.h.

const std::set<Handle>* opencog::DefaultPatternMatchCB::_dynamic = NULL
protected

Definition at line 91 of file DefaultPatternMatchCB.h.

bool opencog::DefaultPatternMatchCB::_have_evaluatables = false
protected

Definition at line 92 of file DefaultPatternMatchCB.h.

Instantiator opencog::DefaultPatternMatchCB::_instor
protected

Definition at line 96 of file DefaultPatternMatchCB.h.

bool opencog::DefaultPatternMatchCB::_optionals_present = false
protected

Definition at line 105 of file DefaultPatternMatchCB.h.

AtomSpace opencog::DefaultPatternMatchCB::_temp_aspace
protected

Definition at line 95 of file DefaultPatternMatchCB.h.

const VariableTypeMap* opencog::DefaultPatternMatchCB::_type_restrictions = NULL
protected

Definition at line 90 of file DefaultPatternMatchCB.h.


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