27 using namespace opencog;
50 const size_t& clause_idx,
52 std::vector<Starter>& rtn)
57 for (
Handle h : lp->getOutgoingSet())
68 if ((np->getType() != VARIABLE_NODE) and
69 (np->getName().find(
"@") == std::string::npos) and
105 {
return s1.
uuid < s2.uuid; });
108 {
return s1.
uuid == s2.uuid; }),
114 if (s1.
width == s2.width)
return s1.
depth > s2.depth;
115 else return s1.
width < s2.width;
121 size_t search_cnt = 0;
122 size_t num_starters =
starters.size();
123 while (num_starters > search_cnt) {
129 std::cout <<
"\n========================================\n";
130 std::cout <<
"Initiating the fuzzy match... (" << search_cnt <<
"/"
131 << num_starters <<
")\n";
132 std::cout <<
"Starter:\n" << best_start->
toShortString() <<
"\n";
133 std::cout <<
"Start term:\n" << starter_term->
toShortString();
134 std::cout <<
"========================================\n\n";
138 size_t iset_size = iset.size();
139 for (
size_t i = 0; i < iset_size; i++) {
143 std::cout <<
"Loop candidate (" << (i + 1) <<
"/" << iset_size <<
"):\n"
152 if (
solns.size() > 0) {
153 std::cout <<
"Fuzzy match is finished.\n";
204 if (std::find(gn.begin(), gn.end(), eh) != gn.end()) {
207 <<
"due to the existance of:\n" << eh->toShortString()
217 std::sort(gn.begin(), gn.end());
219 std::back_inserter(common_nodes));
222 size_t diff = std::abs((
int)(
pat_size - gn.size()));
224 double similarity = 0;
226 for (
const Handle& common_node : common_nodes) {
230 iss = common_node->getIncomingSetSize();
233 else iss = it->second;
237 similarity += 1.0 / iss;
241 std::cout <<
"\n========================================\n";
244 std::cout <<
"Common nodes = " << common_nodes.size() <<
"\n";
245 std::cout <<
"Size diff = " << diff <<
"\n";
246 std::cout <<
"Similarity = " << similarity <<
"\n";
248 std::cout <<
"========================================\n\n";
252 if ((similarity > max_similarity) or
254 max_similarity = similarity;
260 else if (similarity == max_similarity and diff ==
min_size_diff) {
std::vector< UUID > prev_compared
bool explore_neighborhood(const Handle &, const Handle &, const Handle &)
IncomingSet getIncomingSet()
std::vector< Handle > HandleSeq
a list of handles
std::vector< Starter > starters
virtual std::string toShortString(std::string indent="")=0
std::shared_ptr< Link > LinkPtr
static NodePtr NodeCast(const Handle &h)
void check_if_accept(const Handle &gh)
static const Handle UNDEFINED
HandleSeq get_all_nodes(Handle h)
unsigned long UUID
UUID == Universally Unique Identifier.
std::unordered_map< Handle, size_t > in_set_sizes
static LinkPtr LinkCast(const Handle &h)
std::vector< LinkPtr > IncomingSet
std::shared_ptr< Node > NodePtr
unsigned short Type
type of Atoms, represented as short integer (16 bits)
size_t getIncomingSetSize()
Get the size of the incoming set.
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)