OpenCog Framework
Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
|
#include <DefaultPatternMatchCB.h>
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) |
![]() | |
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 |
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.
DefaultPatternMatchCB::DefaultPatternMatchCB | ( | AtomSpace * | as | ) |
Definition at line 42 of file DefaultPatternMatchCB.cc.
References _connectives.
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().
|
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().
|
protected |
Definition at line 239 of file DefaultPatternMatchCB.cc.
References _instor, _temp_aspace, opencog::AtomSpace::clear(), dbgprt, opencog::EvaluationLink::do_evaluate(), opencog::Instantiator::instantiate(), and opencog::Atom::toShortString().
|
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().
|
inlinevirtual |
Reimplemented from opencog::PatternMatchCallback.
Definition at line 80 of file DefaultPatternMatchCB.h.
References _connectives.
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.
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.
|
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.
|
inline |
Definition at line 85 of file DefaultPatternMatchCB.h.
References _optionals_present.
|
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.
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.
|
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().
|
protected |
Definition at line 106 of file DefaultPatternMatchCB.h.
|
protected |
Definition at line 88 of file DefaultPatternMatchCB.h.
|
protected |
Definition at line 99 of file DefaultPatternMatchCB.h.
|
protected |
Definition at line 91 of file DefaultPatternMatchCB.h.
|
protected |
Definition at line 92 of file DefaultPatternMatchCB.h.
|
protected |
Definition at line 96 of file DefaultPatternMatchCB.h.
|
protected |
Definition at line 105 of file DefaultPatternMatchCB.h.
|
protected |
Definition at line 95 of file DefaultPatternMatchCB.h.
|
protected |
Definition at line 90 of file DefaultPatternMatchCB.h.