OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PatternMatchCallback.h
Go to the documentation of this file.
1 /*
2  * PatternMatchCallback.h
3  *
4  * Author: Linas Vepstas February 2008
5  *
6  * Copyright (C) 2008,2009,2014 Linas Vepstas <linasvepstas@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Affero General Public License v3 as
10  * published by the Free Software Foundation and including the exceptions
11  * at http://opencog.org/wiki/Licenses
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with this program; if not, write to:
20  * Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #ifndef _OPENCOG_PATTERN_MATCH_CALLBACK_H
25 #define _OPENCOG_PATTERN_MATCH_CALLBACK_H
26 
27 #include <map>
28 #include <set>
30 #include <opencog/atomspace/Link.h>
31 #include <opencog/atoms/bind/VariableList.h> // for VariableTypeMap
32 
33 // #define DEBUG 1
34 
35 namespace opencog {
36 class PatternMatchEngine;
37 
43 {
44  public:
45  virtual ~PatternMatchCallback() {};
46 
56  virtual bool node_match(const Handle& patt_node,
57  const Handle& grnd_node) = 0;
58 
68  virtual bool variable_match(const Handle& patt_node,
69  const Handle& grnd_node) = 0;
70 
96  virtual bool link_match(const LinkPtr& patt_link,
97  const LinkPtr& grnd_link) = 0;
98 
115  virtual bool post_link_match(const LinkPtr& patt_link,
116  const LinkPtr& grnd_link)
117  {
118  return true; // Accept the match, by default.
119  }
120 
128  virtual bool fuzzy_match(const Handle& ph, const Handle& gh)
129  {
130  return false;
131  }
132 
184  virtual bool evaluate_sentence(const Handle& eval,
185  const std::map<Handle,Handle>& gnds) = 0;
186 
200  virtual bool clause_match(const Handle& pattrn_link_h,
201  const Handle& grnd_link_h)
202  {
203  // By default, reject a clause that is grounded by itself.
204  // XXX someone commented this out... why??? Do you really
205  // want self-grounding???
206  // if (pattrn_link_h == grnd_link_h) return false;
207  return true;
208  }
209 
224  virtual bool optional_clause_match(const Handle& pattrn,
225  const Handle& grnd) = 0;
226 
239  virtual bool grounding(const std::map<Handle, Handle> &var_soln,
240  const std::map<Handle, Handle> &term_soln) = 0;
241 
252  {
253  return h->getIncomingSet();
254  }
255 
261  virtual void push(void) {}
262 
269  virtual void pop(void) {}
270 
271  virtual const std::set<Type>& get_connectives(void)
272  { static const std::set<Type> _empty; return _empty; }
273 
287  virtual bool initiate_search(PatternMatchEngine *) = 0;
288 
294  virtual void set_pattern(const Variables& vars,
295  const Pattern& pat) = 0;
296 };
297 
298 } // namespace opencog
299 
300 #endif // _OPENCOG_PATTERN_MATCH_CALLBACK_H
virtual bool optional_clause_match(const Handle &pattrn, const Handle &grnd)=0
virtual bool evaluate_sentence(const Handle &eval, const std::map< Handle, Handle > &gnds)=0
virtual bool initiate_search(PatternMatchEngine *)=0
IncomingSet getIncomingSet()
Definition: Atom.cc:321
virtual bool post_link_match(const LinkPtr &patt_link, const LinkPtr &grnd_link)
virtual void set_pattern(const Variables &vars, const Pattern &pat)=0
std::shared_ptr< Link > LinkPtr
Definition: Atom.h:53
virtual IncomingSet get_incoming_set(const Handle &h)
virtual bool clause_match(const Handle &pattrn_link_h, const Handle &grnd_link_h)
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 node_match(const Handle &patt_node, const Handle &grnd_node)=0
std::vector< LinkPtr > IncomingSet
Definition: Atom.h:55
virtual bool grounding(const std::map< Handle, Handle > &var_soln, const std::map< Handle, Handle > &term_soln)=0
virtual const std::set< Type > & get_connectives(void)
virtual bool fuzzy_match(const Handle &ph, const Handle &gh)