"Fossies" - the Fresh Open Source Software Archive 
Member "speech_tools/ling_class/standard_feature_functions.cc" (4 Sep 2017, 7918 Bytes) of package /linux/misc/speech_tools-2.5.0-release.tar.gz:
1 /************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1996,1997 */
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 /* Author: Richard Caley (rjc@cstr.ed.ac.uk) */
35 /* Originally: Paul Taylor (pault@cstr,ed,ac,uk) */
36 /* -------------------------------------------------------------------- */
37 /* Some generally useful feature functions. */
38 /* */
39 /* Mostly not very general and way too specific, these shouldn't be here */
40 /* */
41 /*************************************************************************/
42
43 #include "ling_class/EST_Item.h"
44 #include "ling_class/EST_Relation.h"
45 #include "ling_class/EST_Item_Content.h"
46 #include "ling_class/EST_item_aux.h"
47
48 EST_Val ff_duration(EST_Item *s)
49 {
50 if (iprev(s))
51 return s->F("end")-iprev(s)->F("end");
52 else
53 return s->F("end");
54 }
55
56 EST_Val ff_start(EST_Item *s)
57 {
58 /* Changed by awb 12/07/05, to make this actually a generic function */
59 /* no longer changes relation view to Segment -- may affect tilt and */
60 /* other pault things */
61 return (iprev(s) == 0) ? 0.0 : iprev(s)->F("end");
62 }
63
64 EST_Val ff_tilt_phrase_position(EST_Item *s)
65 {
66 EST_String rel_name = s->S("time_path");
67 EST_Item *t, *a;
68
69 if ((t = s->as_relation(rel_name)) == 0)
70 {
71 cerr << "item: " << *s << endl;
72 EST_error("No relation %s for item\n", (const char *) rel_name);
73 }
74
75 a = parent(t);
76
77 cout << "us features phrase pos\n";
78 //cout << "dereferencing syllable: " << *a << endl;
79 cout << "start: " << a->F("start") << endl;
80 cout << "end: " << a->F("end") << endl;
81
82 if (s->S("name","0") == "phrase_start")
83 return a->F("start");
84 else
85 return a->F("end");
86 }
87
88 EST_Val ff_tilt_event_position(EST_Item *s)
89 {
90 EST_String rel_name = s->S("time_path");
91 EST_Item *t, *a;
92
93 if ((t = s->as_relation(rel_name)) == 0)
94 EST_error("No relation %s for item\n", (const char *) rel_name);
95
96 a = parent(t);
97
98 cout << "us features tilt pos\n";
99 cout << "dereferencing syllable: " << *a << endl;
100 cout << "vowel_start: " << a->F("vowel_start") << endl;
101 cout << "start: " << a->F("start") << endl;
102 cout << "end: " << a->F("end") << endl;
103
104 return a->F("vowel_start") + s->F("rel_pos",0.0);
105 }
106
107 EST_Val ff_leaf_end(EST_Item *s)
108 {
109 if (!s->f_present("time_path"))
110 EST_error("Attempted to use leaf end() feature function on "
111 "item with no time_path feature set: %s\n",
112 (const char *)s->relation()->name());
113
114 EST_String rel_name = s->S("time_path");
115 EST_Item *t, *a;
116
117 if ((t = s->as_relation(rel_name)) == 0)
118 EST_error("No relation %s for item\n", (const char *) rel_name);
119
120 a = last_leaf_in_tree(t);
121
122 float def = -1.0;
123 EST_feat_status stat;
124 return getFloat(*a, "end", def, stat);
125 }
126
127 EST_Val ff_leaf_start(EST_Item *s)
128 {
129 if (!s->f_present("time_path"))
130 EST_error("Attempted to use leaf start() feature function on "
131 "item with no time_path feature set: %s\n",
132 (const char *)s->relation()->name());
133
134 EST_String rel_name = s->S("time_path");
135 EST_Item *t, *a;
136
137 if ((t = s->as_relation(rel_name)) == 0)
138 EST_error("No relation %s for item\n", (const char *) rel_name);
139
140 a = first_leaf_in_tree(t);
141 // cout << "this is the first node of the tree\n";
142 //cout << *a << endl;
143
144 float def = -1.0;
145 EST_feat_status stat;
146 return getFloat(*a, "start", def, stat);
147 }
148
149 EST_Val ff_int_start(EST_Item *s)
150 {
151 EST_String rel_name = "IntonationPhrase";
152 EST_Item *t, *a;
153
154 if ((t = s->as_relation(rel_name)) == 0)
155 EST_error("No relation %s for item\n", (const char *) rel_name);
156
157 a = first_leaf_in_tree(parent(t)->as_relation("MetricalTree"));
158
159 float def = -1.0;
160 EST_feat_status stat;
161 return getFloat(*a, "start", def, stat);
162 }
163
164 EST_Val ff_int_end(EST_Item *s)
165 {
166 EST_String rel_name = "IntonationPhrase";
167 EST_Item *t, *a;
168
169 if ((t = s->as_relation(rel_name)) == 0)
170 EST_error("No relation %s for item\n", (const char *) rel_name);
171
172 a = last_leaf_in_tree(parent(t)->as_relation("MetricalTree"));
173
174 float def = -1.0;
175 EST_feat_status stat;
176 return getFloat(*a, "end", def, stat);
177 }
178
179 void register_standard_feature_functions(EST_FeatureFunctionPackage &p)
180 {
181 #ifdef EST_DEBUGGING
182 cerr << "register_standard_feature_functions()\n";
183 #endif
184 p.register_func("duration", ff_duration);
185 p.register_func("start", ff_start);
186 p.register_func("leaf_end", ff_leaf_end);
187 p.register_func("leaf_start", ff_leaf_start);
188 p.register_func("int_end", ff_int_end);
189 p.register_func("int_start", ff_int_start);
190 p.register_func("tilt_event_position", ff_tilt_event_position);
191 p.register_func("tilt_phrase_position", ff_tilt_phrase_position);
192 p.register_func("unisyn_duration", ff_duration);
193 p.register_func("unisyn_start", ff_start);
194 p.register_func("unisyn_leaf_end", ff_leaf_end);
195 p.register_func("unisyn_leaf_start", ff_leaf_start);
196 p.register_func("unisyn_int_end", ff_int_end);
197 p.register_func("unisyn_int_start", ff_int_start);
198 p.register_func("unisyn_tilt_event_position", ff_tilt_event_position);
199 p.register_func("unisyn_tilt_phrase_position", ff_tilt_phrase_position);
200 #ifdef EST_DEBUGGING
201 cerr << "finished register_standard_feature_functions()\n";
202 #endif
203 }
204
205
206