~ubuntu-branches/ubuntu/warty/speech-tools/warty

« back to all changes in this revision

Viewing changes to grammar/wfst/wfst_ops.cc

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Urlichs
  • Date: 2004-04-29 08:07:31 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040429080731-i18e2g1tv8pala5l
Tags: 1:1.2.3-7
* set SHARED=2 in config.in
  - required to build a shared Festival library

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
/*   union, composition                                                  */
39
39
/*                                                                       */
40
40
/*=======================================================================*/
41
 
#include <iostream.h>
 
41
#include <iostream>
42
42
#include <stdlib.h>
43
43
#include "EST_WFST.h"
44
44
#include "wfst_aux.h"
 
45
#include "EST_String.h"
 
46
#include "EST_TList.h"
 
47
#include "EST_TKVL.h"
 
48
#include "EST_THash.h"
45
49
 
46
50
Declare_TList_T(EST_WFST_MultiState *,EST_WFST_MultiStateP)
47
51
 
116
120
    append(i);
117
121
}
118
122
 
119
 
// Current indexing a multistate to a single number is done with
120
 
// a StringTrie index.  It'll probably be worth optimising this
121
 
// later.
122
 
 
123
 
// Will remove this later
124
 
typedef struct {
125
 
    int name;
126
 
} EST_WFST_MSindex;
127
 
 
128
 
static void pi_delete(void *n)
129
 
{
130
 
    EST_WFST_MSindex *t = (EST_WFST_MSindex *)n;
131
 
    delete t;
132
 
}
133
 
 
134
123
int multistate_index(EST_WFST_MultiStateIndex &index,
135
124
                     EST_WFST_MultiState *ms,int proposed) 
136
125
{
140
129
    // I'll have to make this more efficient in future.
141
130
    EST_String istring("");
142
131
    EST_Litem *p;
 
132
    int ns,found;
143
133
 
144
134
    for (p=ms->head(); p != 0; p = next(p))
145
135
        istring += itoString((*ms)(p)) + " ";
146
136
 
147
 
    EST_WFST_MSindex *msi;
148
 
 
149
 
    if ((msi = (EST_WFST_MSindex *)index.lookup(istring)) == 0)
 
137
    ns = index.val(istring,found);
 
138
    if (found)
 
139
        return ns;
 
140
    else
150
141
    {
151
 
        EST_WFST_MSindex *nr = new EST_WFST_MSindex;
152
 
        nr->name = proposed;
153
 
        index.add(istring,(void *)nr);
154
 
        msi = nr;
155
 
    }
156
 
 
157
 
    return msi->name;
 
142
        index.add_item(istring,proposed);
 
143
        return proposed;
 
144
    }
 
145
}
 
146
 
 
147
static int pair_check(EST_THash<int,int> &pairs_done, int i, int o, int odim)
 
148
{
 
149
    int p;
 
150
    int found;
 
151
 
 
152
    p = (i*odim)+o;  // unique number representing i/o pair
 
153
 
 
154
    pairs_done.val(p,found);
 
155
    if (!found)
 
156
    {   // first time seeing this pair
 
157
        pairs_done.add_item(p,1);
 
158
        return 0;
 
159
    }
 
160
    return 1;
 
161
 
158
162
}
159
163
 
160
164
void EST_WFST::determinize(const EST_WFST &ndwfst)
163
167
    EST_WFST_MultiState *start_state,*nms,*current;
164
168
    int ns;
165
169
    Agenda multistate_agenda;
166
 
    EST_WFST_MultiStateIndex index;
 
170
    EST_WFST_MultiStateIndex index(100);
167
171
    int i,o, new_name;
168
172
    int c=0;
 
173
    EST_Litem *sp, *tp;
169
174
 
170
175
    clear();
171
176
    p_in_symbols.copy(ndwfst.p_in_symbols);
183
188
 
184
189
    while (multistate_agenda.length() > 0)
185
190
    {
 
191
        EST_THash<int,int> pairs_done(100);
186
192
        current = multistate_agenda.first();
187
193
        multistate_agenda.remove(multistate_agenda.head());
188
194
        if ((c % 100) == 99)
190
196
                << multistate_agenda.length() << endl;
191
197
        c++;
192
198
 
193
 
        for (i=0; i < p_in_symbols.length(); i++)
194
 
        {   // start at 2 to skip any and epsilon characters -- hmm bad
195
 
            for (o=0; o < p_out_symbols.length(); o++)
 
199
        for (sp=current->head(); sp != 0; sp=next(sp))
 
200
        {
 
201
            const EST_WFST_State *s = ndwfst.state((*current)(sp));
 
202
            for (tp=s->transitions.head(); tp != 0; tp = next(tp))
196
203
            {
 
204
                i = s->transitions(tp)->in_symbol();
 
205
                o = s->transitions(tp)->out_symbol();
 
206
                // Need to check if i/o has already been proposed
 
207
                if (pair_check(pairs_done,i,o,p_out_symbols.length()) == 1)
 
208
                    continue;  // already prosed those
 
209
//      for (i=0; i < p_in_symbols.length(); i++)
 
210
//      {   // start at 2 to skip any and epsilon characters -- hmm bad
 
211
//          for (o=0; o < p_out_symbols.length(); o++)
 
212
//          {
197
213
                if ((i==o) && (i==0)) 
198
214
                    continue;  // don't deal here with epsilon transitions
199
215
                nms = apply_multistate(ndwfst,current,i,o);
229
245
        // Probably want some progress summary
230
246
    }
231
247
 
232
 
    index.clear(pi_delete);
233
248
}
234
249
 
235
250
EST_WFST_MultiState *EST_WFST::apply_multistate(const EST_WFST &wfst,
325
340
            {
326
341
                // Add to end of ii if not already there
327
342
                int nstate = s->transitions(i)->state();
328
 
                if (!is_a_member(ii,nstate))
 
343
                if (!is_a_member(ii,nstate));
329
344
                {
330
345
                    ii.append(nstate);
331
346
                    ms->add(nstate); // gets added in order
345
360
    EST_WFST_MultiState *nms,*current;
346
361
    int ns;
347
362
    Agenda multistate_agenda;
348
 
    EST_WFST_MultiStateIndex index;
 
363
    EST_WFST_MultiStateIndex index(100);
349
364
    int i,o, new_name, n;
350
365
    EST_Litem *p,*q;
351
366
    int c=0;
424
439
        // Probably want some progress summary
425
440
    }
426
441
 
427
 
    index.clear(pi_delete);
428
442
}
429
443
 
430
444
static enum wfst_state_type intersect_state_type(wfst_list &wl,
800
814
    EST_WFST_MultiState *start_state = new EST_WFST_MultiState(wfst_ms_list);
801
815
    EST_WFST_MultiState *nms,*current;
802
816
    Agenda multistate_agenda;
803
 
    EST_WFST_MultiStateIndex index;
 
817
    EST_WFST_MultiStateIndex index(100);
804
818
    wfst_list wl;
805
819
    EST_WFST t;
806
820
    int i,new_name;
876
890
        // Probably want some progress summary
877
891
    }
878
892
 
879
 
    index.clear(pi_delete);
880
893
}
881
894
 
882
895
/***********************************************************************/