-
Notifications
You must be signed in to change notification settings - Fork 6
Handling sentences based on is
Near the top of the templates2.txt file is a group of templates based on the word is. I consider these to be the most basic and important of the program. Here's a simplified explanation of my approach to processing them.
These sentences are separated into attributes or class. Class is the group that the subject is part of.
I'll use the example of where the user types "chocolate is brown". The purpose of this kind of sentence(as I see it) is to attach an attribute(the color brown) to a substance(chocolate). Templates2.txt is searched for a template that matches and quickly matches "* is *". The function attribute_statement is called to handle it. Chocolate and brown are passed as parameters.
The database is checked to make sure that chocolate is a substance and brown is an attribute. That information is then added to the database as a key-value pair in this form: chocolate > color: brown.
That's the general idea but let's throw in some complications. It might happen that the first word isn't a substance or the third word might not be an attribute. It could be that the information is already in the database, or the information may conflict with what's there. The user is informed that something is amiss.
Here is a summary of how the attribute_statement and class_statement functions handle similar templates.
user input: a cat is an animal
matching template: a * is a *
purpose of the sentence: to attach an class to a something unknown
passed to class_statement function: cat, animal
check if animal is an object: yes
store in general.txt: cat > class: animal
user input: beer is a beverage
matching template: * is a *
purpose of the sentence: to attach an class to a substance
passed to class_statement function: beer, beverage
check if beer is a substance: yes
store in general.txt: beer > class: beverage
user input: chocolate is brown
matching template: * is *
purpose of the sentence: to attach an attribute to a substance
passed to attribute_statement function: chocolate, brown
check if chocolate is a substance: yes check if brown is an attribute: yes
get attribute type: color store in general.txt: chocolate > color: brown