Exercise 7: Mapping words to entities

Summary

Before we can transform language, we need to convert words to entities. We can do this my defining word-to-entity mappings. For example:

'I' -> speaker: noun

What this says is that the word "I" might refer to the speaker entity, which is a noun. The specification that speaker is a noun is a convenience feature and simply ensures that the relationship speaker is_a noun exists. Any entity can be used in place of noun. For example: adjective, verb, adverb, etc.

Implement a representation and parser. Also implement a web UI that allows the user to specify one or more word-to-entity mappings to be parsed.

In addition to these mappings, allow the user to specify a word, which will return all of the entities that that word maps to. Implement this feature with classes called EntityTree and EntityTreeNode which will represent the tree of is_a relationships that stem from a word. The tree should be doubly linked so that, given a node, you can get either its children or its parent, and it should prevent duplicate tree nodes. The tree will contain a method named GetList which will traverse the tree and return a flat list of EntityTreeNodes.

Test cases

Click here

Solution

Click here

Web UI

Click here