From 7cdf8a310de9d70d8cdc32d383f3c5c95f5e4d97 Mon Sep 17 00:00:00 2001 From: kenkeiras Date: Wed, 24 May 2017 22:10:17 +0200 Subject: [PATCH] Unroll get_matching last list-comprehension. --- naive-nlu/tree_nlu/parsing.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/naive-nlu/tree_nlu/parsing.py b/naive-nlu/tree_nlu/parsing.py index ed5903a..a179dd4 100644 --- a/naive-nlu/tree_nlu/parsing.py +++ b/naive-nlu/tree_nlu/parsing.py @@ -278,14 +278,23 @@ def get_matching(sample, other): x[0][i][0] == sample[0][i][0], other)) - return [sample[0][x] if isinstance(sample[0][x], str) - else - sample[0][x] if isinstance(sample[0][x], tuple) - else {'groups': sample[0][x]['groups'] & reduce(lambda a, b: a & b, - map(lambda y: y[0][x]['groups'], - other))} - for x - in range(l)] + matching = [] + for x in range(l): # Generate the combination of this and other(s) matcher + first_sample_data = sample[0][x] + if isinstance(first_sample_data, str): + matching.append(first_sample_data) + elif isinstance(first_sample_data, tuple): + matching.append(first_sample_data) + else: + this_groups = sample[0][x]['groups'] + if len(other) > 0: + other_groups = reduce(lambda a, b: a & b, + map(lambda y: y[0][x]['groups'], + other)) + this_groups = this_groups & other_groups + + matching.append({'groups': this_groups}) + return matching def reprocess_language_knowledge(knowledge_base, examples):