Edinburgh Speech Tools  2.1-release
EST_item_content_aux.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  /* -------------------------------------------------------------------- */
36  /* Auxiliary functions related to item_contents. */
37  /* */
38  /*************************************************************************/
39 
43 #include "EST_String.h"
44 #include "EST_error.h"
45 
46 #include "../base_class/EST_get_function_template.h"
47 
50 defineGetFunction(EST_Item_Content, f.val, float, getFloatI)
51 defineGetFunction(EST_Item_Content, f.val, int, getIntegerI)
52 
53 
54 
55 EST_Val getVal(const EST_Item_Content &f,
56  const EST_String name,
57  const EST_Val &def,
58  EST_feat_status &s)
59 {
60  if (f.relations.length() == 0)
61  return getValI(f, name, def, s);
62  else
63  {
64  EST_Litem *p;
65  p = f.relations.head();
66  EST_Item *i = item(f.relations.list(p).v);
67  return getVal(*i, name, def, s);
68  }
69 }
70 
71 
73  const EST_String name,
74  const EST_String &def,
75  EST_feat_status &s)
76 {
77  if (f.relations.length() == 0)
78  return getStringI(f, name, def, s);
79  else
80  {
81  EST_Litem *p;
82  p = f.relations.head();
83  EST_Item *i = item(f.relations.list(p).v);
84  return getString(*i, name, def, s);
85  }
86 }
87 
89  const EST_String name,
90  const int &def,
91  EST_feat_status &s)
92 {
93  if (f.relations.length() == 0)
94  return getIntegerI(f, name, def, s);
95  else
96  {
97  EST_Litem *p;
98  p = f.relations.head();
99  EST_Item *i = item(f.relations.list(p).v);
100  return getInteger(*i, name, def, s);
101  }
102 }
103 
105  const EST_String name,
106  const float &def,
107  EST_feat_status &s)
108 {
109  if (f.relations.length() == 0)
110  return getFloatI(f, name, def, s);
111  else
112  {
113  EST_Litem *p;
114  p = f.relations.head();
115  EST_Item *i = item(f.relations.list(p).v);
116  return getFloat(*i, name, def, s);
117  }
118 }
119 
120 
121 float start(const EST_Item_Content &item_content)
122 {
123  if (item_content.relations.length() == 0)
124  {
125  float v=0;
126  EST_feat_status status=efs_ok;
127 
128  v = getFloat(item_content, "start", -1.0, status);
129 
130  return v;
131  }
132  else
133  {
134  EST_Litem *p;
135  p = item_content.relations.head();
136  EST_Item *i = item(item_content.relations.list(p).v);
137  return start(*i);
138  }
139 }
140 
141 float mid(const EST_Item_Content &item_content)
142 {
143  if (item_content.relations.length() == 0)
144  {
145  float v = 0;
146  EST_feat_status status=efs_ok;
147 
148  v = getFloat(item_content, "mid", -1.0, status);
149 
150  if (v < 0.0)
151  v = (start(item_content)+end(item_content))/2.0;
152 
153  return v;
154  }
155  else
156  {
157  EST_Litem *p;
158  p = item_content.relations.head();
159  EST_Item *i = item(item_content.relations.list(p).v);
160  return mid(*i);
161  }
162 }
163 
164 float time(const EST_Item_Content &item_content)
165 {
166  if (item_content.relations.length() == 0)
167  {
168  float v = 0;
169  EST_feat_status status=efs_ok;
170 
171  v = getFloat(item_content, "time", -1.0, status);
172 
173  if (v < 0.0)
174  v = mid(item_content);
175 
176  return v;
177  }
178  else
179  {
180  EST_Litem *p;
181  p = item_content.relations.head();
182  EST_Item *i = item(item_content.relations.list(p).v);
183  return time(*i);
184  }
185 }
186 
187 float end(const EST_Item_Content &item_content)
188 {
189  if (item_content.relations.length() == 0)
190  {
191  float v=0;
192  EST_feat_status status=efs_ok;
193 
194  v = getFloat(item_content, "end", -1.0, status);
195 
196  return v;
197  }
198  else
199  {
200  EST_Litem *p;
201  p = item_content.relations.head();
202  EST_Item *i = item(item_content.relations.list(p).v);
203  return end(*i);
204  }
205 }
206 
defineGetFunction(EST_Item_Content, f.val, EST_Val, getValI) defineGetFunction(EST_Item_Content
float start(const EST_Item_Content &item_content)
int getInteger(const EST_Item_Content &f, const EST_String name, const int &def, EST_feat_status &s)
EST_TKVL< EST_String, EST_Val > relations
float time(const EST_Item_Content &item_content)
float end(const EST_Item_Content &item_content)
float mid(const EST_Item_Content &item_content)
EST_TList< EST_TKVI< K, V > > list
Linked list of key-val pairs. Don&#39;t use this as it will be made private in the future.
Definition: EST_TKVL.h:94
All OK, value returned.
EST_Litem * head() const
Return First key value pair in list.
Definition: EST_TKVL.h:100
f
Definition: EST_item_aux.cc:48
EST_String getString(const EST_Item_Content &f, const EST_String name, const EST_String &def, EST_feat_status &s)
Return the value as a string.
float getFloat(const EST_Item_Content &f, const EST_String name, const float &def, EST_feat_status &s)
Return the values as a float.
int length() const
number of key value pairs in list
Definition: EST_TKVL.h:97
f getStringI f getIntegerI EST_Val getVal(const EST_Item_Content &f, const EST_String name, const EST_Val &def, EST_feat_status &s)
Return the value as an EST_Val.
EST_feat_status