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   :  14 Apr 2003                           */
37 /* --------------------------------------------------------------------- */
38 /*                                                                       */
39 /* Swig interface for EST_Item                                           */
40 /*                                                                       */
41 /*************************************************************************/
42 
43 %module EST_Item
44 
45 %{
46 #include "ling_class/EST_Item.h"
47 #include "ling_class/EST_item_aux.h"
48 %}
49 
50 %include "EST_Features.i"
51 %include "EST_typemaps.i"
52 %include "EST_error.i"
53 
54 class EST_Item
55 {
56 private:
57   EST_Item_Content *p_contents;
58   EST_Relation *p_relation;
59   EST_Item *n;
60   EST_Item *p;
61   EST_Item *u;
62   EST_Item *d;
63 
64   void unref_contents();
65   void ref_contents();
66   void copy(const EST_Item &s);
67 
68 public:
69   // Default constructor
70   EST_Item();
71   // Copy constructor only makes reference to contents
72   EST_Item(const EST_Item &item);
73   // Includes reference to relation
74   EST_Item(EST_Relation *rel);
75   // Most common form of construction
76   EST_Item(EST_Relation *rel, EST_Item *si);
77   // Deletes it and references to it in its contents
78   ~EST_Item();
79 
80   //////////////////////////////////////////////////////////////
81   //
82   %exception { CATCH_EST_ERROR }
83 
84   // return the value of the feature "name" cast as a float
85   const float F(const EST_String &name) const;
86 
87   // return the value of the feature name cast as a EST_String
88   const EST_String S(const EST_String &name) const;
89 
90   // return the value of the feature name cast as a int
91   const int I(const EST_String &name) const;
92 
93   // return the value of the feature name cast as an EST_Features
94   EST_Features &A(const EST_String &name) const;
95 
96   // set feature "name" to some value */
97   // (note these functions implicitly assume the compiler will
98   //  create a temporary EST_String from the "name" argument
99   //  when calling the respective C++ functions - it's done like
100   //  that because of a conflict between SWIG typemap conversions
101   //  and handling of overloaded functions)
102   void set(const char *name, int ival);
103   void set(const char *name, double fval);
104   void set(const char *name, const char *cval);
105   void set(const char *name, EST_Features &f);
106 
107   // set feature "name" to "val", a registered feature function
108   void set_function(EST_String &name, EST_String &funcname);
109 
110   // remove feature "name"
111   void f_remove(const EST_String &name);
112 
113   %exception;
114   //
115   //////////////////////////////////////////////////////////////
116 
117 
118   // find all the attributes whose values are functions, and
119   // replace them with their evaluation.
120   void evaluate_features();
121 
122   // TRUE if feature is present, FALSE otherwise */
123   int f_present(const EST_String &name) const;
124 
125   // Number of items (including this) until no next item.
126   int length() const;
127 
128   //const EST_Val f(const EST_String &name) const;
129   //const EST_Val f(const EST_String &name, const EST_Val &def) const;
130 
131   // View item from another relation
132   EST_Item *as_relation(const char *relname) const;
133 
134   // TRUE if this item is in named relation
135   int in_relation(const EST_String &relname) const;
136 
137   // The relation name of this particular item
138   const EST_String &relation_name() const;
139 
140   // The relation of this particular item
141   EST_Relation *relation(void) const;
142 
143   // True if "li" is the same item ignoring its relation viewpoint
144   int same_item(const EST_Item *li) const;
145 
146   //EST_Item *up() const;
147 
148   // Delete this item and all its occurences in other relations
149   void unref_all();
150 
151   %extend {
prepend_daughter(EST_Item * p)152     EST_Item *prepend_daughter( EST_Item *p ){
153       return prepend_daughter( self, p );
154     }
155 
append_daughter(EST_Item * p)156     EST_Item *append_daughter( EST_Item *p ){
157       return append_daughter( self, p );
158     }
159 
daughter1()160     EST_Item* daughter1(){
161       return daughter1( self );
162     }
163 
daughtern()164     EST_Item* daughtern() {
165       return daughtern( self );
166     }
167 
next_sibling()168     EST_Item* next_sibling(){
169       return next_sibling( self );
170     }
171 
prev_sibling()172     EST_Item* prev_sibling(){
173       return prev_sibling( self );
174     }
175 
parent()176     EST_Item* parent(){
177       return parent( self );
178     }
179   }
180 
181   ///////////////////////////////////////////////////////////////////////////////
182   // warning: entirely obfuscated macro magic and abuse ahead
183   //                                        - turn back now to preserve sanity...
184 
185   EST_Features &features();
186 
187 // #ifdef HAVEITEMFEATURESFUNCTION
188 //   %apply (bool FEATURESOUTEVAL) { (bool b) };
189 
190 //   %extend {
191 //     void features( bool b ){
192 //       //dummy function
193 //     }
194 //   }
195 
196 //   %clear ( bool b);
197 // #endif //HAVEITEMFEATURESFUNCTION
198 
199 #ifdef HAVEITEMLEAFLISTOUT
200   %extend {
201     %newobject leafs;
leafs(EST_Item ** ITEMLEAFLISTOUT)202     void leafs( EST_Item **ITEMLEAFLISTOUT ){
203       *ITEMLEAFLISTOUT = self;
204     }
205   }
206 #endif //HAVEITEMLEAFLISTOUT
207 
208 #ifdef HAVEITEMDAUGHTERLISTOUT
209   %extend {
210     %newobject daughters;
daughters(EST_Item ** ITEMDAUGHTERLISTOUT)211     void daughters( EST_Item **ITEMDAUGHTERLISTOUT ){
212       *ITEMDAUGHTERLISTOUT = self;
213     }
214   }
215 #endif
216 };
217 
218 
219 //inline EST_Item *as(const EST_Item *n,const char *relname); //as is now keyword in python
220 inline EST_Item *next_item(const EST_Item *node);
221 inline EST_Item *first_leaf(const EST_Item *n);
222 inline EST_Item *last_leaf(const EST_Item *n);
223 inline EST_Item *next_leaf(const EST_Item *n);
224 int num_leaves(const EST_Item *n);
225 void remove_item(EST_Item *l, const char *relname);
226 void copy_node_tree(EST_Item *from, EST_Item *to);
227 void copy_node_tree_contents(EST_Item *from, EST_Item *to);
228 
229 //Rob's function for jumping around HRG structures more easily
230 EST_Item *item_jump(EST_Item *from, const EST_String &to);
231