Edinburgh Speech Tools  2.1-release
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
feature_regression.cc
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1996 */
6 /* All Rights Reserved. */
7 /* */
8 /* Permission is hereby granted, free of charge, to use and distribute */
9 /* this software and its documentation without restriction, including */
10 /* without limitation the rights to use, copy, modify, merge, publish, */
11 /* distribute, sublicense, and/or sell copies of this work, and to */
12 /* permit persons to whom this work is furnished to do so, subject to */
13 /* the following conditions: */
14 /* 1. The code must retain the above copyright notice, this list of */
15 /* conditions and the following disclaimer. */
16 /* 2. Any modifications must be clearly marked as such. */
17 /* 3. Original authors' names are not deleted. */
18 /* 4. The authors' names are not used to endorse or promote products */
19 /* derived from this software without specific prior written */
20 /* permission. */
21 /* */
22 /* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23 /* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24 /* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25 /* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26 /* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27 /* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28 /* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29 /* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30 /* THIS SOFTWARE. */
31 /* */
32 /*************************************************************************/
33 
34 #include "EST_unix.h"
35 #include "EST_ling_class.h"
36 
37 
38 /** @name Feature and Val Classes Example Code
39  */
40 //@{
41 
42 int main(void)
43 {
44 
45  /** @name Adding basic information to an EST_Item
46  *
47  * An item such as
48 \f[
49 \left [
50 \begin{array}{ll}
51 \mbox{POS} & \mbox{\emph{Noun}} \\
52 \mbox{NAME} & \mbox{\emph{example}} \\
53 \mbox{FOCUS} & \mbox{+} \\
54 \end{array} \right ]
55 \f]
56 
57  * is constructed as follows: (note that
58  * the attributes are in capitals by linguistic convention only:
59  * attribute names are case sensitive and can be upper or lower
60  * case).
61  */
62  //@{
63 
64  //@{ code
65  EST_Item p;
66 
67  p.set("POS", "Noun");
68  p.set("NAME", "example");
69  p.set("FOCUS", "+");
70  p.set("DURATION", 2.76);
71  p.set("STRESS", 2);
72 
73  //@} code
74 
75  /** The type of the values in features is a
76  * <classname>EST_Val</classname> class, which is a union which can
77  * store ints, floats, EST_Strings, void pointers, and
78  * <classname>EST_Features</classname>. The overloaded function
79  * facility of C++ means that the <function>set()</function> can be
80  * used for all of these.
81  */
82 
83  //@}
84 
85  /** @name Accessing basic information in an Item
86  *
87  * When accessing the features, the type must be
88  * specified. This is done most easily by using of a series of
89  * functions whose type is coded by a capital letter:
90  * </para>
91  * <formalpara><title><function>F()</function></title><para> return value as a
92  * float</para></formalpara>
93  * <formalpara><title><function>I()</function></title><para> return value as a
94  * integer</para></formalpara>
95  * <formalpara><title><function>S()</function></title><para> return value as a
96  * <formalpara><title><function>A()</function></title><para> return value as a
97  * EST_Features</para></formalpara>
98  * <para>
99  */
100 
101  //@{
102 
103  //@{ code
104  cout << "Part of speech for p is " << p.S("POS") << endl;
105  cout << "Duration for p is " << p.F("DURATION") << endl;
106  cout << "Stress value for p is " << p.I("STRESS") << endl;
107  //@} code
108 
109  /** </para>
110  * <SIDEBAR>
111  * <TITLE>Output</TITLE>
112  * <screen>
113  * "Noun"
114  * 2.75
115  * 1
116  * </screen>
117  * </SIDEBAR>
118  * <para>
119  * A optional default value can be given if a result is always desired
120  */
121 
122  //@{ code
123  cout << "Part of speech for p is "
124  << p.S("POS") << endl;
125  cout << "Syntactic Category for p is "
126  << p.S("CAT", "Noun") << endl; // noerror
127  //@} code
128 
129  //@}
130 
131  /** @name Nested feature structures in items
132  *
133  * Nested feature structures such as
134 \f[
135 \left [
136 \begin{array}{ll}
137 \mbox{NAME} & \mbox{\emph{d}} \\
138 \mbox{PLACE OF ARTICULATION \boxed{1} } &
139  \left [ \begin{array}{ll}
140  \mbox{CORONAL} & \mbox{\emph{+}} \\
141  \mbox{ANTERIOR} & \mbox{\emph{+}} \\
142  \end{array} \right ] \\
143 \mbox{VOICE} & \mbox{\emph{+}} \\
144 \mbox{CONTINUANT} & \mbox{\emph{--}} \\
145 \mbox{SONORANT} & \mbox{\emph{--}} \\
146 \end{array} \right ]
147 \f]
148  * can be created in a number of ways:
149  */
150  //@{
151 
152  //@{ code
153 
154  p.set("NAME", "d");
155  p.set("VOICE", "+");
156  p.set("CONTINUANT", "-");
157  p.set("SONORANT", "-");
158 
159  EST_Features f;
160  p.set("PLACE OF ARTICULATION", f); // copy in empty feature set here
161 
162  p.A("PLACE OF ARTICULATION").set("CORONAL", "+");
163  p.A("PLACE OF ARTICULATION").set("ANTERIOR", "+");
164  //@} code
165 
166  /** or by filling the values in an EST_Features object and
167  * copying it in:
168  */
169 
170  //@{ code
171  EST_Features f2;
172 
173  f2.set("CORONAL", "+");
174  f2.set("ANTERIOR", "+");
175 
176  p.set("PLACE OF ARTICULATION", f2);
177  //@} code
178 
179 
180  /** Nested features can be accessed by multiple calls to the
181  * accessing commands:
182  */
183 
184  //@{ code
185  cout << "Anterior value is: " << p.A("PLACE OF ARTICULATION").S("ANTERIOR");
186  cout << "Coronal value is: " << p.A("PLACE OF ARTICULATION").S("CORONAL");
187  //@} code
188 
189  /** The first command is <function>A()</function> because PLACE is a
190  * feature structure, and the second command is
191  * <function>S()</function> because it returns a string (the
192  * value or ANTRIOR or CORONAL). A shorthand is provided to
193  * extract the value in a single statement:
194  */
195 
196  //@{ code
197  cout << "Anterior value is: " << p.S("PLACE OF ARTICULATION.ANTERIOR");
198  cout << "Coronal value is: " << p.S("PLACE OF ARTICULATION.CORONAL");
199  //@} code
200 
201  /** Again, as the last value to be returned is a string
202  * <function>S()</function> must be used. This shorthand can also be used
203  * to set the features:
204  */
205 
206  //@{ code
207 
208  p.set("PLACE OF ARTICULATION.CORONAL", "+");
209  p.set("PLACE OF ARTICULATION.ANTERIOR", "+");
210  //@} code
211 
212  /** this is the easiest and most commonly used method. */
213 
214 
215  //@}
216 
217  /** @name Utility functions for items
218  *
219  * The presence of a attribute can be checked using
220  * <function>f_present()</function>, which returns true if the
221  * attribute is in the item:
222  */
223  //@{
224 
225  //@{ code
226  cout << "This is true: " << p.f_present("PLACE OF ARTICULATION");
227  cout << "This is false: " << p.f_present("MANNER");
228  //@} code
229 
230  /** A attribute can be removed by <function>f_remove</function>
231  */
232 
233  //@{ code
234  p.f_remove("PLACE OF ARTICULATION");
235  //@} code
236 
237  //@}
238 
239  exit(0);
240 
241 }
242 //@}
void set(const EST_String &name, int ival)
Definition: EST_Features.h:186
const EST_String S(const EST_String &path) const
Definition: EST_Features.h:158
void set(const EST_String &name, int ival)
Definition: EST_Item.h:180
const int I(const EST_String &name) const
Definition: EST_Item.h:155
EST_Features & A(const EST_String &name) const
Definition: EST_Item.h:164
const EST_String S(const EST_String &name) const
Definition: EST_Item.h:144
const float F(const EST_String &name) const
Definition: EST_Item.h:135
void f_remove(const EST_String &name)
Definition: EST_Item.h:223
int f_present(const EST_String &name) const
Definition: EST_Item.h:231