Some examples of usage of linguistic classes
An item such as:
is constructed as follows: (note that the attributes are in capitals by linguistic convention only: attribute names are case sensitive and can be upper or lower case).
The type of the values in features is a EST_Val class, which is a union which can store ints, floats, EST_Strings, void pointers, and EST_Features. The overloaded function facility of C++ means that the EST_Item::set() can be used for all of these.
When accessing the features, the type must be specified. This is done most easily by using of a series of functions whose type is coded by a capital letter:
Output: "Noun" 2.75 1
A optional default value can be given if a result is always desired
Nested feature structures such as
can be created in a number of ways:
or by filling the values in an EST_Features object and copying it in:
Nested features can be accessed by multiple calls to the accessing commands:
The first command is EST_Item::A() because PLACE is a feature structure, and the second command is EST_Item::S() because it returns a string (the value or ANTERIOR or CORONAL). A shorthand is provided to extract the value in a single statement:
Again, as the last value to be returned is a string EST_Item::S() must be used. This shorthand can also be used to set the features:
this is the easiest and most commonly used method.
The presence of a attribute can be checked using EST_Item::f_present(), which returns true if the attribute is in the item:
An attribute can be removed by EST_Item::f_remove.
It is standard to store the phones for an utterance as a linear list in a EST_Relation object. Each phone is represented by one EST_Item, whereas the complete list is stored as a EST_Relation.
The easiest way to build a linear list is by using the EST_Relation::append(), which when called without arguments, makes a new empty EST_Item, adds it onto the end of the relation and returns a pointer to it. The information relevant to that phone can then be added to the returned item.
Note that the -> operator is used because the EST_Item a is a pointer here. The same pointer variable can be used multiple times because every time EST_Relation::append() is called it allocates a new item and returns a pointer to it.
If you already have a EST_Item pointer and want to add it to a relation, you can give it as an argument to EST_Relation::append(), but this is generally inadvisable as it involves some unnecessary copying, and also you have to allocate the memory for the next EST_Item pointer yourself every time (if you don't you will overwrite the previous one):
Items can be prepended in exactly the same way:
Iteration in lists is performed with EST_Relation::next() and EST_Relation::prev(), and an EST_Item, used as an iteration pointer.
Output:
name:i type:vowel name:n type:consonant name:f type:consonant name:o type:vowel name:r type:consonant name:m type:consonant
Output:
name:m type:consonant name:r type:consonant name:o type:vowel name:f type:consonant name:n type:consonant name:i type:vowel
EST_Relation::head() and EST_Relation::tail() return EST_Item pointers to the start and end of the list. EST_Relation::next() and EST_Relation::prev() returns the next or previous item in the list, and returns 0
when the end or start of the list is reached. Hence checking for 0
is a useful termination condition of the iteration. Taking advantage of C shorthand allows us to write:
It is standard to store information such as syntax as a tree in a EST_Relation object. Each tree node is represented by one EST_Item, whereas the complete tree is stored as a EST_Relation.
The easiest way to build a tree is by using the EST_Relation::append_daughter(), which when called without arguments, makes a new empty EST_Item, adds it as a daughter to an existing item and returns a pointer to it. The information relevant to that node can then be added to the returned item. The root node of the tree must be added directly to the EST_Relation.
Output:
(S (NP (N (John)) ) (VP (V (loves)) (NP (DET the) (NOUN woman)) ) )
Obviously, the use of recursive functions in building trees is more efficient and would eliminate the need for the large number of temporary variables used in the above example.
Iteration in trees is done with EST_Relation::daughter1() EST_Relation::daughter2() EST_Relation::daughtern() and EST_Relation::parent(). Pre-order traversal can be achieved iteratively as follows:
A special set of iterators are available for traversal of the leaf (terminal) nodes of a tree:
This is not yet fully implemented?
This is not yet fully implemented?
The EST_Utterance class is used to store all the items and relations relevant to a single utterance. (Here utterance is used as a general linguistic entity - it doesn't have to relate to a well formed complete linguistic unit such as a sentence or phrase).
Instead of storing relations separately, they are stored in utterances:
EST_Relations can be accessed though the utterance object either directly or by use of a temporary EST_Relation pointer:
The contents of the relation can be filled by the methods described above.
A major aspect of this system is that an item can be in two relations at once, as shown in Figure 6-2.
In the following example, using the syntax relation as already created in prog01, shows how to put the terminal nodes of this tree into a word relation:
Thus the terminal nodes in the syntax relation are now stored as a linear list in the word relation.
Hence
produces
Output:
(S (NP (N (John)) ) (VP (V (loves)) (NP (DET the) (NOUN woman)) ) )
whereas
produces
Output
John loves the woman
Even if an item is in more than one relation, it always has the idea of a "current" relation. If the traversal functions (next, previous, parent etc) are called, traversal always occurs with respect to the current relation. An item's current relation can be changed as follows:
while s is still the same item, the current relation is now "Syntax". The current relation is returned by the EST_Item::relation() function:
If you aren't sure whether an item is in a relation, you can check with EST_Item::in_relation(). This will return true if an item is in the requested relation regardless of what the current relation is.
evaluate functions
setting functions