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

#include <FuzzyPatternMatchCB.h>

+ Inheritance diagram for opencog::FuzzyPatternMatchCB:
+ Collaboration diagram for opencog::FuzzyPatternMatchCB:

Classes

struct  Starter
 

Public Member Functions

 FuzzyPatternMatchCB (AtomSpace *, Type, const HandleSeq &)
 
virtual bool initiate_search (PatternMatchEngine *pme)
 
virtual void set_pattern (const Variables &vars, const Pattern &pat)
 
virtual bool fuzzy_match (const Handle &h1, const Handle &h2)
 
virtual bool link_match (const LinkPtr &pLink, const LinkPtr &gLink)
 
virtual bool node_match (const Handle &pNode, const Handle &gNode)
 
virtual bool grounding (const std::map< Handle, Handle > &var_soln, const std::map< Handle, Handle > &term_soln)
 
- Public Member Functions inherited from opencog::DefaultPatternMatchCB
 DefaultPatternMatchCB (AtomSpace *)
 
virtual bool variable_match (const Handle &, const Handle &)
 
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 IncomingSet get_incoming_set (const Handle &h)
 
virtual void push (void)
 
virtual void pop (void)
 

Public Attributes

HandleSeq solns
 

Private Member Functions

void find_starters (const Handle &hg, const size_t &depth, const size_t &clause_idx, const Handle &term, std::vector< Starter > &rtn)
 
void check_if_accept (const Handle &gh)
 

Private Attributes

const Pattern_pattern = NULL
 
Handle clause
 
HandleSeq pat_nodes
 
Type rtn_type
 
HandleSeq excl_list
 
size_t pat_size = 0
 
std::vector< Starterstarters
 
std::vector< UUIDprev_compared
 
std::unordered_map< Handle,
size_t > 
in_set_sizes
 
size_t min_size_diff = SIZE_MAX
 
double max_similarity = -std::numeric_limits<double>::max()
 

Additional Inherited Members

- Protected Member Functions inherited from opencog::DefaultPatternMatchCB
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 inherited from opencog::DefaultPatternMatchCB
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

Definition at line 31 of file FuzzyPatternMatchCB.h.

Constructor & Destructor Documentation

FuzzyPatternMatchCB::FuzzyPatternMatchCB ( AtomSpace as,
Type  rt,
const HandleSeq excl 
)

Definition at line 31 of file FuzzyPatternMatchCB.cc.

Member Function Documentation

void FuzzyPatternMatchCB::check_if_accept ( const Handle gh)
private

Compare and estimate the similarity between the pattern and the potential solution, and decide whether or not to accept it. The potential solution will be accepted if it has a similarity greater than or equals to the maximum similarity that we know, rejected otherwise.

Parameters
ghThe potential solution

Definition at line 197 of file FuzzyPatternMatchCB.cc.

References clause, excl_list, opencog::get_all_nodes(), in_set_sizes, max_similarity, min_size_diff, pat_nodes, pat_size, solns, and opencog::Atom::toShortString().

+ Here is the caller graph for this function:

void FuzzyPatternMatchCB::find_starters ( const Handle hp,
const size_t &  depth,
const size_t &  clause_idx,
const Handle term,
std::vector< Starter > &  rtn 
)
private

Find the starters that can be used to initiate a fuzzy-search. Currently the starters has to be a node that is not an instance nor a variable.

Parameters
hpThe pattern (the hypergraph in the query)
depthThe depth of the starter in the pattern
clause_idxThe index of the clause, i.e. which clause the starter is in among all input clauses
termThe term that the starter is located in the pattern
rtnA list of potential starters found in the pattern

Definition at line 49 of file FuzzyPatternMatchCB.cc.

References opencog::FuzzyPatternMatchCB::Starter::depth, excl_list, opencog::Atom::getIncomingSetSize(), opencog::FuzzyPatternMatchCB::Starter::handle, opencog::LinkCast(), opencog::NodeCast(), pat_size, opencog::FuzzyPatternMatchCB::Starter::term, opencog::Handle::UNDEFINED, opencog::FuzzyPatternMatchCB::Starter::uuid, opencog::Handle::value(), and opencog::FuzzyPatternMatchCB::Starter::width.

+ Here is the caller graph for this function:

