Edinburgh Speech Tools  2.1-release
standard_feature_functions.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,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"
47 
48 using namespace std;
49 
51 {
52  if (s->prev())
53  return s->F("end")-s->prev()->F("end");
54  else
55  return s->F("end");
56 }
57 
59 {
60  /* Changed by awb 12/07/05, to make this actually a generic function */
61  /* no longer changes relation view to Segment -- may affect tilt and */
62  /* other pault things */
63  return (s->prev() == 0) ? 0.0 : s->prev()->F("end");
64 }
65 
67 {
68  EST_String rel_name = s->S("time_path");
69  EST_Item *t, *a;
70 
71  if ((t = s->as_relation(rel_name)) == 0)
72  {
73  cerr << "item: " << *s << endl;
74  EST_error("No relation %s for item\n", (const char *) rel_name);
75  }
76 
77  a = parent(t);
78 
79  cout << "us features phrase pos\n";
80  //cout << "dereferencing syllable: " << *a << endl;
81  cout << "start: " << a->F("start") << endl;
82  cout << "end: " << a->F("end") << endl;
83 
84  if (s->S("name","0") == "phrase_start")
85  return a->F("start");
86  else
87  return a->F("end");
88 }
89 
91 {
92  EST_String rel_name = s->S("time_path");
93  EST_Item *t, *a;
94 
95  if ((t = s->as_relation(rel_name)) == 0)
96  EST_error("No relation %s for item\n", (const char *) rel_name);
97 
98  a = parent(t);
99 
100  cout << "us features tilt pos\n";
101  cout << "dereferencing syllable: " << *a << endl;
102  cout << "vowel_start: " << a->F("vowel_start") << endl;
103  cout << "start: " << a->F("start") << endl;
104  cout << "end: " << a->F("end") << endl;
105 
106  return a->F("vowel_start") + s->F("rel_pos",0.0);
107 }
108 
110 {
111  if (!s->f_present("time_path"))
112  EST_error("Attempted to use leaf end() feature function on "
113  "item with no time_path feature set: %s\n",
114  (const char *)s->relation()->name());
115 
116  EST_String rel_name = s->S("time_path");
117  EST_Item *t, *a;
118 
119  if ((t = s->as_relation(rel_name)) == 0)
120  EST_error("No relation %s for item\n", (const char *) rel_name);
121 
122  a = last_leaf_in_tree(t);
123 
124  float def = -1.0;
125  EST_feat_status stat;
126  return getFloat(*a, "end", def, stat);
127 }
128 
130 {
131  if (!s->f_present("time_path"))
132  EST_error("Attempted to use leaf start() feature function on "
133  "item with no time_path feature set: %s\n",
134  (const char *)s->relation()->name());
135 
136  EST_String rel_name = s->S("time_path");
137  EST_Item *t, *a;
138 
139  if ((t = s->as_relation(rel_name)) == 0)
140  EST_error("No relation %s for item\n", (const char *) rel_name);
141 
142  a = first_leaf_in_tree(t);
143  // cout << "this is the first node of the tree\n";
144  //cout << *a << endl;
145 
146  float def = -1.0;
147  EST_feat_status stat;
148  return getFloat(*a, "start", def, stat);
149 }
150 
152 {
153  EST_String rel_name = "IntonationPhrase";
154  EST_Item *t, *a;
155 
156  if ((t = s->as_relation(rel_name)) == 0)
157  EST_error("No relation %s for item\n", (const char *) rel_name);
158 
159  a = first_leaf_in_tree(parent(t)->as_relation("MetricalTree"));
160 
161  float def = -1.0;
162  EST_feat_status stat;
163  return getFloat(*a, "start", def, stat);
164 }
165 
167 {
168  EST_String rel_name = "IntonationPhrase";
169  EST_Item *t, *a;
170 
171  if ((t = s->as_relation(rel_name)) == 0)
172  EST_error("No relation %s for item\n", (const char *) rel_name);
173 
174  a = last_leaf_in_tree(parent(t)->as_relation("MetricalTree"));
175 
176  float def = -1.0;
177  EST_feat_status stat;
178  return getFloat(*a, "end", def, stat);
179 }
180 
182 {
183 #ifdef EST_DEBUGGING
184  cerr << "register_standard_feature_functions()\n";
185 #endif
186  p.register_func("duration", ff_duration);
187  p.register_func("start", ff_start);
188  p.register_func("leaf_end", ff_leaf_end);
189  p.register_func("leaf_start", ff_leaf_start);
190  p.register_func("int_end", ff_int_end);
191  p.register_func("int_start", ff_int_start);
192  p.register_func("tilt_event_position", ff_tilt_event_position);
193  p.register_func("tilt_phrase_position", ff_tilt_phrase_position);
194  p.register_func("unisyn_duration", ff_duration);
195  p.register_func("unisyn_start", ff_start);
196  p.register_func("unisyn_leaf_end", ff_leaf_end);
197  p.register_func("unisyn_leaf_start", ff_leaf_start);
198  p.register_func("unisyn_int_end", ff_int_end);
199  p.register_func("unisyn_int_start", ff_int_start);
200  p.register_func("unisyn_tilt_event_position", ff_tilt_event_position);
201  p.register_func("unisyn_tilt_phrase_position", ff_tilt_phrase_position);
202 #ifdef EST_DEBUGGING
203  cerr << "finished register_standard_feature_functions()\n";
204 #endif
205 }
206 
207 
208 
EST_Val ff_int_start(EST_Item *s)
float getFloat(const EST_Features &f, const EST_String name, float def, EST_feat_status &status)
Return the values as a float.
void register_func(const EST_String &name, const EST_Item_featfunc func)
EST_Val ff_tilt_phrase_position(EST_Item *s)
EST_Val ff_duration(EST_Item *s)
EST_Item * as_relation(const char *relname) const
View item from another relation (const char *) method.
Definition: EST_Item.h:316
EST_Val ff_int_end(EST_Item *s)
const EST_String & name() const
Definition: EST_Relation.h:118
EST_Item * prev() const
Definition: EST_Item.h:350
float F(const EST_String &name) const
Definition: EST_Item.h:135
#define EST_error
Definition: EST_error.h:104
EST_Relation * relation(void) const
The relation of this particular item.
Definition: EST_Item.h:330
EST_Item * first_leaf_in_tree(const EST_Item *root)
Definition: EST_Item.cc:410
EST_Val ff_leaf_start(EST_Item *s)
EST_Val ff_leaf_end(EST_Item *s)
EST_Val ff_tilt_event_position(EST_Item *s)
void register_standard_feature_functions(EST_FeatureFunctionPackage &p)
const EST_String S(const EST_String &name) const
Definition: EST_Item.h:144
EST_Item * last_leaf_in_tree(const EST_Item *root)
Definition: EST_Item.cc:415
EST_Item * parent(const EST_Item *n)
return parent of n
EST_Val ff_start(EST_Item *s)
EST_feat_status
int f_present(const EST_String &name) const
Definition: EST_Item.h:236