Edinburgh Speech Tools 2.4-release
 
Loading...
Searching...
No Matches
item_feats.cc
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"
45#include "ling_class/EST_Item_Content.h"
46#include "ling_class/EST_Relation.h"
47#include "ling_class/EST_FeatureFunctionPackage.h"
48#include "EST_FeatureFunctionContext.h"
49
50const char *error_name(EST_Item_featfunc f)
51{
52 (void)f;
53 return "<<EST_Item_featfunc>>";
54}
55
56const EST_Item_featfunc get_featfunc(const EST_String &name,int must)
57{
58 const EST_Item_featfunc f = EST_FeatureFunctionContext::global->get_featfunc(name, must);
59
60 return f;
61}
62
63void register_featfunc(const EST_String &name, const EST_Item_featfunc func)
64{
65 if (EST_FeatureFunctionContext::global->get_featfunc("standard", name,0) != 0)
66 cerr << "item featfunc \"" << name <<
67 "\" redefined definition" << endl;
68
69 EST_FeatureFunctionPackage *package = EST_FeatureFunctionContext::global->get_package("standard");
70
71 package->register_func(name,func);
72}
73
74EST_String get_featname(const EST_Item_featfunc func)
75{
76
77 int found;
78 EST_String name = EST_FeatureFunctionContext::global->get_featfunc_name(func, found);
79
80 if (!found)
81 EST_error("featfunc %p has no name", func);
82
83 return name;
84}
85
86void EST_register_feature_function_package(const char *name,
87 void (*init_fn)(EST_FeatureFunctionPackage &p))
88{
89 EST_FeatureFunctionPackage *package = new EST_FeatureFunctionPackage(name, 20);
90 EST_FeatureFunctionContext::global->add_package(package);
91 (*init_fn)(*package);
92}
93
94/* EST_Item_featfuncs may be used in EST_Vals */
95/* EST_Item_featfuncs aren't a class so we can't use the standard */
96/* registration procedure and have to explicitly write it */
97val_type val_type_featfunc = "featfunc";
98const EST_Item_featfunc featfunc(const EST_Val &v)
99{
100 if (v.type() == val_type_featfunc)
101 return (const EST_Item_featfunc)v.internal_ptr();
102 else
103 EST_error("val not of type val_type_featfunc");
104 return NULL;
105}
106
107void val_delete_featfunc(void *v)
108{ /* Function pointers can't be freed */
109 (void)v;
110}
111
112void val_copy_featfunc(void *v1,void *v2)
113{
114 v1 = v2;
115}
116
117EST_Val est_val(const EST_Item_featfunc f)
118{
119 return EST_Val(val_type_featfunc,(void *)f,val_delete_featfunc);
120}
121
122#if 0
123/* An example only */
124EST_Val start_time(EST_Item *s)
125{
126 EST_Relation *r = s->relation();
127
128 if (s == 0)
129 return 0.0;
130 else if ((r == 0) || (r->f("timing-style") != "segment"))
131 return s->f("start");
132 else
133 {
134 // Its to be derived.
135 EST_String asrel = r->f("start-from");
136 EST_Item *fl = s->first_leaf();
137
138 if ((asrel == "0") || (asrel == s->relation_name()))
139 {
140 if (iprev(s))
141 return iprev(fl)->f("end");
142 else
143 return 0.0;
144 }
145 else
146 return start_time(fl->as_relation(asrel));
147 }
148}
149#endif
EST_Relation * relation(void) const
The relation of this particular item.
Definition EST_Item.h:316
const EST_String & relation_name() const
The relation name of this particular item.
Definition EST_Item.cc:199
EST_Item * as_relation(const char *relname) const
View item from another relation (const char *) method.
Definition EST_Item.h:302
EST_Features f
const val_type type(void) const
Definition EST_Val.h:126