Move pieces of parsing code in parsing module.

This commit is contained in:
kenkeiras 2017-05-11 20:56:01 +02:00
parent 3cc1f9bcde
commit ad975015a6
3 changed files with 5 additions and 4 deletions

View File

@ -47,10 +47,10 @@ class KnowledgeBase(object):
def process(self, row):
knowledge_before = copy.deepcopy(self.knowledge)
decomposition, inferred_tree = parsing.get_fit(self, row)
tokens, decomposition, inferred_tree = parsing.get_fit(self, row)
result = knowledge_evaluation.integrate_information(self.knowledge,
{
"elements": row,
"elements": tokens,
"decomposition": decomposition,
"parsed": inferred_tree,
})

View File

@ -67,6 +67,7 @@ def reprocess_language_knowledge(knowledge_base, examples):
def get_fit(knowledge, row):
row = row.lower().split()
for sample, ast in knowledge.trained:
if len(sample) != len(row):
continue
@ -74,6 +75,6 @@ def get_fit(knowledge, row):
if all(map(lambda x: (not isinstance(sample[x], str)
or sample[x] == row[x]),
range(len(sample)))):
return sample, ast
return row, sample, ast
else:
return None

View File

@ -96,7 +96,7 @@ def main():
print("----")
for test in [{'text': 'a bus can run'}, {'text': 'io is a moon'}]:
row = test['text'].lower().split()
row = test['text']
result, differences = knowledge.process(row)
print("result:", result)