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):
|
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]:
|
if 'as_property' in knowledge_base[value]:
|
||||||
return knowledge_base[value]['as_property']
|
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):
|
def modifiable_property_from_property(prop, path, value):
|
||||||
|
@ -1,30 +1,38 @@
|
|||||||
from ..knowledge_base import KnowledgeBase
|
from ..knowledge_base import KnowledgeBase
|
||||||
|
|
||||||
examples = [
|
examples = [
|
||||||
|
('full_example',
|
||||||
{
|
{
|
||||||
"text": "is icecream cold?",
|
"text": "is icecream cold?",
|
||||||
"affirmation": "icecream is cold",
|
"affirmation": "icecream is cold",
|
||||||
"parsed": ("question", ("exists-property-with-value", 'icecream', 'cold')),
|
"parsed": ("question",
|
||||||
|
("exists-property-with-value", 'icecream', 'cold')),
|
||||||
"answer": True,
|
"answer": True,
|
||||||
},
|
}),
|
||||||
# {
|
('full_example',
|
||||||
# "text": "is earth a planet?",
|
{
|
||||||
# "affirmation": "is earth a planet?",
|
"text": "is earth a planet?",
|
||||||
# "parsed": (),
|
"affirmation": "earth is a planet",
|
||||||
# "answer": None,
|
"parsed": ("question",
|
||||||
# },
|
("pertenence-to-group", 'earth', 'planet')),
|
||||||
# {
|
"answer": True,
|
||||||
# "text": "Is green a color?",
|
}),
|
||||||
# "affirmation": "Is green a color?",
|
('full_example',
|
||||||
# "parsed": (),
|
{
|
||||||
# "answer": None,
|
"text": "Is green a color?",
|
||||||
# },
|
"affirmation": "green is a color",
|
||||||
# {
|
"parsed": ("question",
|
||||||
# "text": "do airplanes fly?",
|
("pertenence-to-group", 'green', 'color')),
|
||||||
# "affirmation": "do airplanes fly?",
|
"answer": True,
|
||||||
# "parsed": (),
|
}),
|
||||||
# "answer": None,
|
('full_example',
|
||||||
# },
|
{
|
||||||
|
"text": "do airplanes fly?",
|
||||||
|
"affirmation": "airplanes fly",
|
||||||
|
"parsed": ("question",
|
||||||
|
("has-capacity", 'plane', 'fly')),
|
||||||
|
"answer": True,
|
||||||
|
}),
|
||||||
# {
|
# {
|
||||||
# "text": "Is it hot during the summer?",
|
# "text": "Is it hot during the summer?",
|
||||||
# "affirmation": "Is it hot during the summer?",
|
# "affirmation": "Is it hot during the summer?",
|
||||||
@ -61,12 +69,12 @@ examples = [
|
|||||||
# "parsed": (),
|
# "parsed": (),
|
||||||
# "answer": None,
|
# "answer": None,
|
||||||
# },
|
# },
|
||||||
# {
|
('text_example',
|
||||||
# "text": "Is milk white?",
|
{
|
||||||
# "affirmation": "Is milk white?",
|
"question": "Is milk white?",
|
||||||
# "parsed": (),
|
"affirmation": "milk is white",
|
||||||
# "answer": None,
|
"answer": True,
|
||||||
# },
|
}),
|
||||||
# {
|
# {
|
||||||
# "text": "do people have emotions?",
|
# "text": "do people have emotions?",
|
||||||
# "affirmation": "do people have emotions?",
|
# "affirmation": "do people have emotions?",
|
||||||
@ -607,10 +615,24 @@ base_knowledge = {
|
|||||||
'icecream': {
|
'icecream': {
|
||||||
"groups": set(['noun', 'object', 'comestible', 'sweet']),
|
"groups": set(['noun', 'object', 'comestible', 'sweet']),
|
||||||
},
|
},
|
||||||
"cold": {
|
'cold': {
|
||||||
"groups": set(['property', 'temperature']),
|
"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():
|
def main():
|
||||||
@ -618,20 +640,30 @@ def main():
|
|||||||
knowledge=base_knowledge,
|
knowledge=base_knowledge,
|
||||||
)
|
)
|
||||||
|
|
||||||
affirmations = [
|
for example_type, data in examples:
|
||||||
{
|
if example_type == 'full_example':
|
||||||
'text': x['affirmation'],
|
affirmation = {
|
||||||
'parsed': x['parsed'][1],
|
'text': data['affirmation'],
|
||||||
|
'parsed': data['parsed'][1],
|
||||||
}
|
}
|
||||||
for x in examples
|
question = data
|
||||||
]
|
differences = knowledge.train([affirmation])
|
||||||
questions = examples
|
differences = knowledge.train([question])
|
||||||
|
|
||||||
differences = knowledge.train(affirmations)
|
result, _, _ = knowledge.process(data['text'])
|
||||||
differences = knowledge.train(questions)
|
|
||||||
|
|
||||||
for example in examples:
|
if result != data['answer']:
|
||||||
result, _, _ = knowledge.process(example['text'])
|
raise AssertionError('{} is not {}'.format(result, data['answer']))
|
||||||
|
|
||||||
if result != example['answer']:
|
elif example_type == 'text_example':
|
||||||
raise AssertionError('{} is not {}'.format(result, example['answer']))
|
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