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