From b2b6be6c9ae376f5dd6f652e506e5378ef5cddce Mon Sep 17 00:00:00 2001 From: kenkeiras Date: Wed, 17 May 2017 01:05:55 +0200 Subject: [PATCH] Fix subquery learning/interpretation. --- naive-nlu/parsing.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/naive-nlu/parsing.py b/naive-nlu/parsing.py index d1a6fa8..6c5ab44 100644 --- a/naive-nlu/parsing.py +++ b/naive-nlu/parsing.py @@ -6,6 +6,7 @@ import re import copy from functools import reduce from typing import List +from modifiable_property import ModifiableProperty MAX_RECURSIONS = 5 @@ -110,11 +111,11 @@ def integrate_language(knowledge_base, example): new_tokens.insert(offset, (subquery_type, remix)) tokens = new_tokens - resolved_parsed = replace_position(resolved_parsed, position, subquery_type) + resolved_parsed = replace_position(resolved_parsed, position, offset) print("#########") - tokens, matcher, result = make_template(knowledge_base, tokens, parsed) + tokens, matcher, result = make_template(knowledge_base, tokens, resolved_parsed) print("T:", tokens) print("M:", matcher) print("R:", result) @@ -357,7 +358,11 @@ def fitting_return_type(knowledge, remaining_output + tail_of_ouput_stream, "\x1b[0m") print() - yield (parsed_input, + resolved_input = knowledge_evaluation.resolve(knowledge.knowledge, + parsed_input, ast) + if isinstance(resolved_input, ModifiableProperty): + resolved_input = resolved_input.getter() + yield ([resolved_input], (remaining_input, remaining_output + tail_of_ouput_stream)) except TypeError as e: print(indent + "X " + str(e)) @@ -368,6 +373,9 @@ def fitting_return_type(knowledge, except IndexError as e: print(indent + "X " + str(e)) pass + except KeyError as e: + print(indent + "X " + str(e)) + pass raise TypeError("No matching type found")