From 460ad73bbafc636f726584d5ce83392fb5c6a726 Mon Sep 17 00:00:00 2001 From: kenkeiras Date: Tue, 23 May 2017 23:17:44 +0200 Subject: [PATCH] Handle the possibility of remixes not working. --- naive-nlu/tree_nlu/parsing.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/naive-nlu/tree_nlu/parsing.py b/naive-nlu/tree_nlu/parsing.py index fa16a33..080aaa0 100644 --- a/naive-nlu/tree_nlu/parsing.py +++ b/naive-nlu/tree_nlu/parsing.py @@ -295,6 +295,8 @@ def reprocess_language_knowledge(knowledge_base, examples): def reverse_remix(tree_section, remix): result_section = [] for origin in remix: + if origin >= len(tree_section): + return None result_section.append(copy.deepcopy(tree_section[origin])) return result_section + tree_section[len(remix):] @@ -332,6 +334,9 @@ def resolve_fit(knowledge, fit, remaining_recursions): else: ((result_type, remixer), tokens) = element remixed_tokens = reverse_remix(tokens, remixer) + if remixed_tokens is None: + return None + minifit = get_fit(knowledge, remixed_tokens, remaining_recursions - 1) if minifit is None: return None