Allow learning from unparsed data in tests.
This commit is contained in:
parent
586ac76d1f
commit
e6e8146478
@ -41,10 +41,21 @@ def get_subquery_type(knowledge_base, atom):
|
||||
|
||||
|
||||
def property_for_value(knowledge_base, value):
|
||||
if value in knowledge_base:
|
||||
# Annotate the property as property
|
||||
groups = knowledge_base[value].get('groups', set(['property']))
|
||||
groups.add('property')
|
||||
knowledge_base[value]['groups'] = groups
|
||||
|
||||
# And find the property "name"
|
||||
if 'as_property' in knowledge_base[value]:
|
||||
return knowledge_base[value]['as_property']
|
||||
|
||||
return knowledge_base[value].get('groups', set(['noun']))
|
||||
return knowledge_base[value].get('groups', set(['property']))
|
||||
else:
|
||||
# Consider that any property is... a property
|
||||
knowledge_base[value] = {'groups': {'property'}}
|
||||
return {'property'}
|
||||
|
||||
|
||||
def modifiable_property_from_property(prop, path, value):
|
||||
|
@ -1,30 +1,38 @@
|
||||
from ..knowledge_base import KnowledgeBase
|
||||
|
||||
examples = [
|
||||
('full_example',
|
||||
{
|
||||
"text": "is icecream cold?",
|
||||
"affirmation": "icecream is cold",
|
||||
"parsed": ("question", ("exists-property-with-value", 'icecream', 'cold')),
|
||||
"parsed": ("question",
|
||||
("exists-property-with-value", 'icecream', 'cold')),
|
||||
"answer": True,
|
||||
},
|
||||
# {
|
||||
# "text": "is earth a planet?",
|
||||
# "affirmation": "is earth a planet?",
|
||||
# "parsed": (),
|
||||
# "answer": None,
|
||||
# },
|
||||
# {
|
||||
# "text": "Is green a color?",
|
||||
# "affirmation": "Is green a color?",
|
||||
# "parsed": (),
|
||||
# "answer": None,
|
||||
# },
|
||||
# {
|
||||
# "text": "do airplanes fly?",
|
||||
# "affirmation": "do airplanes fly?",
|
||||
# "parsed": (),
|
||||
# "answer": None,
|
||||
# },
|
||||
}),
|
||||
('full_example',
|
||||
{
|
||||
"text": "is earth a planet?",
|
||||
"affirmation": "earth is a planet",
|
||||
"parsed": ("question",
|
||||
("pertenence-to-group", 'earth', 'planet')),
|
||||
"answer": True,
|
||||
}),
|
||||
('full_example',
|
||||
{
|
||||
"text": "Is green a color?",
|
||||
"affirmation": "green is a color",
|
||||
"parsed": ("question",
|
||||
("pertenence-to-group", 'green', 'color')),
|
||||
"answer": True,
|
||||
}),
|
||||
('full_example',
|
||||
{
|
||||
"text": "do airplanes fly?",
|
||||
"affirmation": "airplanes fly",
|
||||
"parsed": ("question",
|
||||
("has-capacity", 'plane', 'fly')),
|
||||
"answer": True,
|
||||
}),
|
||||
# {
|
||||
# "text": "Is it hot during the summer?",
|
||||
# "affirmation": "Is it hot during the summer?",
|
||||
@ -61,12 +69,12 @@ examples = [
|
||||
# "parsed": (),
|
||||
# "answer": None,
|
||||
# },
|
||||
# {
|
||||
# "text": "Is milk white?",
|
||||
# "affirmation": "Is milk white?",
|
||||
# "parsed": (),
|
||||
# "answer": None,
|
||||
# },
|
||||
('text_example',
|
||||
{
|
||||
"question": "Is milk white?",
|
||||
"affirmation": "milk is white",
|
||||
"answer": True,
|
||||
}),
|
||||
# {
|
||||
# "text": "do people have emotions?",
|
||||
# "affirmation": "do people have emotions?",
|
||||
@ -607,10 +615,24 @@ base_knowledge = {
|
||||
'icecream': {
|
||||
"groups": set(['noun', 'object', 'comestible', 'sweet']),
|
||||
},
|
||||
"cold": {
|
||||
'cold': {
|
||||
"groups": set(['property', 'temperature']),
|
||||
"as_property": "temperature",
|
||||
}
|
||||
},
|
||||
'earth': {
|
||||
"groups": set(['noun', 'object', 'planet']),
|
||||
},
|
||||
'planet': {
|
||||
"groups": set(['noun', 'group']),
|
||||
},
|
||||
'color': {
|
||||
"groups": set(['property', 'group']),
|
||||
},
|
||||
'green': {
|
||||
"groups": set(['noun', 'color', 'concept']),
|
||||
},
|
||||
'fly': {
|
||||
"groups": set(['verb']),
|
||||
},
|
||||
}
|
||||
|
||||
def main():
|
||||
@ -618,20 +640,30 @@ def main():
|
||||
knowledge=base_knowledge,
|
||||
)
|
||||
|
||||
affirmations = [
|
||||
{
|
||||
'text': x['affirmation'],
|
||||
'parsed': x['parsed'][1],
|
||||
for example_type, data in examples:
|
||||
if example_type == 'full_example':
|
||||
affirmation = {
|
||||
'text': data['affirmation'],
|
||||
'parsed': data['parsed'][1],
|
||||
}
|
||||
for x in examples
|
||||
]
|
||||
questions = examples
|
||||
question = data
|
||||
differences = knowledge.train([affirmation])
|
||||
differences = knowledge.train([question])
|
||||
|
||||
differences = knowledge.train(affirmations)
|
||||
differences = knowledge.train(questions)
|
||||
result, _, _ = knowledge.process(data['text'])
|
||||
|
||||
for example in examples:
|
||||
result, _, _ = knowledge.process(example['text'])
|
||||
if result != data['answer']:
|
||||
raise AssertionError('{} is not {}'.format(result, data['answer']))
|
||||
|
||||
if result != example['answer']:
|
||||
raise AssertionError('{} is not {}'.format(result, example['answer']))
|
||||
elif example_type == 'text_example':
|
||||
affirmation = data['affirmation']
|
||||
question = data['question']
|
||||
|
||||
_, _, _ = knowledge.process(affirmation)
|
||||
result, _, _ = knowledge.process(question)
|
||||
|
||||
if result != data['answer']:
|
||||
raise AssertionError('{} is not {}'.format(result, data['answer']))
|
||||
|
||||
else:
|
||||
raise NotImplementedError('Example type: {}'.format(example_type))
|
||||
|
Loading…
Reference in New Issue
Block a user