Edinburgh Speech Tools  2.1-release
feature_regression.cc
Go to the documentation of this file.
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 using namespace std;
38 
39 
40 /** @name Feature and Val Classes Example Code
41  */
42 //@{
43 
44 int main(void)
45 {
46 
47  /** @name Adding basic information to an EST_Item
48  *
49  * An item such as
50 \f[
51 \left [
52 \begin{array}{ll}
53 \mbox{POS} & \mbox{\emph{Noun}} \\
54 \mbox{NAME} & \mbox{\emph{example}} \\
55 \mbox{FOCUS} & \mbox{+} \\
56 \end{array} \right ]
57 \f]
58 
59  * is constructed as follows: (note that
60  * the attributes are in capitals by linguistic convention only:
61  * attribute names are case sensitive and can be upper or lower
62  * case).
63  */
64  //@{
65 
66  //@{ code
67  EST_Item p;
68 
69  p.set("POS", "Noun");
70  p.set("NAME", "example");
71  p.set("FOCUS", "+");
72  p.set("DURATION", 2.76);
73  p.set("STRESS", 2);
74 
75  //@} code
76 
77  /** The type of the values in features is a
78  * <classname>EST_Val</classname> class, which is a union which can
79  * store ints, floats, EST_Strings, void pointers, and
80  * <classname>EST_Features</classname>. The overloaded function
81  * facility of C++ means that the <function>set()</function> can be
82  * used for all of these.
83  */
84 
85  //@}
86 
87  /** @name Accessing basic information in an Item
88  *
89  * When accessing the features, the type must be
90  * specified. This is done most easily by using of a series of
91  * functions whose type is coded by a capital letter:
92  * </para>
93  * <formalpara><title><function>F()</function></title><para> return value as a
94  * float</para></formalpara>
95  * <formalpara><title><function>I()</function></title><para> return value as a
96  * integer</para></formalpara>
97  * <formalpara><title><function>S()</function></title><para> return value as a
98  * <formalpara><title><function>A()</function></title><para> return value as a
99  * EST_Features</para></formalpara>
100  * <para>
101  */
102 
103  //@{
104 
105  //@{ code
106  cout << "Part of speech for p is " << p.S("POS") << endl;
107  cout << "Duration for p is " << p.F("DURATION") << endl;
108  cout << "Stress value for p is " << p.I("STRESS") << endl;
109  //@} code
110 
111  /** </para>
112  * <SIDEBAR>
113  * <TITLE>Output</TITLE>
114  * <screen>
115  * "Noun"
116  * 2.75
117  * 1
118  * </screen>
119  * </SIDEBAR>
120  * <para>
121  * A optional default value can be given if a result is always desired
122  */
123 
124  //@{ code
125  cout << "Part of speech for p is "
126  << p.S("POS") << endl;
127  cout << "Syntactic Category for p is "
128  << p.S("CAT", "Noun") << endl; // noerror
129  //@} code
130 
131  //@}
132 
133  /** @name Nested feature structures in items
134  *
135  * Nested feature structures such as
136 \f[
137 \left [
138 \begin{array}{ll}
139 \mbox{NAME} & \mbox{\emph{d}} \\
140 \mbox{PLACE OF ARTICULATION \boxed{1} } &
141  \left [ \begin{array}{ll}
142  \mbox{CORONAL} & \mbox{\emph{+}} \\
143  \mbox{ANTERIOR} & \mbox{\emph{+}} \\
144  \end{array} \right ] \\
145 \mbox{VOICE} & \mbox{\emph{+}} \\
146 \mbox{CONTINUANT} & \mbox{\emph{--}} \\
147 \mbox{SONORANT} & \mbox{\emph{--}} \\
148 \end{array} \right ]
149 \f]
150  * can be created in a number of ways:
151  */
152  //@{
153 
154  //@{ code
155 
156  p.set("NAME", "d");
157  p.set("VOICE", "+");
158  p.set("CONTINUANT", "-");
159  p.set("SONORANT", "-");
160 
161  EST_Features f;
162  p.set("PLACE OF ARTICULATION", f); // copy in empty feature set here
163 
164  p.A("PLACE OF ARTICULATION").set("CORONAL", "+");
165  p.A("PLACE OF ARTICULATION").set("ANTERIOR", "+");
166  //@} code
167 
168  /** or by filling the values in an EST_Features object and
169  * copying it in:
170  */
171 
172  //@{ code
173  EST_Features f2;
174 
175  f2.set("CORONAL", "+");
176  f2.set("ANTERIOR", "+");
177 
178  p.set("PLACE OF ARTICULATION", f2);
179  //@} code
180 
181 
182  /** Nested features can be accessed by multiple calls to the
183  * accessing commands:
184  */
185 
186  //@{ code
187  cout << "Anterior value is: " << p.A("PLACE OF ARTICULATION").S("ANTERIOR");
188  cout << "Coronal value is: " << p.A("PLACE OF ARTICULATION").S("CORONAL");
189  //@} code
190 
191  /** The first command is <function>A()</function> because PLACE is a
192  * feature structure, and the second command is
193  * <function>S()</function> because it returns a string (the
194  * value or ANTRIOR or CORONAL). A shorthand is provided to
195  * extract the value in a single statement:
196  */
197 
198  //@{ code
199  cout << "Anterior value is: " << p.S("PLACE OF ARTICULATION.ANTERIOR");
200  cout << "Coronal value is: " << p.S("PLACE OF ARTICULATION.CORONAL");
201  //@} code
202 
203  /** Again, as the last value to be returned is a string
204  * <function>S()</function> must be used. This shorthand can also be used
205  * to set the features:
206  */
207 
208  //@{ code
209 
210  p.set("PLACE OF ARTICULATION.CORONAL", "+");
211  p.set("PLACE OF ARTICULATION.ANTERIOR", "+");
212  //@} code
213 
214  /** this is the easiest and most commonly used method. */
215 
216 
217  //@}
218 
219  /** @name Utility functions for items
220  *
221  * The presence of a attribute can be checked using
222  * <function>f_present()</function>, which returns true if the
223  * attribute is in the item:
224  */
225  //@{
226 
227  //@{ code
228  cout << "This is true: " << p.f_present("PLACE OF ARTICULATION");
229  cout << "This is false: " << p.f_present("MANNER");
230  //@} code
231 
232  /** A attribute can be removed by <function>f_remove</function>
233  */
234 
235  //@{ code
236  p.f_remove("PLACE OF ARTICULATION");
237  //@} code
238 
239  //@}
240 
241  exit(0);
242 
243 }
244 //@}
int I(const EST_String &name) const
Definition: EST_Item.h:155
void set(const EST_String &name, ssize_t ival)
Definition: EST_Item.h:185
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
int main(int argc, char **argv)
Definition: align_main.cc:69
float F(const EST_String &name) const
Definition: EST_Item.h:135
f
Definition: EST_item_aux.cc:48
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
void f_remove(const EST_String &name)
Definition: EST_Item.h:228
int f_present(const EST_String &name) const
Definition: EST_Item.h:236