1
/*************************************************************************/
3
/* Centre for Speech Technology Research */
4
/* (University of Edinburgh, UK) and */
6
/* Copyright (c) 2003 */
7
/* All Rights Reserved. */
9
/* Permission is hereby granted, free of charge, to use and distribute */
10
/* this software and its documentation without restriction, including */
11
/* without limitation the rights to use, copy, modify, merge, publish, */
12
/* distribute, sublicense, and/or sell copies of this work, and to */
13
/* permit persons to whom this work is furnished to do so, subject to */
14
/* the following conditions: */
16
/* 1. The code must retain the above copyright notice, this list of */
17
/* conditions and the following disclaimer. */
18
/* 2. Any modifications must be clearly marked as such. */
19
/* 3. Original authors' names are not deleted. */
20
/* 4. The authors' names are not used to endorse or promote products */
21
/* derived from this software without specific prior written */
24
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
25
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
26
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT */
27
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
28
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
29
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
30
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
31
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
34
/*************************************************************************/
35
/* Author : Korin Richmond */
36
/* Date : 15 May 2003 */
37
/* --------------------------------------------------------------------- */
39
/* Swig Python type maps for EST_Features class */
40
/* (converts to/from Python Dictionary object) */
42
/*************************************************************************/
45
static PyObject* features_to_PyDict( EST_Features *features ){
47
EST_Features::RwEntries p;
48
PyObject *result = PyDict_New();
50
for( p.begin(*features); p != 0; ++p ){
51
const EST_Val &v = p->v;
54
if(v.type() == val_unset)
57
else if( v.type() == val_int )
58
py_val = PyInt_FromLong( v.Int() );
60
else if( v.type() == val_float )
61
py_val = PyFloat_FromDouble( v.Float() );
63
else if( v.type() == val_type_feats )
64
py_val = features_to_PyDict( feats(v) );
66
// else if( v.type() == val_type_featfunc ){
68
// EST_Val tempval = ((featfunc)(*v))(##SHOULD BE AN ITEM##);
69
// if( tempval.type() == val_int )
70
// py_val = PyInt_FromLong( tempval.Int() );
72
// else if( tempval.type() == val_float )
73
// py_val = PyFloat_FromDouble( tempval.Float() );
76
// py_val = PyString_FromString( tempval.string() );
79
// py_val = PyString_FromString( v.string() );
83
EST_String s( v.string() );
84
if ( s.length() == 0 )
85
py_val = Py_BuildValue((char*)"");
87
py_val = PyString_FromStringAndSize( s.str(), s.length() );
90
PyDict_SetItemString( result, (char*)(p->k), py_val );
97
static PyObject* item_features_to_PyDict( EST_Item *item, bool evaluate_ff ){
99
EST_Features::RwEntries p;
100
PyObject *result = PyDict_New();
102
for( p.begin(item->features()); p != 0; ++p ){
103
const EST_Val &v = p->v;
106
if(v.type() == val_unset)
109
else if( v.type() == val_int )
110
py_val = PyInt_FromLong( v.Int() );
112
else if( v.type() == val_float )
113
py_val = PyFloat_FromDouble( v.Float() );
115
else if( v.type() == val_type_feats )
116
py_val = features_to_PyDict( feats(v) );
118
else if( (v.type() == val_type_featfunc) && evaluate_ff ){
119
EST_Val tempval = ((featfunc)(v))(item);
120
if( tempval.type() == val_int )
121
py_val = PyInt_FromLong( tempval.Int() );
123
else if( tempval.type() == val_float )
124
py_val = PyFloat_FromDouble( tempval.Float() );
127
EST_String s( tempval.string() );
128
if ( s.length() == 0 )
129
py_val = Py_BuildValue((char*)"");
131
py_val = PyString_FromStringAndSize( s.str(), s.length() );
135
EST_String s( v.string() );
136
if ( s.length() == 0 )
137
py_val = Py_BuildValue((char*)"");
139
py_val = PyString_FromStringAndSize( s.str(), s.length() );
142
PyDict_SetItemString( result, (char*)(p->k), py_val );
148
%typemap(out) EST_Features &
149
"$result = features_to_PyDict( $1 );";
151
// #ifndef HAVEITEMFEATURESFUNCTION
152
// #define HAVEITEMFEATURESFUNCTION
156
// } FUNCTIONARGS_ITEMFEATURES;
158
// %typemap(out) FUNCTION {
159
// $result = item_features_to_PyDict( arg1, arg2 );