From f338fb786d995f4a107a3b3bc577b09f1f363993 Mon Sep 17 00:00:00 2001 From: kenkeiras Date: Mon, 22 May 2017 22:06:49 +0200 Subject: [PATCH] Set base logging level as info, remove unused debug strings. --- naive-nlu/knowledge_base.py | 12 ++++++------ naive-nlu/knowledge_evaluation.py | 2 -- naive-nlu/parsing.py | 29 +---------------------------- naive-nlu/test.py | 2 ++ 4 files changed, 9 insertions(+), 36 deletions(-) diff --git a/naive-nlu/knowledge_base.py b/naive-nlu/knowledge_base.py index 7750315..31fe4d2 100644 --- a/naive-nlu/knowledge_base.py +++ b/naive-nlu/knowledge_base.py @@ -23,18 +23,18 @@ class KnowledgeBase(object): # Parse everything parsed_examples = [] for example in examples: - logging.debug("\x1b[7;32m> {} \x1b[0m".format(example)) + logging.info("\x1b[7;32m> {} \x1b[0m".format(example)) tokens, decomposition, inferred_tree = parsing.integrate_language(self, example) - logging.debug(tokens) + logging.info(tokens) result = knowledge_evaluation.integrate_information(self.knowledge, { "elements": tokens, "decomposition": decomposition, "parsed": inferred_tree, }) - logging.debug("\x1b[7;33m< {} \x1b[0m".format(self.get_value(result))) + logging.info("\x1b[7;33m< {} \x1b[0m".format(self.get_value(result))) self.act_upon(result) - logging.debug("\x1b[7;34m> set: {} \x1b[0m".format(self.get_value(result))) + logging.info("\x1b[7;34m> set: {} \x1b[0m".format(self.get_value(result))) self.examples.append((decomposition, inferred_tree)) # Reduce values @@ -49,7 +49,7 @@ class KnowledgeBase(object): def process(self, row): knowledge_before = copy.deepcopy(self.knowledge) - logging.debug("\x1b[7;32m> {} \x1b[0m".format(row)) + logging.info("\x1b[7;32m> {} \x1b[0m".format(row)) tokens = parsing.to_tokens(row) tokens, inferred_tree = parsing.get_fit(self, tokens) result = knowledge_evaluation.integrate_information(self.knowledge, @@ -75,4 +75,4 @@ class KnowledgeBase(object): if is_modifiable_property(result): result.setter() else: - logging.debug(result) + logging.warning("Cannot act upon: {}".format(result)) diff --git a/naive-nlu/knowledge_evaluation.py b/naive-nlu/knowledge_evaluation.py index 9f5d021..4485adb 100644 --- a/naive-nlu/knowledge_evaluation.py +++ b/naive-nlu/knowledge_evaluation.py @@ -41,8 +41,6 @@ def get_subquery_type(knowledge_base, atom): def property_for_value(knowledge_base, value): - # logging.debug(value) - # logging.debug(knowledge_base[value]) return knowledge_base[value]['as_property'] diff --git a/naive-nlu/parsing.py b/naive-nlu/parsing.py index 2133e9e..d83ac87 100644 --- a/naive-nlu/parsing.py +++ b/naive-nlu/parsing.py @@ -133,26 +133,11 @@ def apply_remix(tokens, remix): def build_remix_matrix(knowledge_base, tokens, atom, similar): - # logging.debug("+" * 20) - tokens = list(tokens) tokens, matcher, result = make_template(knowledge_base, tokens, atom) similar_matcher, similar_result, similar_result_resolved, _ = similar - # logging.debug("NEW:") - # logging.debug("Tokens:", tokens) - # logging.debug("Matcher:", matcher) - # logging.debug("Result:", result) - # logging.debug("---") - # logging.debug("Similar:") - # logging.debug("Matcher:", similar_matcher) - # logging.debug("Result:", similar_result) - start_bounds, end_bounds = find_bounds(matcher, similar_matcher) - # logging.debug("---") - # logging.debug("Bounds:") - # logging.debug("Start:", start_bounds) - # logging.debug("End: ", end_bounds) for i, element in (end_bounds + start_bounds[::-1]): matcher.pop(i) @@ -161,15 +146,10 @@ def build_remix_matrix(knowledge_base, tokens, atom, similar): possible_remixes = get_possible_remixes(knowledge_base, matcher, similar_matcher) chosen_remix = possible_remixes[0] - # logging.debug("New tokens:", tokens) - # logging.debug("-" * 20) return chosen_remix, (start_bounds, end_bounds) def get_possible_remixes(knowledge_base, matcher, similar_matcher): - # logging.debug("*" * 20) - # logging.debug(matcher) - # logging.debug(similar_matcher) matrix = [] for element in matcher: @@ -183,8 +163,6 @@ def get_possible_remixes(knowledge_base, matcher, similar_matcher): indexes = all_indexes(similar_matcher, element) matrix.append(indexes) - # logging.debug(matrix) - # logging.debug([list(x) for x in list(zip(*matrix))]) # TODO: do some scoring to find the most "interesting combination" return [list(x) for x in list(zip(*matrix))] @@ -304,19 +282,14 @@ def get_matching(sample, other): def reprocess_language_knowledge(knowledge_base, examples): examples = knowledge_base.examples + examples - logging.debug('\n'.join(map(str, knowledge_base.examples))) - logging.debug("--") - pattern_examples = [] for i, sample in enumerate(examples): other = examples[:i] + examples[i + 1:] match = get_matching(sample, other) - logging.debug("->", match) if len(match) > 0: sample = (match, sample[1],) pattern_examples.append(sample) - logging.debug("---") - logging.debug("\x1b[7m--\x1b[0m") + return pattern_examples diff --git a/naive-nlu/test.py b/naive-nlu/test.py index d6692d9..347f6e7 100644 --- a/naive-nlu/test.py +++ b/naive-nlu/test.py @@ -1,6 +1,8 @@ import json import logging +logging.getLogger().setLevel(logging.INFO) + from knowledge_base import KnowledgeBase from modifiable_property import is_modifiable_property