OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FuzzyPatternMatchCB.h
Go to the documentation of this file.
1 /*
2  * FuzzyPatternMatchCB.h
3  *
4  * Copyright (C) 2015 OpenCog Foundation
5  *
6  * Author: Leung Man Hin <https://github.com/leungmanhin>
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 FUZZYPATTERNMATCHCB_H
25 #define FUZZYPATTERNMATCHCB_H
26 
28 
29 namespace opencog
30 {
33  {
34  public:
35  // The solutions
37 
39 
40  virtual bool initiate_search(PatternMatchEngine* pme);
41 
42  virtual void set_pattern(const Variables& vars,
43  const Pattern& pat)
44  {
46  _pattern = &pat;
47  }
48 
49  virtual bool fuzzy_match(const Handle& h1, const Handle& h2)
50  {
51  return true;
52  }
53 
54  virtual bool link_match(const LinkPtr& pLink, const LinkPtr& gLink);
55 
56  virtual bool node_match(const Handle& pNode, const Handle& gNode)
57  {
58  return true;
59  }
60 
61  virtual bool grounding(const std::map<Handle, Handle>& var_soln,
62  const std::map<Handle, Handle>& term_soln)
63  {
64  return true;
65  }
66 
67  private:
68  const Pattern* _pattern = NULL;
69 
70  // The input pattern
72 
73  // The nodes in the pattern
75 
76  // Type of atom that we are looking for
78 
79  // List of atoms that we don't want them to exist in the solutions
81 
82  struct Starter
83  {
87  size_t width;
88  size_t depth;
89  };
90 
91  // How many nodes are there in the pattern
92  size_t pat_size = 0;
93 
94  // Potential starters that can be used to initiate the search
95  std::vector<Starter> starters;
96 
97  // Links that have previously been compared
98  std::vector<UUID> prev_compared;
99 
100  // Stores the incoming set sizes of nodes
101  std::unordered_map<Handle, size_t> in_set_sizes;
102 
103  // The minimum difference between the pattern and all the known solutions
104  size_t min_size_diff = SIZE_MAX;
105 
106  // The maximum similarity of all the potential solutions we found
107  double max_similarity = -std::numeric_limits<double>::max();
108 
109  void find_starters(const Handle& hg, const size_t& depth,
110  const size_t& clause_idx, const Handle& term,
111  std::vector<Starter>& rtn);
112 
113  void check_if_accept(const Handle& gh);
114  };
115 }
116 
117 #endif // FUZZYPATTERNMATCHCB_H
118 
std::vector< UUID > prev_compared
virtual bool fuzzy_match(const Handle &h1, const Handle &h2)
virtual void set_pattern(const Variables &, const Pattern &)
std::vector< Handle > HandleSeq
a list of handles
Definition: Handle.h:246
std::vector< Starter > starters
std::shared_ptr< Link > LinkPtr
Definition: Atom.h:53
virtual void set_pattern(const Variables &vars, const Pattern &pat)
void check_if_accept(const Handle &gh)
virtual bool grounding(const std::map< Handle, Handle > &var_soln, const std::map< Handle, Handle > &term_soln)
virtual bool node_match(const Handle &pNode, const Handle &gNode)
unsigned long UUID
UUID == Universally Unique Identifier.
Definition: Handle.h:46
std::unordered_map< Handle, size_t > in_set_sizes
unsigned short Type
type of Atoms, represented as short integer (16 bits)
Definition: types.h:40
virtual bool link_match(const LinkPtr &pLink, const LinkPtr &gLink)
void find_starters(const Handle &hg, const size_t &depth, const size_t &clause_idx, const Handle &term, std::vector< Starter > &rtn)
FuzzyPatternMatchCB(AtomSpace *, Type, const HandleSeq &)
virtual bool initiate_search(PatternMatchEngine *pme)