Add learning phase to shallow (1 level) nested structures.

This commit is contained in:
kenkeiras 2017-05-15 16:51:39 +02:00
parent 099af2a815
commit 5f6b067e17
4 changed files with 111 additions and 27 deletions

View file

@ -22,6 +22,7 @@ class KnowledgeBase(object):
# Parse everything
parsed_examples = []
for example in examples:
print("\x1b[7;32m> {} \x1b[0m".format(example))
tokens, decomposition, inferred_tree = parsing.integrate_language(self, example)
print(tokens)
result = knowledge_evaluation.integrate_information(self.knowledge, {
@ -29,7 +30,10 @@ class KnowledgeBase(object):
"decomposition": decomposition,
"parsed": inferred_tree,
})
print("\x1b[7;33m< {} \x1b[0m".format(self.get_value(result)))
self.act_upon(result)
print("\x1b[7;34m< {} \x1b[0m".format(self.get_value(result)))
self.examples.append((decomposition, inferred_tree))
# Reduce values
@ -59,6 +63,12 @@ class KnowledgeBase(object):
return result, inferred_tree, knowledge_diff_getter
def get_value(self, result):
if isinstance(result, ModifiableProperty):
return result.getter()
else:
return result
def act_upon(self, result):
if isinstance(result, ModifiableProperty):
result.setter()