Edinburgh Speech Tools  2.1-release
item_feats.cc
Go to the documentation of this file.
1 /*************************************************************************/
2 /* */
3 /* Centre for Speech Technology Research */
4 /* University of Edinburgh, UK */
5 /* Copyright (c) 1998 */
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 /* Author : Alan W Black */
34 /* Date : June 1998 */
35 /*-----------------------------------------------------------------------*/
36 /* Support for feature functions for EST_Items */
37 /* */
38 /*=======================================================================*/
39 #include <cstdlib>
40 #include <cstdio>
41 #include <iostream>
42 #include <fstream>
43 #include "EST_THash.h"
44 #include "ling_class/EST_Item.h"
49 
50 using namespace std;
51 
53 {
54  (void)f;
55  return "<<EST_Item_featfunc>>";
56 }
57 
59 {
61 
62  return f;
63 }
64 
65 void register_featfunc(const EST_String &name, const EST_Item_featfunc func)
66 {
67  if (EST_FeatureFunctionContext::global->get_featfunc("standard", name,0) != 0)
68  cerr << "item featfunc \"" << name <<
69  "\" redefined definition" << endl;
70 
71  EST_FeatureFunctionPackage *package = EST_FeatureFunctionContext::global->get_package("standard");
72 
73  package->register_func(name,func);
74 }
75 
77 {
78 
79  int found;
81 
82  if (!found)
83  EST_error("featfunc %p has no name", func);
84 
85  return name;
86 }
87 
89  void (*init_fn)(EST_FeatureFunctionPackage &p))
90 {
91  EST_FeatureFunctionPackage *package = new EST_FeatureFunctionPackage(name, 20);
93  (*init_fn)(*package);
94 }
95 
96 /* EST_Item_featfuncs may be used in EST_Vals */
97 /* EST_Item_featfuncs aren't a class so we can't use the standard */
98 /* registration procedure and have to explicitly write it */
101 {
102  if (v.type() == val_type_featfunc)
103  return (const EST_Item_featfunc)v.internal_ptr();
104  else
105  EST_error("val not of type val_type_featfunc");
106  return NULL;
107 }
108 
109 void val_delete_featfunc(void *v)
110 { /* Function pointers can't be freed */
111  (void)v;
112 }
113 
114 /* Sergio Oller: Comment it out: unused. Did you mean *v1 = *v2? */
115 #if 0
116 void val_copy_featfunc(void *v1,void *v2)
117 {
118  v1 = v2;
119 }
120 #endif
121 
123 {
124  return EST_Val(val_type_featfunc,(void *)f,val_delete_featfunc);
125 }
126 
127 #if 0
128 /* An example only */
129 EST_Val start_time(EST_Item *s)
130 {
131  EST_Relation *r = s->relation();
132 
133  if (s == 0)
134  return 0.0;
135  else if ((r == 0) || (r->f("timing-style") != "segment"))
136  return s->f("start");
137  else
138  {
139  // Its to be derived.
140  EST_String asrel = r->f("start-from");
141  EST_Item *fl = s->first_leaf();
142 
143  if ((asrel == "0") || (asrel == s->relation_name()))
144  {
145  if (prev(s))
146  return prev(fl)->f("end");
147  else
148  return 0.0;
149  }
150  else
151  return start_time(fl->as_relation(asrel));
152  }
153 }
154 #endif
EST_Val est_val(const EST_Item_featfunc f)
Definition: item_feats.cc:122
EST_Val(* EST_Item_featfunc)(class EST_Item *)
Definition: EST_Features.h:53
EST_Item_featfunc get_featfunc(const EST_String name, int must=0)
EST_Item_featfunc featfunc(const EST_Val &v)
Definition: item_feats.cc:100
void register_func(const EST_String &name, const EST_Item_featfunc func)
const char * val_type
Definition: EST_Val.h:57
EST_Item * as_relation(const char *relname) const
View item from another relation (const char *) method.
Definition: EST_Item.h:316
const EST_Val f(const EST_String &name) const
Definition: EST_Item.h:260
val_type val_type_featfunc
Definition: item_feats.cc:99
const EST_String & relation_name() const
The relation name of this particular item.
Definition: EST_Item.cc:196
val_type type(void) const
Definition: EST_Val.h:137
EST_String get_featname(const EST_Item_featfunc func)
Definition: item_feats.cc:76
EST_String get_featfunc_name(const EST_Item_featfunc func, int &found) const
NULL
Definition: EST_WFST.cc:55
const void * internal_ptr(void) const
Definition: EST_Val.h:174
#define EST_error
Definition: EST_error.h:104
f
Definition: EST_item_aux.cc:48
const char * error_name(EST_Item_featfunc f)
Definition: item_feats.cc:52
static EST_FeatureFunctionContext * global
EST_Relation * relation(void) const
The relation of this particular item.
Definition: EST_Item.h:330
EST_Features f
Definition: EST_Relation.h:101
EST_Item_featfunc get_featfunc(const EST_String &name, int must)
Definition: item_feats.cc:58
void register_featfunc(const EST_String &name, const EST_Item_featfunc func)
Definition: item_feats.cc:65
void val_delete_featfunc(void *v)
Definition: item_feats.cc:109
EST_Item * first_leaf() const
Definition: EST_Item.cc:386
void EST_register_feature_function_package(const char *name, void(*init_fn)(EST_FeatureFunctionPackage &p))
Definition: item_feats.cc:88
void add_package(EST_FeatureFunctionPackage *package)