Extract more contextual info from the words.
A property dictionary is now only to be considered equal to a word when it shares at least one group, or neither has groups.
This commit is contained in:
parent
d3b604efca
commit
0fbb9238eb
@ -22,7 +22,6 @@ class KnowledgeBase(object):
|
||||
knowledge_before = copy.deepcopy(self.knowledge)
|
||||
|
||||
# Parse everything
|
||||
parsed_examples = []
|
||||
for example in examples:
|
||||
# If there's parsed data, leverage it ASAP
|
||||
if 'parsed' in example:
|
||||
|
@ -273,3 +273,21 @@ def integrate_information(knowledge_base, example):
|
||||
return tagged_with_ast(
|
||||
ast, elements,
|
||||
knowledge_ingestion[method](knowledge_base, elements, *args))
|
||||
|
||||
def can_be_used_in_place(knowledge, token, minisegment):
|
||||
if token not in knowledge.knowledge:
|
||||
return False
|
||||
|
||||
info = knowledge.knowledge[token]
|
||||
info_groups = info.get('groups', set())
|
||||
minisegment_groups = minisegment.get('groups', set())
|
||||
|
||||
# Common group
|
||||
if len(info_groups & minisegment_groups) > 0:
|
||||
return True
|
||||
|
||||
# Neither has a group
|
||||
elif len(info_groups) == 0 == len(minisegment_groups):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
@ -395,8 +395,7 @@ def is_definite_minisegment(minisegment):
|
||||
|
||||
def match_token(knowledge, next_token, minisegment):
|
||||
if isinstance(minisegment, dict):
|
||||
# TODO: check if the dictionary matches the values
|
||||
return True
|
||||
return knowledge_evaluation.can_be_used_in_place(knowledge, next_token, minisegment)
|
||||
elif isinstance(minisegment, str):
|
||||
# TODO: check if the two elements can be used in each other place
|
||||
return next_token == minisegment
|
||||
|
@ -98,6 +98,12 @@ base_knowledge = {
|
||||
'fly': {
|
||||
"groups": {'verb'},
|
||||
},
|
||||
'bus': {
|
||||
"groups": {'noun'},
|
||||
},
|
||||
'run': {
|
||||
"groups": {'verb'},
|
||||
},
|
||||
'swim': {
|
||||
"groups": {'verb'},
|
||||
},
|
||||
|
@ -1,3 +1,4 @@
|
||||
import logging
|
||||
from ..knowledge_base import KnowledgeBase
|
||||
from ..utils.visuals import show_progbar
|
||||
|
||||
@ -109,7 +110,7 @@ examples = [
|
||||
# },
|
||||
('text_example',
|
||||
{
|
||||
"question": "Is milk white?",
|
||||
"question": "is milk white?",
|
||||
"affirmation": "milk is white",
|
||||
"answer": True,
|
||||
}),
|
||||
@ -662,9 +663,15 @@ base_knowledge = {
|
||||
'planet': {
|
||||
"groups": {'noun', 'group'},
|
||||
},
|
||||
'white': {
|
||||
"groups": {'noun', 'color', 'concept', 'property'},
|
||||
},
|
||||
'green': {
|
||||
"groups": {'noun', 'color', 'concept'},
|
||||
},
|
||||
'milk': {
|
||||
"groups": {'noun'},
|
||||
},
|
||||
'fly': {
|
||||
"groups": {'verb'},
|
||||
},
|
||||
@ -713,11 +720,12 @@ def main():
|
||||
elif example_type == 'text_example':
|
||||
show_progbar(i, total, data['affirmation'])
|
||||
affirmation = data['affirmation']
|
||||
logging.debug("Processing affirmation: {}".format(affirmation))
|
||||
_, _, _ = knowledge.process(affirmation)
|
||||
|
||||
show_progbar(i, total, data['question'])
|
||||
question = data['question']
|
||||
|
||||
_, _, _ = knowledge.process(affirmation)
|
||||
logging.debug("Processing question : {}".format(question))
|
||||
result, _, _ = knowledge.process(question)
|
||||
|
||||
if result != data['answer']:
|
||||
|
Loading…
Reference in New Issue
Block a user