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