From 3dc69158b95aa82aee169e2b2fa2ca6fb9f13b44 Mon Sep 17 00:00:00 2001 From: Ozbolt Menegatti Date: Wed, 6 Feb 2019 15:26:09 +0100 Subject: [PATCH] NW: switching print for logging --- wani.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/wani.py b/wani.py index c201a86..2c5d71f 100644 --- a/wani.py +++ b/wani.py @@ -380,7 +380,7 @@ class Component: f = ComponentRepresentation.new(dict(feature.attrib)) if type(f) is None: - print("Unknown representation in component {}, skipping...".format(self.idx), file=sys.stderr) + logging.warning("Unknown representation in component {}, skipping...".format(self.idx), file=sys.stderr) continue if type(f) is StructureSelection: assert(cr is None) @@ -593,8 +593,8 @@ class SyntacticStructure: elif el.get('basic') == "agreement": self.add_agreement(n, el) else: - print("Strange representation (basic={}) in structure {}. Skipping" - .format(el.get('basic'), self.id), file=sys.stderr) + logging.warning("Strange representation (basic={}) in structure {}. Skipping" + .format(el.get('basic'), self.id)) continue def add_agreement(self, n, el): @@ -789,7 +789,7 @@ def main(): structures = build_structures(STRUKTURE) for s in structures: - print(s) + logging.debug(str(s)) words = load_corpus(STAVKI) # import pickle @@ -798,11 +798,11 @@ def main(): # with open("words.p", "rb") as fp: # words = pickle.load(fp) - print("MATCHES...") + logging.info("MATCHES...") matches = {s.id: [] for s in structures} for idx, s in enumerate(structures): - print("\r{}/{}: {:7s}".format(idx, len(structures), s.id)) #, end="") + logging.info("{}/{}: {:7s}".format(idx, len(structures), s.id)) for w in words: mhere = s.match(w) logging.debug(" GOT: {}".format(len(mhere))) @@ -852,6 +852,9 @@ def main(): to_print.extend([""] * (length - len(to_print))) to_print.extend([str(cid), ""]) + logging.info("TIME: {}".format(time.time() - t)) + logging.debug([(k, len(v)) for k, v in matches.items()]) + logging.debug(sum(len(v) for _, v in matches.items())) csv.append(", ".join(to_print)) @@ -870,10 +873,6 @@ def main(): # print(groups) - print("") - print("TIME", time.time() - t) - print([(k, len(v)) for k, v in matches.items()]) - print(sum(len(v) for _, v in matches.items())) if __name__ == '__main__': logging.basicConfig(level=logging.INFO)