Move pieces of parsing code in parsing module.
This commit is contained in:
parent
3cc1f9bcde
commit
ad975015a6
@ -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,
|
||||
})
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user