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):
|
def process(self, row):
|
||||||
knowledge_before = copy.deepcopy(self.knowledge)
|
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,
|
result = knowledge_evaluation.integrate_information(self.knowledge,
|
||||||
{
|
{
|
||||||
"elements": row,
|
"elements": tokens,
|
||||||
"decomposition": decomposition,
|
"decomposition": decomposition,
|
||||||
"parsed": inferred_tree,
|
"parsed": inferred_tree,
|
||||||
})
|
})
|
||||||
|
@ -67,6 +67,7 @@ def reprocess_language_knowledge(knowledge_base, examples):
|
|||||||
|
|
||||||
|
|
||||||
def get_fit(knowledge, row):
|
def get_fit(knowledge, row):
|
||||||
|
row = row.lower().split()
|
||||||
for sample, ast in knowledge.trained:
|
for sample, ast in knowledge.trained:
|
||||||
if len(sample) != len(row):
|
if len(sample) != len(row):
|
||||||
continue
|
continue
|
||||||
@ -74,6 +75,6 @@ def get_fit(knowledge, row):
|
|||||||
if all(map(lambda x: (not isinstance(sample[x], str)
|
if all(map(lambda x: (not isinstance(sample[x], str)
|
||||||
or sample[x] == row[x]),
|
or sample[x] == row[x]),
|
||||||
range(len(sample)))):
|
range(len(sample)))):
|
||||||
return sample, ast
|
return row, sample, ast
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
@ -96,7 +96,7 @@ def main():
|
|||||||
print("----")
|
print("----")
|
||||||
|
|
||||||
for test in [{'text': 'a bus can run'}, {'text': 'io is a moon'}]:
|
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)
|
result, differences = knowledge.process(row)
|
||||||
|
|
||||||
print("result:", result)
|
print("result:", result)
|
||||||
|
Loading…
Reference in New Issue
Block a user