From efbdae7dd250c9fa68431c9024792292c4cc8c2b Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sat, 13 Jun 2020 11:25:20 -0500 Subject: [PATCH 1/6] Print flag bits about terms. --- opencog/atoms/pattern/PatternTerm.cc | 41 ++++++++++++++++++++++++---- opencog/atoms/pattern/PatternTerm.h | 2 ++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/opencog/atoms/pattern/PatternTerm.cc b/opencog/atoms/pattern/PatternTerm.cc index c34ca9ace8..390bb91755 100644 --- a/opencog/atoms/pattern/PatternTerm.cc +++ b/opencog/atoms/pattern/PatternTerm.cc @@ -301,15 +301,46 @@ void PatternTerm::markAlways() // ============================================================== -std::string PatternTerm::to_string() const { return to_string(": "); } +std::string PatternTerm::to_short_string() const { return to_string(": "); } -std::string PatternTerm::to_string(const std::string& indent) const +std::string PatternTerm::to_short_string(const std::string& sep) const { - // Term is null-terminated at thye top. + // Term is null-terminated at the top. // Top term never has a handle in it. if (not _handle) return "-"; - std::string str = _parent->to_string(); - str += indent + _handle->id_to_string(); + std::string str = _parent->to_short_string(sep); + str += sep + _handle->id_to_string(); + return str; +} + +std::string PatternTerm::to_string() const { return to_string(""); } + +std::string PatternTerm::to_string(const std::string& indent) const +{ + // Term is null-terminated at the top. + // Top term never has a handle in it. + if (not _handle) return "\n"; + std::string str = _parent->to_string(indent + " "); + str += indent; + const Handle& h = isQuoted() ? getQuote() : getHandle(); + str += nameserver().getTypeName(h->get_type()) + " : "; + if (isQuoted()) str += "Q: "; + if (_has_any_bound_var) str += "HABV: "; + if (_has_bound_var) str += "HBV: "; + if (_is_bound_var) str += "BV: "; + if (_has_any_globby_var) str += "HAGV: "; + if (_has_globby_var) str += "HGV: "; + if (_is_globby_var) str += "GV: "; + if (_has_any_evaluatable) str += "EE: "; + if (_has_evaluatable) str += "E: "; + if (_is_virtual) str += "V: "; + if (_has_any_unordered_link) str += "U: "; + if (_is_literal) str += "L: "; + if (_is_present) str += "P: "; + if (_is_absent) str += "A: "; + if (_is_choice) str += "C: "; + if (_is_always) str += "AW: "; + str += _handle->id_to_string() + "\n"; return str; } diff --git a/opencog/atoms/pattern/PatternTerm.h b/opencog/atoms/pattern/PatternTerm.h index a2bb4423b8..b726ac00aa 100644 --- a/opencog/atoms/pattern/PatternTerm.h +++ b/opencog/atoms/pattern/PatternTerm.h @@ -231,6 +231,8 @@ class PatternTerm // See http://stackoverflow.com/questions/16734783 for explanation. std::string to_string() const; std::string to_string(const std::string& indent) const; + std::string to_short_string() const; + std::string to_short_string(const std::string& indent) const; }; #define createPatternTerm std::make_shared From 246bc2effdfb73d877973a793e601f53a54b58c5 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sat, 13 Jun 2020 12:22:01 -0500 Subject: [PATCH 2/6] Improved debug printing. --- opencog/atoms/pattern/PatternTerm.h | 3 +- opencog/query/InitiateSearchMixin.cc | 9 ++- opencog/query/PatternMatchEngine.cc | 108 ++++++++++++++------------- 3 files changed, 65 insertions(+), 55 deletions(-) diff --git a/opencog/atoms/pattern/PatternTerm.h b/opencog/atoms/pattern/PatternTerm.h index b726ac00aa..0f3b1eda9b 100644 --- a/opencog/atoms/pattern/PatternTerm.h +++ b/opencog/atoms/pattern/PatternTerm.h @@ -183,7 +183,8 @@ class PatternTerm Arity getArity() const { return _outgoing.size(); } PatternTermPtr getOutgoingTerm(Arity pos) const; - const Handle& getQuote() const noexcept { return _quote; } + const Handle& getQuote() const noexcept { + return isQuoted() ? _quote : _handle; } Quotation& getQuotation() { return _quotation; }; const Quotation& getQuotation() const noexcept { return _quotation; } bool isQuoted() const { return _quotation.is_quoted(); } diff --git a/opencog/query/InitiateSearchMixin.cc b/opencog/query/InitiateSearchMixin.cc index d5287c3bbf..0ee47dfa54 100644 --- a/opencog/query/InitiateSearchMixin.cc +++ b/opencog/query/InitiateSearchMixin.cc @@ -365,9 +365,9 @@ bool InitiateSearchMixin::choice_loop(PatternMatchCallback& pmc, DO_LOG({LAZY_LOG_FINE << "Choice loop start term is: " << (_starter_term == (Atom*) nullptr ? - "UNDEFINED" : _starter_term->to_string());}) + "UNDEFINED" : _starter_term->to_short_string());}) DO_LOG({LAZY_LOG_FINE << "Choice loop root clause is: " - << _root->getHandle()->to_string();}) + << _root->getQuote()->to_string();}) bool found = search_loop(pmc, dbg_banner); // Terminate search if satisfied. @@ -996,8 +996,9 @@ bool InitiateSearchMixin::search_loop(PatternMatchCallback& pmc, for (const Handle& h : _search_set) { DO_LOG({LAZY_LOG_FINE << dbg_banner - << "\nLoop candidate (" << ++i << "/" << hsz << "):\n" - << h->to_string();}) + << "\n Loop candidate (" + << ++i << "/" << hsz << "):\n" + << h->to_short_string(" ");}) bool found = pme.explore_neighborhood(_starter_term, h, _root); if (found) return true; } diff --git a/opencog/query/PatternMatchEngine.cc b/opencog/query/PatternMatchEngine.cc index 44ba0f9014..e510f9df96 100644 --- a/opencog/query/PatternMatchEngine.cc +++ b/opencog/query/PatternMatchEngine.cc @@ -63,8 +63,22 @@ static inline void logmsg(const char * msg, const Handle& h) { LAZY_LOG_FINE << msg << std::endl << (h == (Atom*) nullptr ? - std::string("(invalid handle)") : - h->to_short_string()); + std::string(" (invalid handle)") : + h->to_short_string(" ")); +} + +static inline void logmsg(const char * msg, const PatternTermPtr& ptm) +{ + LAZY_LOG_FINE << msg << ptm->to_string(" ") + << ptm->getQuote()->to_short_string(" "); +} + +static inline void logmsg(const char * msg, const PatternTermPtr& ptm, + bool rslt) +{ + LAZY_LOG_FINE << msg << ptm->to_string(" ") + << ptm->getQuote()->to_short_string(" ") + << "\n Found: " << rslt; } static inline void logmsg(const char * msg, size_t n) @@ -77,9 +91,11 @@ static inline void logmsg(const char * msg) LAZY_LOG_FINE << msg; } #else -static inline void logmsg(const char * msg, const Handle& h) {} -static inline void logmsg(const char * msg, size_t n) {} -static inline void logmsg(const char * msg) {} +static inline void logmsg(const char*, const PatternTermPtr&, bool) {} +static inline void logmsg(const char*, const PatternTermPtr&) {} +static inline void logmsg(const char*, const Handle&) {} +static inline void logmsg(const char*, size_t) {} +static inline void logmsg(const char*) {} #endif @@ -1176,7 +1192,7 @@ bool PatternMatchEngine::tree_compare(const PatternTermPtr& ptm, bool match = _pmc.link_match(ptm, hg); if (not match) return false; - logmsg("depth=", depth); + logmsg("tree depth=", depth); logmsg("tree_compare:", hp); logmsg("to:", hg); @@ -1249,7 +1265,7 @@ bool PatternMatchEngine::explore_term_branches(const Handle& term, for (const PatternTermPtr &ptm : pl->second) { - DO_LOG({LAZY_LOG_FINE << "Begin exploring term: " << ptm->to_string();}) + logmsg("Begin exploring term:", ptm); bool found; if (ptm->hasAnyGlobbyVar()) found = explore_glob_branches(ptm, hg, clause); @@ -1258,9 +1274,7 @@ bool PatternMatchEngine::explore_term_branches(const Handle& term, else found = explore_type_branches(ptm, hg, clause); - DO_LOG({LAZY_LOG_FINE << "Finished exploring term: " - << ptm->to_string() - << " found=" << found; }) + logmsg("Finished exploring term:", ptm, found); if (found) return true; } return false; @@ -1379,7 +1393,7 @@ bool PatternMatchEngine::explore_upvar_branches(const PatternTermPtr& ptm, IncomingSet iset = _pmc.get_incoming_set(hg, t); size_t sz = iset.size(); DO_LOG({LAZY_LOG_FINE << "Looking upward at term = " - << parent->getHandle()->to_string() << std::endl + << parent->getQuote()->to_string() << std::endl << "The grounded pivot point " << hg->to_string() << " has " << sz << " branches";}) @@ -1425,7 +1439,7 @@ bool PatternMatchEngine::explore_upvar_branches(const PatternTermPtr& ptm, } _perm_breakout = nullptr; - DO_LOG({LAZY_LOG_FINE << "Found upward soln = " << found;}) + logmsg("Found upward soln =", found); return found; } @@ -1447,8 +1461,8 @@ bool PatternMatchEngine::explore_upglob_branches(const PatternTermPtr& ptm, size_t sz = iset.size(); DO_LOG({LAZY_LOG_FINE << "Looking globby upward for term = " - << parent->getHandle()->to_string() << std::endl - << "It's grounding " << hg->to_string() + << parent->getQuote()->to_string() << std::endl + << "It's grounding " << hg->to_short_string() << " has " << sz << " branches";}) // Move up the solution graph, looking for a match. @@ -1509,7 +1523,7 @@ bool PatternMatchEngine::explore_glob_branches(const PatternTermPtr& ptm, // if (explore_odometer(ptm, hg, clause)) if (explore_type_branches(ptm, hg, clause)) return true; - DO_LOG({logger().fine("Globby clause not grounded; try again");}) + logmsg("Globby clause not grounded; try again"); } while (_glob_state.size() > gstate_size); @@ -1535,8 +1549,7 @@ bool PatternMatchEngine::explore_odometer(const PatternTermPtr& ptm, _perm_take_step = true; _perm_go_around = false; - DO_LOG({LAZY_LOG_FINE << "ODO STEP unordered beneath term: " - << ptm->to_string();}) + logmsg("ODO STEP unordered beneath term:", ptm); if (explore_type_branches(ptm, hg, clause)) return true; } @@ -1568,7 +1581,7 @@ bool PatternMatchEngine::explore_unordered_branches(const PatternTermPtr& ptm, if (explore_single_branch(ptm, hg, clause)) return true; - DO_LOG({logger().fine("Step to next permutation");}) + logmsg("Step to next permutation"); // If we are here, there was no match. // On the next go-around, take a step. @@ -1579,7 +1592,7 @@ bool PatternMatchEngine::explore_unordered_branches(const PatternTermPtr& ptm, _perm_take_step = false; _perm_have_more = false; - DO_LOG({logger().fine("No more unordered permutations");}) + logmsg("No more unordered permutations"); return false; } @@ -1633,7 +1646,7 @@ bool PatternMatchEngine::explore_choice_branches(const PatternTermPtr& ptm, throw RuntimeException(TRACE_INFO, "Maybe this works but its not tested!! Find out!"); - DO_LOG({logger().fine("Begin choice branchpoint iteration loop");}) + logmsg("Begin choice branchpoint iteration loop"); do { // XXX This `need_choice_push` thing is probably wrong; it probably // should resemble the perm_push() used for unordered links. @@ -1648,14 +1661,14 @@ bool PatternMatchEngine::explore_choice_branches(const PatternTermPtr& ptm, if (match) return true; - DO_LOG({logger().fine("Step to next choice");}) + logmsg("Step to next choice"); // If we are here, there was no match. // On the next go-around, take a step. _choose_next = true; } while (have_choice(ptm, hg)); - DO_LOG({logger().fine("Exhausted all choice possibilities" - "\n----------------------------------");}) + logmsg("Exhausted all choice possibilities" + "\n----------------------------------"); return false; } @@ -1808,21 +1821,20 @@ bool PatternMatchEngine::explore_single_branch(const PatternTermPtr& ptm, { solution_push(); - DO_LOG({LAZY_LOG_FINE << "ssss Checking term=" << ptm->to_string() - << " for soln by " << hg->id_to_string();}) + logmsg("ssss Checking term=", ptm); + logmsg("ssss For soln by", hg); bool match = tree_compare(ptm, hg, CALL_SOLN); if (not match) { - DO_LOG({LAZY_LOG_FINE << "ssss NO solution for term=" - << ptm->to_string() - << " its NOT solved by " << hg->id_to_string();}) + logmsg("ssss NO solution for term=", ptm); + logmsg("ssss NOT solved by by", hg); solution_pop(); return false; } - logmsg("ssss Solved term:", ptm->getHandle()); + logmsg("ssss Solved term:", ptm); logmsg("ssss It is solved by:", hg); logmsg("ssss will move up."); @@ -1890,10 +1902,7 @@ bool PatternMatchEngine::do_term_up(const PatternTermPtr& ptm, // find its parent in the clause. For an evaluatable term, we find // the parent evaluatable in the clause, which may be many steps // higher. - DO_LOG({LAZY_LOG_FINE << "Term = " << ptm->to_string() - << "\n" << ptm->getHandle()->to_string() - // << "\nof clause = " << clause->getHandle()->to_string() - << "\nhas ground, move upwards";}) + logmsg("This term has ground, move upwards:", ptm); if (ptm->hasAnyEvaluatable()) { @@ -1903,7 +1912,7 @@ bool PatternMatchEngine::do_term_up(const PatternTermPtr& ptm, clause->getHandle()); bool found = _pmc.evaluate_sentence(clause->getHandle(), var_grounding); - DO_LOG({logger().fine("After evaluating clause, found = %d", found);}) + logmsg("After evaluating clause, found = ", found); if (found) return clause_accept(clause, hg); @@ -1923,14 +1932,14 @@ bool PatternMatchEngine::do_term_up(const PatternTermPtr& ptm, if (not parent->isChoice()) { bool found = explore_up_branches(ptm, hg, clause); - DO_LOG({logger().fine("After moving up the clause, found = %d", found);}) + logmsg("After moving up the clause, found = ", found); return found; } // If we are here, then we have Choice term. if (parent == clause) { - DO_LOG({logger().fine("Exploring Choice term at root");}) + logmsg("Exploring Choice term at root"); return clause_accept(clause, hg); } @@ -1941,7 +1950,7 @@ bool PatternMatchEngine::do_term_up(const PatternTermPtr& ptm, // (hop up) past the Choice term, before resuming the search. // The easiest way to hop is to do it recursively... i.e. // call ourselves again. - DO_LOG({logger().fine("Exploring Choice term below root");}) + logmsg("Exploring Choice term below root"); OC_ASSERT(not have_choice(parent, hg), "Something is wrong with the Choice code"); @@ -1970,7 +1979,7 @@ bool PatternMatchEngine::clause_accept(const PatternTermPtr& clause, { clause_accepted = true; match = _pmc.optional_clause_match(clause_root, hg, var_grounding); - DO_LOG({logger().fine("optional clause match callback match=%d", match);}) + logmsg("Optional clause match callback match=", match); } else if (clause->isAlways()) @@ -1978,12 +1987,12 @@ bool PatternMatchEngine::clause_accept(const PatternTermPtr& clause, _did_check_forall = true; match = _pmc.always_clause_match(clause_root, hg, var_grounding); _forall_state = _forall_state and match; - DO_LOG({logger().fine("for-all clause match callback match=%d", match);}) + logmsg("For-all clause match callback match=", match); } else { match = _pmc.clause_match(clause_root, hg, var_grounding); - DO_LOG({logger().fine("clause match callback match=%d", match);}) + logmsg("clause match callback match=", match); } if (not match) return false; @@ -2052,7 +2061,7 @@ bool PatternMatchEngine::do_next_clause(void) if (PatternTerm::UNDEFINED == next_clause) { bool found = report_grounding(var_grounding, clause_grounding); - DO_LOG(logger().fine("==================== FINITO! accepted=%d", found);) + logmsg("==================== FINITO! accepted=", found); DO_LOG(log_solution(var_grounding, clause_grounding);) clause_stacks_pop(); return found; @@ -2105,7 +2114,7 @@ bool PatternMatchEngine::do_next_clause(void) Handle curr_root = next_clause->getHandle(); static Handle undef(Handle::UNDEFINED); bool match = _pmc.optional_clause_match(curr_root, undef, var_grounding); - DO_LOG({logger().fine("Exhausted search for optional clause, cb=%d", match);}) + logmsg("Exhausted search for optional clause, cb=", match); if (not match) { clause_stacks_pop(); return false; @@ -2117,8 +2126,8 @@ bool PatternMatchEngine::do_next_clause(void) if (PatternTerm::UNDEFINED == next_clause) { - DO_LOG({logger().fine("==================== FINITO BANDITO!"); - log_solution(var_grounding, clause_grounding);}) + logmsg("==================== FINITO BANDITO!"); + DO_LOG({log_solution(var_grounding, clause_grounding);}) found = report_grounding(var_grounding, clause_grounding); } else @@ -2456,8 +2465,7 @@ bool PatternMatchEngine::get_next_thinnest_clause(bool search_eval, void PatternMatchEngine::clause_stacks_push(void) { _clause_stack_depth++; - DO_LOG({logger().fine("--- CLAUSE stack push to depth=%d", - _clause_stack_depth);}) + logmsg("--- CLAUSE stack push to depth=", _clause_stack_depth); var_solutn_stack.push(var_grounding); _clause_solutn_stack.push(clause_grounding); @@ -2501,7 +2509,7 @@ void PatternMatchEngine::clause_stacks_pop(void) perm_pop(); _clause_stack_depth --; - DO_LOG({logger().fine("CLAUSE stack pop to depth %d", _clause_stack_depth);}) + logmsg("CLAUSE stack pop to depth", _clause_stack_depth); } /** @@ -2692,7 +2700,7 @@ bool PatternMatchEngine::explore_clause_direct(const Handle& term, const PatternTermPtr& clause) { // If we are looking for a pattern to match, then ... look for it. - DO_LOG({logger().fine("Clause is matchable; start matching it");}) + logmsg("Clause is matchable; start matching it"); _did_check_forall = false; bool found = explore_term_branches(term, grnd, clause); @@ -2712,7 +2720,7 @@ bool PatternMatchEngine::explore_clause_evaluatable(const Handle& term, const Handle& grnd, const PatternTermPtr& clause) { - DO_LOG({logger().fine("Clause is evaluatable; start evaluating it");}) + logmsg("Clause is evaluatable; start evaluating it"); // Some people like to have a clause that is just one big // giant variable, matching almost anything. Keep these folks @@ -2726,7 +2734,7 @@ bool PatternMatchEngine::explore_clause_evaluatable(const Handle& term, OC_ASSERT(is_clause_grounded(clause), "Internal error!"); bool found = _pmc.evaluate_sentence(clause->getHandle(), var_grounding); - DO_LOG({logger().fine("Post evaluating clause, found = %d", found);}) + logmsg("Post evaluating clause, found = ", found); if (found) { return clause_accept(clause, grnd); From 164a1fd73ed9d407d0526aa8b6ff86fc12fcbd55 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sat, 13 Jun 2020 13:15:25 -0500 Subject: [PATCH 3/6] Add full-term printing --- opencog/atoms/pattern/PatternTerm.cc | 53 ++++++++++++++++++++++------ opencog/atoms/pattern/PatternTerm.h | 3 ++ 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/opencog/atoms/pattern/PatternTerm.cc b/opencog/atoms/pattern/PatternTerm.cc index 390bb91755..53d9c50029 100644 --- a/opencog/atoms/pattern/PatternTerm.cc +++ b/opencog/atoms/pattern/PatternTerm.cc @@ -313,17 +313,9 @@ std::string PatternTerm::to_short_string(const std::string& sep) const return str; } -std::string PatternTerm::to_string() const { return to_string(""); } - -std::string PatternTerm::to_string(const std::string& indent) const +std::string PatternTerm::flag_string() const { - // Term is null-terminated at the top. - // Top term never has a handle in it. - if (not _handle) return "\n"; - std::string str = _parent->to_string(indent + " "); - str += indent; - const Handle& h = isQuoted() ? getQuote() : getHandle(); - str += nameserver().getTypeName(h->get_type()) + " : "; + std::string str; if (isQuoted()) str += "Q: "; if (_has_any_bound_var) str += "HABV: "; if (_has_bound_var) str += "HBV: "; @@ -340,7 +332,46 @@ std::string PatternTerm::to_string(const std::string& indent) const if (_is_absent) str += "A: "; if (_is_choice) str += "C: "; if (_is_always) str += "AW: "; - str += _handle->id_to_string() + "\n"; + str += _handle->id_to_string(); + return str; +} + +std::string PatternTerm::to_string() const { return to_string(""); } + +std::string PatternTerm::to_string(const std::string& indent) const +{ + // Term is null-terminated at the top. + // Top term never has a handle in it. + if (not _handle) return "\n"; + std::string str = _parent->to_string(indent + " "); + str += indent; + str += nameserver().getTypeName(getQuote()->get_type()) + " : "; + str += flag_string() + "\n"; + return str; +} + +std::string PatternTerm::to_full_string() const { return to_full_string(""); } + +std::string PatternTerm::to_full_string(const std::string& indent) const +{ + if (getQuote()->is_node()) + { + std::string str = getQuote()->to_short_string(indent); + str += "\t; " + flag_string() + "\n"; + return str; + } + + std::string str = indent; + std::string more_indent = indent + " "; // two spaces + str += "(" + nameserver().getTypeName(getQuote()->get_type()); + str += "\t\t; " + flag_string() + "\n"; + for (const PatternTermPtr& ptm: getOutgoingSet()) + { + if (str.back() == ')') str += "\n"; + str += ptm->to_full_string(more_indent); + } + if (str.back() != ')') str += indent; + str += ")"; return str; } diff --git a/opencog/atoms/pattern/PatternTerm.h b/opencog/atoms/pattern/PatternTerm.h index 0f3b1eda9b..061518d1f4 100644 --- a/opencog/atoms/pattern/PatternTerm.h +++ b/opencog/atoms/pattern/PatternTerm.h @@ -234,6 +234,9 @@ class PatternTerm std::string to_string(const std::string& indent) const; std::string to_short_string() const; std::string to_short_string(const std::string& indent) const; + std::string to_full_string() const; + std::string to_full_string(const std::string& indent) const; + std::string flag_string() const; }; #define createPatternTerm std::make_shared From 6db1676b337d10be99dbd7524cd20e1f0cd65e10 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sat, 13 Jun 2020 13:15:52 -0500 Subject: [PATCH 4/6] Use full-term printing --- opencog/atoms/pattern/Pattern.cc | 2 - opencog/atoms/pattern/PatternLink.cc | 61 +++++++++------------------- opencog/query/InitiateSearchMixin.cc | 4 +- 3 files changed, 21 insertions(+), 46 deletions(-) diff --git a/opencog/atoms/pattern/Pattern.cc b/opencog/atoms/pattern/Pattern.cc index 8e50046f3b..d3b747df99 100644 --- a/opencog/atoms/pattern/Pattern.cc +++ b/opencog/atoms/pattern/Pattern.cc @@ -26,8 +26,6 @@ namespace opencog { std::string Pattern::to_string(const std::string& indent) const { std::stringstream ss; - bool first = true; - ss << indent << "Pattern: " << redex_name << std::endl; if (body) diff --git a/opencog/atoms/pattern/PatternLink.cc b/opencog/atoms/pattern/PatternLink.cc index da8d288433..c9cc57610d 100644 --- a/opencog/atoms/pattern/PatternLink.cc +++ b/opencog/atoms/pattern/PatternLink.cc @@ -1060,57 +1060,34 @@ void PatternLink::debug_log(void) const logger().fine("%lu components", _num_comps); logger().fine("%lu variables\n", _variables.varset.size()); - int cl = 0; + int num = 0; + std::string str; for (const PatternTermPtr& ptm : _pat.pmandatory) { - const Handle& h = - ptm->isQuoted() ? ptm->getQuote() : ptm->getHandle(); - std::stringstream ss; - ss << "Mandatory " << cl << ":"; - if (ptm->hasAnyEvaluatable()) ss << " (evaluatable)"; - ss << std::endl; - ss << h->to_short_string(); - logger().fine() << ss.str(); - cl++; + str += "Mandatory " + std::to_string(num) + ":"; + if (ptm->hasAnyEvaluatable()) str += " (evaluatable)"; + str += "\n"; + str += ptm->to_full_string(); + num++; } - if (0 < _pat.absents.size()) + for (const PatternTermPtr& ptm : _pat.absents) { - logger().fine("Pattern has must-be-absent clauses:"); - cl = 0; - for (const PatternTermPtr& ptm : _pat.absents) - { - const Handle& h = - ptm->isQuoted() ? ptm->getQuote() : ptm->getHandle(); - std::stringstream ss; - ss << "Optional clause " << cl << ":" << std::endl; - ss << h->to_short_string(); - logger().fine() << ss.str(); - cl++; - } + str += "Absent clause " + std::to_string(num) + ":\n"; + str + ptm->to_full_string(); + num++; } - else - logger().fine("No must-be-absent clauses"); - if (0 < _pat.always.size()) + for (const PatternTermPtr& ptm : _pat.always) { - logger().fine("Pattern has for-all clauses:"); - cl = 0; - for (const PatternTermPtr& ptm : _pat.always) - { - const Handle& h = - ptm->isQuoted() ? ptm->getQuote() : ptm->getHandle(); - std::stringstream ss; - ss << "Always clause " << cl << ":"; - if (ptm->hasAnyEvaluatable()) ss << " (evaluatable)"; - ss << std::endl; - ss << h->to_short_string(); - logger().fine() << ss.str(); - cl++; - } + str += "Always clause " + std::to_string(num) + ":"; + if (ptm->hasAnyEvaluatable()) str += " (evaluatable)"; + str += "\n"; + str += ptm->to_full_string(); + num++; } - else - logger().fine("No always clauses"); + + logger().fine() << str; // Print out the bound variables in the predicate. for (const Handle& h : _variables.varset) diff --git a/opencog/query/InitiateSearchMixin.cc b/opencog/query/InitiateSearchMixin.cc index 0ee47dfa54..46be18d81f 100644 --- a/opencog/query/InitiateSearchMixin.cc +++ b/opencog/query/InitiateSearchMixin.cc @@ -366,8 +366,8 @@ bool InitiateSearchMixin::choice_loop(PatternMatchCallback& pmc, DO_LOG({LAZY_LOG_FINE << "Choice loop start term is: " << (_starter_term == (Atom*) nullptr ? "UNDEFINED" : _starter_term->to_short_string());}) - DO_LOG({LAZY_LOG_FINE << "Choice loop root clause is: " - << _root->getQuote()->to_string();}) + DO_LOG({LAZY_LOG_FINE << "Choice loop root clause is:\n" + << _root->to_full_string();}) bool found = search_loop(pmc, dbg_banner); // Terminate search if satisfied. From bdca7b3b73eb4294860408b7ef600d70795fe559 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sat, 13 Jun 2020 13:30:20 -0500 Subject: [PATCH 5/6] debug-printing for PattternTermSeq --- opencog/atoms/pattern/PatternTerm.cc | 17 +++++++++++++++-- opencog/atoms/pattern/PatternTerm.h | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/opencog/atoms/pattern/PatternTerm.cc b/opencog/atoms/pattern/PatternTerm.cc index 53d9c50029..b10e86d387 100644 --- a/opencog/atoms/pattern/PatternTerm.cc +++ b/opencog/atoms/pattern/PatternTerm.cc @@ -380,9 +380,22 @@ std::string oc_to_string(const PatternTerm& pt, const std::string& indent) return pt.to_string(indent); } -std::string oc_to_string(const PatternTermPtr& pt_ptr, const std::string& indent) +std::string oc_to_string(const PatternTermPtr& ptr, const std::string& indent) { - return pt_ptr->to_string(); + return ptr->to_string(); +} + +std::string oc_to_string(const PatternTermSeq& pts, const std::string& indent) +{ + std::string str; + size_t i=0; + for (const PatternTermPtr& ptm : pts) + { + str += indent + "term[" + std::to_string(i) + "]:\n"; + str += ptm->to_full_string(indent + " ") + "\n"; + i++; + } + return str; } } // ~namespace opencog diff --git a/opencog/atoms/pattern/PatternTerm.h b/opencog/atoms/pattern/PatternTerm.h index 061518d1f4..68b879397f 100644 --- a/opencog/atoms/pattern/PatternTerm.h +++ b/opencog/atoms/pattern/PatternTerm.h @@ -247,6 +247,8 @@ std::string oc_to_string(const PatternTerm& pt, const std::string& indent=empty_string); std::string oc_to_string(const PatternTermPtr& pt, const std::string& indent=empty_string); +std::string oc_to_string(const PatternTermSeq& pt, + const std::string& indent=empty_string); } // namespace opencog From fd7eba4b74f292afcfdb23d3632dfb02e90b7a8b Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sat, 13 Jun 2020 13:53:38 -0500 Subject: [PATCH 6/6] Debug-printing cleanups --- opencog/atoms/pattern/PatternLink.cc | 15 ++++++++------- opencog/query/InitiateSearchMixin.cc | 25 ++++++++++++------------- opencog/query/PatternMatchEngine.cc | 18 +++++++++--------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/opencog/atoms/pattern/PatternLink.cc b/opencog/atoms/pattern/PatternLink.cc index c9cc57610d..8f57658957 100644 --- a/opencog/atoms/pattern/PatternLink.cc +++ b/opencog/atoms/pattern/PatternLink.cc @@ -1061,32 +1061,33 @@ void PatternLink::debug_log(void) const logger().fine("%lu variables\n", _variables.varset.size()); int num = 0; - std::string str; + std::string str = "\n"; for (const PatternTermPtr& ptm : _pat.pmandatory) { - str += "Mandatory " + std::to_string(num) + ":"; + str += "================ Mandatory clause " + std::to_string(num) + ":"; if (ptm->hasAnyEvaluatable()) str += " (evaluatable)"; str += "\n"; - str += ptm->to_full_string(); + str += ptm->to_full_string() + "\n\n"; num++; } for (const PatternTermPtr& ptm : _pat.absents) { - str += "Absent clause " + std::to_string(num) + ":\n"; - str + ptm->to_full_string(); + str += "================ Absent clause " + std::to_string(num) + ":\n"; + str += ptm->to_full_string() + "\n\n"; num++; } for (const PatternTermPtr& ptm : _pat.always) { - str += "Always clause " + std::to_string(num) + ":"; + str += "================ Always clause " + std::to_string(num) + ":"; if (ptm->hasAnyEvaluatable()) str += " (evaluatable)"; str += "\n"; - str += ptm->to_full_string(); + str += ptm->to_full_string() + "\n\n"; num++; } + str.pop_back(); logger().fine() << str; // Print out the bound variables in the predicate. diff --git a/opencog/query/InitiateSearchMixin.cc b/opencog/query/InitiateSearchMixin.cc index 46be18d81f..55064aa272 100644 --- a/opencog/query/InitiateSearchMixin.cc +++ b/opencog/query/InitiateSearchMixin.cc @@ -363,9 +363,9 @@ bool InitiateSearchMixin::choice_loop(PatternMatchCallback& pmc, _starter_term = ch.start_term; _search_set = ch.search_set; - DO_LOG({LAZY_LOG_FINE << "Choice loop start term is: " - << (_starter_term == (Atom*) nullptr ? - "UNDEFINED" : _starter_term->to_short_string());}) + DO_LOG({LAZY_LOG_FINE << "Choice loop start term is:\n" + << (_starter_term == (Atom*) nullptr ? "UNDEFINED" : + _starter_term->to_short_string(" "));}) DO_LOG({LAZY_LOG_FINE << "Choice loop root clause is:\n" << _root->to_full_string();}) @@ -751,12 +751,10 @@ bool InitiateSearchMixin::setup_link_type_search() if (PatternTerm::UNDEFINED == _root) return false; - DO_LOG({const Handle& s = - _root->isQuoted() ? _root->getQuote() : _root->getHandle(); - LAZY_LOG_FINE << "Start clause is: " << std::endl - << s->to_string();}) - DO_LOG({LAZY_LOG_FINE << "Start term is: " << std::endl - << _starter_term->to_string();}) + DO_LOG({LAZY_LOG_FINE << "Start clause is:\n" + << _root->to_full_string();}) + DO_LOG({LAZY_LOG_FINE << "Start term is:\n" + << _starter_term->to_short_string();}) // Get type of the rarest link Type ptype = _starter_term->get_type(); @@ -809,7 +807,7 @@ bool InitiateSearchMixin::setup_variable_search(void) bool empty = false; for (const Handle& var: _variables->varset) { - DO_LOG({LAZY_LOG_FINE << "Examine variable " << var->to_string();}) + DO_LOG({LAZY_LOG_FINE << "Examine variable " << var->to_short_string();}) const auto& tit = _variables->_simple_typemap.find(var); if (_variables->_simple_typemap.end() == tit) continue; @@ -822,7 +820,7 @@ bool InitiateSearchMixin::setup_variable_search(void) for (Type t : typeset) num += (size_t) _as->get_num_atoms_of_type(t); - DO_LOG({LAZY_LOG_FINE << var->to_string() << " has " + DO_LOG({LAZY_LOG_FINE << var->to_short_string() << " has " << num << " atoms in the atomspace";}) if (0 == num) empty = true; @@ -1060,8 +1058,9 @@ bool InitiateSearchMixin::search_loop(PatternMatchCallback& pmc, Handle h(_search_set[j]); DO_LOG({LAZY_LOG_FINE << dbg_banner - << "\nLoop candidate (" << ++i << "/" << hsz << "):\n" - << h->to_string();}) + << "\n Loop candidate (" + << ++i << "/" << hsz << "):\n" + << h->to_short_string(" ");}) if (pme.explore_neighborhood(_starter_term, h, _root)) nfnd++; } _recursing = false; diff --git a/opencog/query/PatternMatchEngine.cc b/opencog/query/PatternMatchEngine.cc index e510f9df96..f10d008c69 100644 --- a/opencog/query/PatternMatchEngine.cc +++ b/opencog/query/PatternMatchEngine.cc @@ -243,7 +243,7 @@ bool PatternMatchEngine::ordered_compare(const PatternTermPtr& ptm, } depth --; - logmsg("ordered_compare match?=", match); + logmsg("ordered_compare match?:", match); if (not match) { @@ -1192,7 +1192,7 @@ bool PatternMatchEngine::tree_compare(const PatternTermPtr& ptm, bool match = _pmc.link_match(ptm, hg); if (not match) return false; - logmsg("tree depth=", depth); + logmsg("tree depth:", depth); logmsg("tree_compare:", hp); logmsg("to:", hg); @@ -1821,15 +1821,15 @@ bool PatternMatchEngine::explore_single_branch(const PatternTermPtr& ptm, { solution_push(); - logmsg("ssss Checking term=", ptm); - logmsg("ssss For soln by", hg); + logmsg("ssss Checking term:", ptm); + logmsg("ssss For soln by:", hg); bool match = tree_compare(ptm, hg, CALL_SOLN); if (not match) { - logmsg("ssss NO solution for term=", ptm); - logmsg("ssss NOT solved by by", hg); + logmsg("ssss NO solution for term:", ptm); + logmsg("ssss NOT solved by:", hg); solution_pop(); return false; } @@ -3027,11 +3027,11 @@ void PatternMatchEngine::log_solution( if (not m->second) { Handle mf(m->first); - logmsg("Ungrounded clause", mf); + logmsg("Ungrounded (absent) clause", mf); continue; } - std::string str = m->second->to_short_string(); - logger().fine("%d. %s", i, str.c_str()); + std::string str = m->second->to_short_string(" "); + logger().fine("Clause %d:\n%s", i, str.c_str()); } }