OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PMCGroundings Class Reference
+ Inheritance diagram for PMCGroundings:
+ Collaboration diagram for PMCGroundings:

Public Member Functions

 PMCGroundings (PatternMatchCallback &cb)
 
bool node_match (const Handle &node1, const Handle &node2)
 
bool variable_match (const Handle &node1, const Handle &node2)
 
bool link_match (const LinkPtr &link1, const LinkPtr &link2)
 
bool post_link_match (const LinkPtr &link1, const LinkPtr &link2)
 
bool fuzzy_match (const Handle &h1, const Handle &h2)
 
bool evaluate_sentence (const Handle &link_h, const std::map< Handle, Handle > &gnds)
 
bool clause_match (const Handle &pattrn_link_h, const Handle &grnd_link_h)
 
bool optional_clause_match (const Handle &pattrn, const Handle &grnd)
 
IncomingSet get_incoming_set (const Handle &h)
 
void push (void)
 
void pop (void)
 
void set_pattern (const Variables &vars, const Pattern &pat)
 
bool initiate_search (PatternMatchEngine *pme)
 
bool grounding (const std::map< Handle, Handle > &var_soln, const std::map< Handle, Handle > &term_soln)
 
- Public Member Functions inherited from opencog::PatternMatchCallback
virtual ~PatternMatchCallback ()
 
virtual const std::set< Type > & get_connectives (void)
 

Public Attributes

std::vector< std::map< Handle,
Handle > > 
_term_groundings
 
std::vector< std::map< Handle,
Handle > > 
_var_groundings
 

Private Attributes

PatternMatchCallback_cb
 

Detailed Description

A pass-through class, which wraps a regular callback, but captures all of the different possible groundings that result. This class is used to piece together graphs out of multiple components.

Definition at line 50 of file PatternMatch.cc.

Constructor & Destructor Documentation

PMCGroundings::PMCGroundings ( PatternMatchCallback cb)
inline

Definition at line 56 of file PatternMatch.cc.

Member Function Documentation

bool PMCGroundings::clause_match ( const Handle pattrn_link_h,
const Handle grnd_link_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 from opencog::PatternMatchCallback.

Definition at line 79 of file PatternMatch.cc.

bool PMCGroundings::evaluate_sentence ( const Handle eval,
const std::map< Handle, Handle > &  gnds 
)
inlinevirtual

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.

Implements opencog::PatternMatchCallback.

Definition at line 74 of file PatternMatch.cc.

bool PMCGroundings::fuzzy_match ( const Handle ph,
const Handle gh 
)
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 from opencog::PatternMatchCallback.

Definition at line 71 of file PatternMatch.cc.

IncomingSet PMCGroundings::get_incoming_set ( const Handle 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 from opencog::PatternMatchCallback.

Definition at line 85 of file PatternMatch.cc.

bool PMCGroundings::grounding ( const std::map< Handle, Handle > &  var_soln,
const std::map< Handle, Handle > &  term_soln 
)
inlinevirtual

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.

Implements opencog::PatternMatchCallback.

Definition at line 103 of file PatternMatch.cc.

bool PMCGroundings::initiate_search ( PatternMatchEngine )
inlinevirtual

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.

Implements opencog::PatternMatchCallback.

Definition at line 96 of file PatternMatch.cc.

bool PMCGroundings::link_match ( const LinkPtr patt_link,
const LinkPtr grnd_link 
)
inlinevirtual

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.

Implements opencog::PatternMatchCallback.

Definition at line 65 of file PatternMatch.cc.

bool PMCGroundings::node_match ( const Handle patt_node,
const Handle grnd_node 
)
inlinevirtual

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).

Implements opencog::PatternMatchCallback.

Definition at line 59 of file PatternMatch.cc.

bool PMCGroundings::optional_clause_match ( const Handle pattrn,
const Handle grnd 
)
inlinevirtual

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.

Implements opencog::PatternMatchCallback.

Definition at line 82 of file PatternMatch.cc.

void PMCGroundings::pop ( void  )
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 from opencog::PatternMatchCallback.

Definition at line 89 of file PatternMatch.cc.

bool PMCGroundings::post_link_match ( const LinkPtr patt_link,
const LinkPtr grnd_link 
)
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 from opencog::PatternMatchCallback.

Definition at line 68 of file PatternMatch.cc.

void PMCGroundings::push ( void  )
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 from opencog::PatternMatchCallback.

Definition at line 88 of file PatternMatch.cc.

void PMCGroundings::set_pattern ( const Variables vars,
const Pattern pat 
)
inlinevirtual

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.

Definition at line 90 of file PatternMatch.cc.

bool PMCGroundings::variable_match ( const Handle patt_node,
const Handle grnd_node 
)
inlinevirtual

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).

Implements opencog::PatternMatchCallback.

Definition at line 62 of file PatternMatch.cc.

Member Data Documentation

PatternMatchCallback& PMCGroundings::_cb
private

Definition at line 53 of file PatternMatch.cc.

std::vector<std::map<Handle, Handle> > PMCGroundings::_term_groundings

Definition at line 111 of file PatternMatch.cc.

std::vector<std::map<Handle, Handle> > PMCGroundings::_var_groundings

Definition at line 112 of file PatternMatch.cc.


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