diff --git a/naive-nlu/tree_nlu/test.py b/naive-nlu/tree_nlu/test.py index ec57f8b..810e3c8 100644 --- a/naive-nlu/tree_nlu/test.py +++ b/naive-nlu/tree_nlu/test.py @@ -17,13 +17,13 @@ def main(): test_module.main() print(" \x1b[1;32m✓\x1b[0m {}".format(test_name)) except AssertionError as ae: - print(" \x1b[1;31m✗\x1b[0m {}".format(test_name, - (' : [Assertion] {}'.format(ae.args[0])) if len(ae.args) > 0 + print(" \x1b[1;31m✗\x1b[0m {}{}".format(test_name, + ('\n [Assertion] {}'.format(ae.args[0])) if len(ae.args) > 0 else '')) failed = True except Exception as e: - print(" \x1b[1;7;31m!\x1b[0m {} : [Exception] {}".format(test_name, e)) + print(" \x1b[1;7;31m!\x1b[0m {}\n [Exception] {}".format(test_name, e)) failed = True traceback.print_exc() diff --git a/naive-nlu/tree_nlu/tests/gac_100.py b/naive-nlu/tree_nlu/tests/gac_100.py index 5716568..b2c31e0 100644 --- a/naive-nlu/tree_nlu/tests/gac_100.py +++ b/naive-nlu/tree_nlu/tests/gac_100.py @@ -1,4 +1,5 @@ from ..knowledge_base import KnowledgeBase +from ..utils.visuals import show_progbar def _assert(args): assert(args) @@ -670,14 +671,20 @@ def main(): knowledge=base_knowledge, ) - for example_type, data in examples: + total = len(examples) + + for i, (example_type, data) in enumerate(examples): if example_type == 'full_example': affirmation = { 'text': data['affirmation'], 'parsed': data['parsed'][1], } question = data + + show_progbar(i, total, data['affirmation']) differences = knowledge.train([affirmation]) + + show_progbar(i, total, data['text']) differences = knowledge.train([question]) result, _, _ = knowledge.process(data['text']) @@ -690,7 +697,10 @@ def main(): f(knowledge) elif example_type == 'text_example': + show_progbar(i, total, data['affirmation']) affirmation = data['affirmation'] + + show_progbar(i, total, data['question']) question = data['question'] _, _, _ = knowledge.process(affirmation) @@ -701,3 +711,5 @@ def main(): else: raise NotImplementedError('Example type: {}'.format(example_type)) + + print("\r\x1b[K", end='') diff --git a/naive-nlu/tree_nlu/utils/visuals.py b/naive-nlu/tree_nlu/utils/visuals.py new file mode 100644 index 0000000..a6dd611 --- /dev/null +++ b/naive-nlu/tree_nlu/utils/visuals.py @@ -0,0 +1,15 @@ +def show_progbar(done, total, msg=''): + total_blocks = 10 + blocks_done = (done * total_blocks) // total + blocks_to_go = total_blocks - blocks_done + + print('\r\x1b[K' # Go to the start of the line + '\x1b[0m' # Restart the "style" + '|' # Put the first "|" + + blocks_done * '█' # Completed blocks + + blocks_to_go * ' ' # Uncompleted blocks + + '\x1b[7m|\x1b[0m' # End the bar + + ' ' + + msg # Add message + + '\r' # Go back to the start + , end='')