virtual bool opencog::FuzzyPatternMatchCB::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 49 of file FuzzyPatternMatchCB.h.

virtual bool opencog::FuzzyPatternMatchCB::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 61 of file FuzzyPatternMatchCB.h.

bool FuzzyPatternMatchCB::initiate_search ( PatternMatchEngine pme)
virtual

Implement the initiate_search method in the Pattern Matcher. The main difference between this method and the default one is that this initiates multiple searches using differnt nodes as starters instead of one, explores the neighborhood of each of them, and captures the partial matches in the callbacks. It stops when there are no more available starters in the pattern.

Parameters
pmeThe PatternMatchEngine object
Returns
True if one or more solutions are found, false otherwise

Implements opencog::PatternMatchCallback.

Definition at line 95 of file FuzzyPatternMatchCB.cc.

References _pattern, clause, opencog::FuzzyPatternMatchCB::Starter::depth, opencog::PatternMatchEngine::explore_neighborhood(), find_starters(), opencog::Atom::getIncomingSet(), opencog::Pattern::mandatory, solns, starters, opencog::Atom::toShortString(), opencog::FuzzyPatternMatchCB::Starter::uuid, and opencog::FuzzyPatternMatchCB::Starter::width.

bool FuzzyPatternMatchCB::link_match ( const LinkPtr pl,
const LinkPtr gl 
)
virtual

Implement the link_match callback.

It compares and estimates the similarity between the pattern and the potential solution found.

Parameters
plA link in the pattern
glA potential solution
Returns
Always return true to accept it, and keep the matching going

Reimplemented from opencog::DefaultPatternMatchCB.

Definition at line 171 of file FuzzyPatternMatchCB.cc.

References check_if_accept(), clause, opencog::get_all_nodes(), opencog::Atom::getHandle(), pat_nodes, prev_compared, rtn_type, and opencog::Handle::value().

virtual bool opencog::FuzzyPatternMatchCB::node_match ( const Handle npat_h,
const Handle nsoln_h 
)
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 (grounding) node from the atomspace.

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

Reimplemented from opencog::DefaultPatternMatchCB.

Definition at line 56 of file FuzzyPatternMatchCB.h.

virtual void opencog::FuzzyPatternMatchCB::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.

Reimplemented from opencog::DefaultPatternMatchCB.

Definition at line 42 of file FuzzyPatternMatchCB.h.

References _pattern, and opencog::DefaultPatternMatchCB::set_pattern().

Member Data Documentation

const Pattern* opencog::FuzzyPatternMatchCB::_pattern = NULL
private

Definition at line 68 of file FuzzyPatternMatchCB.h.

Handle opencog::FuzzyPatternMatchCB::clause
private

Definition at line 71 of file FuzzyPatternMatchCB.h.

HandleSeq opencog::FuzzyPatternMatchCB::excl_list
private

Definition at line 80 of file FuzzyPatternMatchCB.h.

std::unordered_map<Handle, size_t> opencog::FuzzyPatternMatchCB::in_set_sizes
private

Definition at line 101 of file FuzzyPatternMatchCB.h.

double opencog::FuzzyPatternMatchCB::max_similarity = -std::numeric_limits<double>::max()
private

Definition at line 107 of file FuzzyPatternMatchCB.h.

size_t opencog::FuzzyPatternMatchCB::min_size_diff = SIZE_MAX
private

Definition at line 104 of file FuzzyPatternMatchCB.h.

HandleSeq opencog::FuzzyPatternMatchCB::pat_nodes
private

Definition at line 74 of file FuzzyPatternMatchCB.h.

size_t opencog::FuzzyPatternMatchCB::pat_size = 0
private

Definition at line 92 of file FuzzyPatternMatchCB.h.

std::vector<UUID> opencog::FuzzyPatternMatchCB::prev_compared
private

Definition at line 98 of file FuzzyPatternMatchCB.h.

Type opencog::FuzzyPatternMatchCB::rtn_type
private

Definition at line 77 of file FuzzyPatternMatchCB.h.

HandleSeq opencog::FuzzyPatternMatchCB::solns

Definition at line 36 of file FuzzyPatternMatchCB.h.

std::vector<Starter> opencog::FuzzyPatternMatchCB::starters
private

Definition at line 95 of file FuzzyPatternMatchCB.h.


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