Exercise 24: Basic context

Summary

The goal of this exercise is to implement basic support for the contextual words he, she, his, her, it, and its.

Context must be supported within a statement and across statements. For example:
Within a statement: "Daniel likes his bike."
Across statements: "Daniel is 27. He likes running."
If an entity is_a instance and is_a male, then it qualifies as a he.
If an entity is_a instance and is_a female, then it qualifies as a she.
If an entity is_a instance and is neither a male or a female, it qualifies as an it.
A very simple strategy will be used whereby any token which is interpreted to be a he, she, or it will become the contextual resolution for its respective class until it is replaced by the next match.
The entities context.he, context.she, and context.it will hold this information once a statement or question has finished processing.
The is_a instance relationship will be used to specify whether an entity is an actual instance of an object, rather than being a concept/class of object.
A short form notation will be introduced such that if an entity is defined as, for example, i:DanielBigham, an implicit relationship DanielBigham is_a instance will be created. All objects that should fulfill context must have this relationship.
Add basic support for multiple sentences. For the time being, simply split on ". ".

Tasks

Add support for the i: syntax and apply it where necessary so that all of the appropriate entities have the is_a relationship.
Add an IsInstance property to IEntity.
Add basic support for multiple sentences. For the time being, simply split on ". " and "? ".
Design and implement a Context class which will be used for resolving contextual words within the transformation process.
Add a ContextType enumeration with He, She and It as members.
Add a hash named localContext to the Context class that maps a ContextType to an entity. This will be used within the transformation process where we don't want to update context.he, context.she, or context.it since any time we consider an interpretation we might end up abandoning it.
Add properties He, She and It to the Context class, which return the current context for each respective type.
If the context isn't found in the localContext hash, get it from the context.he, context.she, and context.it entities. (Thus, the Context object will need a reference to the brain state)
Implement a ProcessToken class, which will take a token as its input and update the local context as needed.
Implement a Clone method.
Whenever a token is processed during the transformation search, call context.ProcessToken.
Add a Context property to the Fragment class, and set it with a clone of the current context each time a fragment is added during the transformation search.
Add a new transformation output type called TransOutput_ContextToken and thus a new token type called ContextToken. The syntax should be:
he -> context(he)
she -> context(she)
it -> context(it)
 
Update context.he, context.she, and context.it after a statement/question is successfully parsed.

Web UI

Click here