~ubuntu-branches/ubuntu/maverick/speech-tools/maverick

« back to all changes in this revision

Viewing changes to wrappers/interface/python/EST_Features.i

  • Committer: Bazaar Package Importer
  • Author(s): Kumar Appaiah, Kartik Mistry, Kumar Appaiah
  • Date: 2010-07-17 11:32:04 UTC
  • mfrom: (3.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100717113204-mnse3jo236j107q8
Tags: 1:2.0.95~beta-1
[ Kartik Mistry ]
* debian/control:
  + [Lintian] Added missing ${misc:Depends}
  + Updated Standards-Version to 3.8.4 (no changes needed)
* debian/patches/const_char.diff:
  + Added missing patch header
* Removed unused patch invalid_const_char_conversion_fixes.diff

[ Kumar Appaiah ]
* New upstream release.
* Standards Version is now 3.9.0 (No changes needed)
* Update debian/rules to specify version numbers.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*************************************************************************/
 
2
/*                                                                       */
 
3
/*                Centre for Speech Technology Research                  */
 
4
/*                 (University of Edinburgh, UK) and                     */
 
5
/*                           Korin Richmond                              */
 
6
/*                         Copyright (c) 2003                            */
 
7
/*                         All Rights Reserved.                          */
 
8
/*                                                                       */
 
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:                                            */
 
15
/*                                                                       */
 
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        */
 
22
/*      permission.                                                      */
 
23
/*                                                                       */
 
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       */
 
32
/*  THIS SOFTWARE.                                                       */
 
33
/*                                                                       */
 
34
/*************************************************************************/
 
35
/*                       Author :  Korin Richmond                        */
 
36
/*                       Date   :  15 May 2003                           */
 
37
/* --------------------------------------------------------------------- */
 
38
/*                                                                       */
 
39
/* Swig Python type maps for EST_Features class                          */
 
40
/* (converts to/from Python Dictionary object)                           */
 
41
/*                                                                       */
 
42
/*************************************************************************/
 
43
 
 
44
%{
 
45
  static PyObject* features_to_PyDict( EST_Features *features ){
 
46
    
 
47
    EST_Features::RwEntries p;
 
48
    PyObject *result = PyDict_New();
 
49
    
 
50
    for( p.begin(*features); p != 0; ++p ){
 
51
      const EST_Val &v = p->v;
 
52
      
 
53
      PyObject *py_val;
 
54
      if(v.type() == val_unset)
 
55
        py_val = Py_None;
 
56
 
 
57
      else if( v.type() == val_int )
 
58
        py_val = PyInt_FromLong( v.Int() );
 
59
 
 
60
      else if( v.type() == val_float )
 
61
        py_val = PyFloat_FromDouble( v.Float() );
 
62
 
 
63
      else if( v.type() == val_type_feats )
 
64
        py_val = features_to_PyDict( feats(v) );
 
65
 
 
66
//       else if( v.type() == val_type_featfunc ){
 
67
//      if( evaluate_ff ){
 
68
//        EST_Val tempval = ((featfunc)(*v))(##SHOULD BE AN ITEM##);
 
69
//        if( tempval.type() == val_int )
 
70
//          py_val = PyInt_FromLong( tempval.Int() );
 
71
          
 
72
//        else if( tempval.type() == val_float )
 
73
//          py_val = PyFloat_FromDouble( tempval.Float() );
 
74
          
 
75
//        else
 
76
//          py_val = PyString_FromString( tempval.string() );
 
77
//      }
 
78
//      else
 
79
//        py_val = PyString_FromString( v.string() );
 
80
//       }
 
81
 
 
82
      else{
 
83
        EST_String s( v.string() );
 
84
        if ( s.length() == 0 )
 
85
          py_val = Py_BuildValue((char*)"");
 
86
        else
 
87
          py_val = PyString_FromStringAndSize( s.str(), s.length() );
 
88
      }
 
89
 
 
90
      PyDict_SetItemString( result, (char*)(p->k), py_val );
 
91
    }
 
92
    return result;
 
93
  }
 
94
%}
 
95
 
 
96
%{
 
97
  static PyObject* item_features_to_PyDict( EST_Item *item, bool evaluate_ff ){
 
98
    
 
99
    EST_Features::RwEntries p;
 
100
    PyObject *result = PyDict_New();
 
101
    
 
102
    for( p.begin(item->features()); p != 0; ++p ){
 
103
      const EST_Val &v = p->v;
 
104
      
 
105
      PyObject *py_val;
 
106
      if(v.type() == val_unset)
 
107
        py_val = Py_None;
 
108
 
 
109
      else if( v.type() == val_int )
 
110
        py_val = PyInt_FromLong( v.Int() );
 
111
 
 
112
      else if( v.type() == val_float )
 
113
        py_val = PyFloat_FromDouble( v.Float() );
 
114
 
 
115
      else if( v.type() == val_type_feats )
 
116
        py_val = features_to_PyDict( feats(v) );
 
117
 
 
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() );
 
122
        
 
123
        else if( tempval.type() == val_float )
 
124
          py_val = PyFloat_FromDouble( tempval.Float() );
 
125
        
 
126
        else{
 
127
          EST_String s( tempval.string() );
 
128
          if ( s.length() == 0 )
 
129
            py_val = Py_BuildValue((char*)"");
 
130
          else
 
131
            py_val = PyString_FromStringAndSize( s.str(), s.length() );
 
132
        }
 
133
      }
 
134
      else{
 
135
        EST_String s( v.string() );
 
136
        if ( s.length() == 0 )
 
137
          py_val = Py_BuildValue((char*)"");
 
138
        else
 
139
          py_val = PyString_FromStringAndSize( s.str(), s.length() );
 
140
      }
 
141
      
 
142
      PyDict_SetItemString( result, (char*)(p->k), py_val );
 
143
    }
 
144
    return result;
 
145
  }
 
146
%}
 
147
 
 
148
%typemap(out) EST_Features &
 
149
  "$result = features_to_PyDict( $1 );";
 
150
 
 
151
// #ifndef HAVEITEMFEATURESFUNCTION
 
152
// #define HAVEITEMFEATURESFUNCTION
 
153
// typedef struct {
 
154
//   EST_Item *it;
 
155
//   bool evaluate_ff;
 
156
// } FUNCTIONARGS_ITEMFEATURES;
 
157
 
 
158
// %typemap(out) FUNCTION {
 
159
//   $result = item_features_to_PyDict( arg1, arg2 );
 
160
// }
 
161
// #endif
 
162