OpenCog Framework
Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
|
#include <PatternMatchCallback.h>
Public Member Functions | |
virtual | ~PatternMatchCallback () |
virtual bool | node_match (const Handle &patt_node, const Handle &grnd_node)=0 |
virtual bool | variable_match (const Handle &patt_node, const Handle &grnd_node)=0 |
virtual bool | link_match (const LinkPtr &patt_link, const LinkPtr &grnd_link)=0 |
virtual bool | post_link_match (const LinkPtr &patt_link, const LinkPtr &grnd_link) |
virtual bool | fuzzy_match (const Handle &ph, const Handle &gh) |
virtual bool | evaluate_sentence (const Handle &eval, const std::map< Handle, Handle > &gnds)=0 |
virtual bool | clause_match (const Handle &pattrn_link_h, const Handle &grnd_link_h) |
virtual bool | optional_clause_match (const Handle &pattrn, const Handle &grnd)=0 |
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 const std::set< Type > & | get_connectives (void) |
virtual bool | initiate_search (PatternMatchEngine *)=0 |
virtual void | set_pattern (const Variables &vars, const Pattern &pat)=0 |
Callback interface, used to implement specifics of hypergraph matching, and also, to report solutions when found.
Definition at line 42 of file PatternMatchCallback.h.
|
inlinevirtual |
Definition at line 45 of file PatternMatchCallback.h.
|
inlinevirtual |
Called when a top-level clause has been fully grounded. This is meant to be used for evaluating the truth value of the clause, as an intermediate stage for evaluating the overall truth value of a solution (grounding).
A clause match has occured if all calls to node_match(), variable_match(), link_match() and post_link_match() in that clause have returned true.
Return false to reject this clause as a valid grounding, return true to accept this grounding.
Reimplemented in PMCGroundings, and opencog::DefaultPatternMatchCB.
Definition at line 200 of file PatternMatchCallback.h.
|
pure virtual |
Invoked to confirm or deny a candidate grounding for term that consistes entirely of connectives and evaluatable terms.
An 'evaluatable term' is any pattern term (term occuring in the search pattern, either a node or link) that was previously declared as 'evaluatable', by the 'set_evaluatable_terms()' callback below. Thus, for example, the canonical, default convention is that evaluatable terms are any terms that contain a GPN – a 'GroundedPredicateNode', and therefore requires running code that lies outside of the pattern matcher (typically scheme or python code). In general, though, evaluatable terms don't have to be of this sort – they can be any part of the search pattern that was previously specified by the 'set_evaluatable_terms()' callback.
Connectives are any link types that were declared by the 'get_connectives()' callback, below. Connectives are those link types that are are able to combine evaluatable terms. For example, the canonical, default connectives are logic connectives: AndLink, OrLink, NotLink. They don't have to be these, but, that is what they would be if emulating a logic that uses the classical boolean logic values of true/false.
For another example, they might be SetUnion, SetIntersectionLink, and SetComplimentLink if emulating a logic that uses probability values for truth values (so, e.g. SetUnionLink would connect the probability of A or B, i.e. it would compute P(A or B) SetIntersectionLink would compute P(A and B), and so on.
Unlike the other callbacks, this takes arguments in s slightly different form. Here, 'eval' is the evalutatable term, and 'gnds' contains the currently-proposed grounding for any variables occuring within that term. It is a map: the 'key' is either a variable, or another term whose grounding is being currently considered, and the 'value' is the proposed grounding.
In ordinary logic, a well-formed formula with no free variables is called a "sentence". Thus, in the sense of logic, the 'eval' argument, together with 'gnds' combine to bind values to all the variables in 'term', thus leaving a sentence with no free variables. In logic, sentences are always true or false, ergo the the return value.
The return value follows the same convention as all the other callbacks: 'true' accepts the grounding, and the search for the rest of the pattern continues, while 'false' rejects the grounding, and forces a backtrack.
Implemented in opencog::DefaultPatternMatchCB, and PMCGroundings.
|
inlinevirtual |
Called when the template pattern and the candidate grounding are not having the same type, or one of them are undefined. It is obviously a mismatch so it returns false by default, but it would be useful if we are not looking for an exact match. It gives the Pattern Matcher more flexibility.
Reimplemented in PMCGroundings, and opencog::FuzzyPatternMatchCB.
Definition at line 128 of file PatternMatchCallback.h.
|
inlinevirtual |
Reimplemented in opencog::DefaultPatternMatchCB.
Definition at line 271 of file PatternMatchCallback.h.
|
inlinevirtual |
Called whenever the incoming set of an atom is to be explored. This callback allows the search space to be prioritized, by returning (all or some of) the incoming set in some sorted order: the first in the list will be searched first. The search space can also be limited, by returning a set that is smaller than the full incoming set (for example, by returning only those atoms with a high av-sti).
Reimplemented in PMCGroundings, and opencog::AttentionalFocusCB.
Definition at line 251 of file PatternMatchCallback.h.
References opencog::Atom::getIncomingSet().
|
pure virtual |
Called when a complete grounding for all clauses is found. Should return false to search for more solutions; or return true to terminate search. (Just as in all the other callbacks, a return value of true
means that the proposed grounding is acceptable. The engine is designed to halt once an acceptable solution has been found; thus, in order to force it to search for more, a return value of false is needed.)
Note that the callback may be called many times reporting the same result.
Implemented in opencog::SatisfyingSet, PMCGroundings, opencog::Satisfier, opencog::Implicator, opencog::ForwardChainerPMCB, opencog::FuzzyPatternMatchCB, opencog::BackwardChainerPMCB, opencog::VarGroundingPMCB, and opencog::UnifyPMCB.
|
pure virtual |
Called to initiate the search. This callback is responsible for performing the top-most, outer loop of the search. That is, it gets to pick the starting points for the search, thereby possibly limiting the breadth of the search. It may also cull the variables, clauses, or negated clauses to remove those that will not alter the final semantics of the search.
The return value is used to indicate if the search pattern was satisfied (grounded) or not. This is just like the return values on all the other callbacks; it summarizes (passes through) the return values of all the others.
Implemented in PMCGroundings, opencog::InitiateSearchCB, and opencog::FuzzyPatternMatchCB.
|
pure virtual |
Called right before link in the template pattern is 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 grounding link from the atomspace. Return true if the link contents should be compared, else return false. (i.e. return false if mis-match).
If true is returned, then the pattern matcher will proceed, and will compare the outgoing sets of the two links. Thus, this callback should not bother with looking at the outgoing sets. Indeed, it is very possible that the outgoing sets will fail to match; but this is not yet known, at the time that this callback is made. By contrast, the post_link_match() callback will be called after a full grounding has been established; that is, after the outgoing sets have been compared.
This callback offers a good time to check the truth value, the attention value, and the link type, and to proceed with the search, or cut it off, based on these values.
Implemented in PMCGroundings, opencog::DefaultPatternMatchCB, opencog::ForwardChainerPMCB, opencog::FuzzyPatternMatchCB, and opencog::AttentionalFocusCB.
|
pure 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 node from the atomspace. Return true if the nodes match, else return false. (i.e. return false if mis-match).
Implemented in opencog::DefaultPatternMatchCB, PMCGroundings, opencog::ForwardChainerPMCB, opencog::FuzzyPatternMatchCB, and opencog::AttentionalFocusCB.
|
pure virtual |
Called when the search for a top-level optional clause has been completed. The clause may or may not have been grounded as a result of the search. If it has been grounded, then grnd will be non-null.
Return false to terminate further searches from this point on; the result of termination will be backtracking to search for other possible groundings of the required clauses. Return true to examine the next optional clause (if any).
Note that all required clauses will have been grounded before any optional clauses are examined.
Implemented in PMCGroundings, and opencog::DefaultPatternMatchCB.
|
inlinevirtual |
Called prior to starting a back-track, retreating from the most recently grounded top-level clause (tree). This gives the callee the opportunity to maintain state with a stack, if needed.
Reimplemented in PMCGroundings.
Definition at line 269 of file PatternMatchCallback.h.
|
inlinevirtual |
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 in PMCGroundings, and opencog::DefaultPatternMatchCB.
Definition at line 115 of file PatternMatchCallback.h.
|
inlinevirtual |
Called after a top-level clause (tree) has been fully grounded. This gives the callee the opportunity to save state onto a stack, if needed.
Reimplemented in PMCGroundings.
Definition at line 261 of file PatternMatchCallback.h.
|
pure virtual |
Called before search initiation, to indicate the pattern that will be searched for, and the variables to be grounded during the search.
Implemented in opencog::SatisfyingSet, PMCGroundings, opencog::AFImplicator, opencog::Satisfier, opencog::DefaultPatternMatchCB, opencog::InitiateSearchCB, opencog::BackwardChainerPMCB, opencog::DefaultImplicator, opencog::ForwardChainerPMCB, and opencog::FuzzyPatternMatchCB.
|
pure 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 solution node from the atomspace. Return true if the grouding is acceptable, else return false. (i.e. return false if mis-match).
Implemented in PMCGroundings, opencog::DefaultPatternMatchCB, and opencog::UnifyPMCB.