Edinburgh Speech Tools  2.1-release
EST_item_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 items. */
37  /* */
38  /*************************************************************************/
39 
41 #include "ling_class/EST_Item.h"
42 #include "EST_String.h"
43 #include "EST_error.h"
44 
45 #include "../base_class/EST_get_function_template.h"
46 
49 defineGetFunction(EST_Item, f, float, getFloat)
50 defineGetFunction(EST_Item, f, int, getInteger)
51 
52 float start(const EST_Item &item)
53 {
54  float v=0;
55  EST_feat_status status=efs_ok;
56  EST_Item * pp;
57 
58  v = getFloat(item, "start", -1.0, status);
59 
60  if (v<0.0)
61  {
62  if ((pp = item.prev()) != NULL)
63  v = getFloat(*pp, "end", -1.0, status);
64  }
65 
66  return v;
67 }
68 
69 float mid(const EST_Item &item)
70 {
71  float v = 0;
72  EST_feat_status status=efs_ok;
73 
74  v = getFloat(item, "mid", -1.0, status);
75 
76  if (v<0.0)
77  v = (start(item)+end(item))/2.0;
78 
79  return v;
80 }
81 
82 float time(const EST_Item &item)
83 {
84 
85  float v = 0;
86  EST_feat_status status=efs_ok;
87 
88  v = getFloat(item, "time", -1.0, status);
89 
90  if (v<0.0)
91  v = mid(item);
92 
93  return v;
94 }
95 
96 float end(const EST_Item &item)
97 {
98  float v=0;
99  EST_feat_status status=efs_ok;
100  EST_Item * nn;
101 
102  v = getFloat(item, "end", -1.0, status);
103 
104  if (v < 0.0)
105  {
106  if ((nn = item.next()) != NULL)
107  v = getFloat(*nn, "start", -1.0, status);
108  }
109 
110  return v;
111 }
112 
float getFloat(const EST_Features &f, const EST_String name, float def, EST_feat_status &status)
Return the values as a float.
EST_String getString(const EST_Features &f, const EST_String name, const EST_String &def, EST_feat_status &status)
Return the value as a string.
float end(const EST_Item &item)
Definition: EST_item_aux.cc:96
int getInteger(const EST_Features &f, const EST_String name, int def, EST_feat_status &status)
Return the values as a float.
getString getInteger float start(const EST_Item &item)
Definition: EST_item_aux.cc:52
defineGetFunction(EST_Item, f, EST_Val, getVal) defineGetFunction(EST_Item
EST_Item * prev() const
Definition: EST_Item.h:350
float time(const EST_Item &item)
Definition: EST_item_aux.cc:82
float mid(const EST_Item &item)
Definition: EST_item_aux.cc:69
All OK, value returned.
NULL
Definition: EST_WFST.cc:55
f
Definition: EST_item_aux.cc:48
EST_Item * next() const
Definition: EST_Item.h:348
EST_Val getVal(const EST_Features &f, const EST_String name, const EST_Val &def, EST_feat_status &status)
Return the value as an EST_Val.
EST_feat_status