Blame view

tools/openfst-1.6.7/src/extensions/python/pywrapfst.pxd 12.9 KB
8dcb6dfcb   Yannick Estève   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
  # See www.openfst.org for extensive documentation on this weighted
  # finite-state transducer library.
  
  
  from libc.time cimport time
  from libc.time cimport time_t
  
  from libcpp cimport bool
  from libcpp.memory cimport shared_ptr
  from libcpp.memory cimport unique_ptr
  from libcpp.utility cimport pair
  from libcpp.vector cimport vector
  
  from libcpp.string cimport string
  from basictypes cimport int32
  from basictypes cimport int64
  from basictypes cimport uint32
  from basictypes cimport uint64
  cimport fst as fst
  from ios cimport stringstream
  
  
  
  # Exportable helper functions.
  
  
  cdef string tostring(data, encoding=?) except *
  
  cdef string weight_tostring(data, encoding=?) except *
  
  cdef fst.ComposeFilter _get_compose_filter(
      const string &compose_filter) except *
  
  cdef fst.DeterminizeType _get_determinize_type(const string &det_type) except *
  
  cdef fst.QueueType _get_queue_type(const string &queue_type) except *
  
  cdef fst.RandArcSelection _get_rand_arc_selection(
      const string &replace_label_type) except *
  
  cdef fst.ReplaceLabelType _get_replace_label_type(
      const string &replace_label_type, bool epsilon_on_replace) except *
  
  
  # Weight.
  
  
  cdef fst.WeightClass _get_WeightClass_or_One(const string &weight_type,
                                               weight_string) except *
  
  cdef fst.WeightClass _get_WeightClass_or_Zero(const string &weight_type,
                                                weight_string) except *
  
  
  cdef class Weight(object):
  
    cdef unique_ptr[fst.WeightClass] _weight
  
    cdef void _check_weight(self) except *
  
    cpdef Weight copy(self)
  
    cpdef string to_string(self)
  
    cpdef string type(self)
  
  
  cdef Weight _Zero(weight_type)
  
  cdef Weight _One(weight_type)
  
  cdef Weight _NoWeight(weight_type)
  
  cdef Weight _plus(Weight lhs, Weight rhs)
  
  cdef Weight _times(Weight lhs, Weight rhs)
  
  cdef Weight _divide(Weight lhs, Weight rhs)
  
  cdef Weight _power(Weight lhs, size_t n)
  
  
  # SymbolTable.
  
  ctypedef fst.SymbolTable * SymbolTable_ptr
  
  
  cdef class _SymbolTable(object):
  
    cdef fst.SymbolTable *_table
  
    cpdef int64 available_key(self)
  
    cpdef string checksum(self)
  
    cpdef SymbolTable copy(self)
  
    cpdef int64 get_nth_key(self, ssize_t pos) except *
  
    cpdef string labeled_checksum(self)
  
    cpdef bool member(self, key)
  
    cpdef string name(self)
  
    cpdef size_t num_symbols(self)
  
    cpdef void write(self, filename) except *
  
    cpdef void write_text(self, filename) except *
  
  
  cdef class _EncodeMapperSymbolTable(_SymbolTable):
  
    cdef shared_ptr[fst.EncodeMapperClass] _encoder
  
  
  cdef class _FstSymbolTable(_SymbolTable):
  
    cdef shared_ptr[fst.FstClass] _fst
  
  
  cdef class _MutableSymbolTable(_SymbolTable):
  
    cpdef int64 add_symbol(self, symbol, int64 key=?)
  
    cpdef void add_table(self, _SymbolTable syms)
  
    cpdef void set_name(self, new_name) except *
  
  
  cdef class _MutableFstSymbolTable(_MutableSymbolTable):
  
    cdef shared_ptr[fst.MutableFstClass] _mfst
  
  
  cdef class SymbolTable(_MutableSymbolTable):
  
    cdef unique_ptr[fst.SymbolTable] _smart_table
  
  
  cdef _EncodeMapperSymbolTable _init_EncodeMapperSymbolTable(
      fst.SymbolTable *table, shared_ptr[fst.EncodeMapperClass] encoder)
  
  
  cdef _FstSymbolTable _init_FstSymbolTable(fst.SymbolTable *table,
                                            shared_ptr[fst.FstClass] ifst)
  
  
  cdef _MutableFstSymbolTable _init_MutableFstSymbolTable(fst.SymbolTable *table,
      shared_ptr[fst.MutableFstClass] ifst)
  
  
  cdef SymbolTable _init_SymbolTable(fst.SymbolTable *table)
  
  
  
  cdef class SymbolTableIterator(object):
  
    cdef shared_ptr[fst.SymbolTable] _table
    cdef unique_ptr[fst.SymbolTableIterator] _siter
  
    cpdef bool done(self)
  
    cpdef void next(self)
  
    cpdef void reset(self)
  
    cpdef string symbol(self)
  
    cpdef int64 value(self)
  
  
  # EncodeMapper.
  
  
  cdef class EncodeMapper(object):
  
    cdef shared_ptr[fst.EncodeMapperClass] _encoder
  
    cpdef string arc_type(self)
  
    cpdef uint32 flags(self)
  
    cpdef _EncodeMapperSymbolTable input_symbols(self)
  
    cpdef _EncodeMapperSymbolTable output_symbols(self)
  
    cpdef uint64 properties(self, uint64 mask)
  
    cpdef void set_input_symbols(self, _SymbolTable syms) except *
  
    cpdef void set_output_symbols(self, _SymbolTable syms) except *
  
    cpdef string weight_type(self)
  
  
  # Fst.
  
  
  ctypedef fst.FstClass * FstClass_ptr
  ctypedef fst.MutableFstClass * MutableFstClass_ptr
  ctypedef fst.VectorFstClass * VectorFstClass_ptr
  
  
  cdef class _Fst(object):
  
    cdef shared_ptr[fst.FstClass] _fst
  
    cpdef string arc_type(self)
  
    cpdef ArcIterator arcs(self, int64 state)
  
    cpdef _Fst copy(self)
  
    cpdef void draw(self, filename, _SymbolTable isymbols=?,
                    _SymbolTable osymbols=?, SymbolTable ssymbols=?,
                    bool acceptor=?, title=?, double width=?,
                    double height=?, bool portrait=?, bool vertical=?,
                    double ranksep=?, double nodesep=?, int32 fontsize=?,
                    int32 precision=?, float_format=?,
                    bool show_weight_one=?)
  
    cpdef Weight final(self, int64 state)
  
    cpdef string fst_type(self)
  
    cpdef _FstSymbolTable input_symbols(self)
  
    cpdef size_t num_arcs(self, int64 state) except *
  
    cpdef size_t num_input_epsilons(self, int64 state) except *
  
    cpdef size_t num_output_epsilons(self, int64 state) except *
  
    cpdef _FstSymbolTable output_symbols(self)
  
    cpdef uint64 properties(self, uint64 mask, bool test)
  
    cpdef int64 start(self)
  
    cpdef StateIterator states(self)
  
    cpdef string text(self, _SymbolTable isymbols=?, _SymbolTable osymbols=?,
                      _SymbolTable ssymbols=?, bool acceptor=?,
                      bool show_weight_one=?, missing_sym=?)
  
    cpdef bool verify(self)
  
    cpdef string weight_type(self)
  
    cpdef void write(self, filename) except *
  
    cpdef string write_to_string(self)
  
  
  cdef class _MutableFst(_Fst):
  
    cdef shared_ptr[fst.MutableFstClass] _mfst
  
    cdef void _check_mutating_imethod(self) except *
  
    cdef void _add_arc(self, int64 state, Arc arc) except *
  
    cpdef int64 add_state(self) except *
  
    cdef void _arcsort(self, sort_type=?) except *
  
    cdef void _closure(self, bool closure_plus=?) except *
  
    cdef void _concat(self, _Fst ifst) except *
  
    cdef void _connect(self) except *
  
    cdef void _decode(self, EncodeMapper) except *
  
    cdef void _delete_arcs(self, int64 state, size_t n=?) except *
  
    cdef void _delete_states(self, states=?) except *
  
    cdef void _encode(self, EncodeMapper) except *
  
    cdef void _invert(self) except *
  
    cdef void _minimize(self, float delta=?, bool allow_nondet=?) except *
  
    cpdef MutableArcIterator mutable_arcs(self, int64 state)
  
    cpdef int64 num_states(self)
  
    cdef void _project(self, bool project_output=?) except *
  
    cdef void _prune(self, float delta=?, int64 nstate=?, weight=?) except *
  
    cdef void _push(self, float delta=?, bool remove_total_weight=?,
                    bool to_final=?) except *
  
    cdef void _relabel_pairs(self, ipairs=?, opairs=?) except *
  
    cdef void _relabel_tables(self, _SymbolTable old_isymbols=?,
        _SymbolTable new_isymbols=?, unknown_isymbol=?,
        bool attach_new_isymbols=?,
        _SymbolTable old_osymbols=?, _SymbolTable new_osymbols=?,
        unknown_osymbol=?, bool attach_new_osymbols=?) except *
  
    cdef void _reserve_arcs(self, int64 state, size_t n) except *
  
    cdef void _reserve_states(self, int64 n) except *
  
    cdef void _reweight(self, potentials, bool to_final=?) except *
  
    cdef void _rmepsilon(self, queue_type=?, bool connect=?, weight=?,
                         int64 nstate=?, float delta=?) except *
  
    cdef void _set_final(self, int64 state, weight=?) except *
  
    cdef void _set_properties(self, uint64 props, uint64 mask)
  
    cdef void _set_start(self, int64 state) except *
  
    cdef void _set_input_symbols(self, _SymbolTable syms) except *
  
    cdef void _set_output_symbols(self, _SymbolTable syms) except *
  
    cdef void _topsort(self) except *
  
    cdef void _union(self, _Fst ifst) except *
  
  
  # Fst construction helpers.
  
  
  cdef _Fst _init_Fst(FstClass_ptr tfst)
  
  cdef _MutableFst _init_MutableFst(MutableFstClass_ptr tfst)
  
  cdef _Fst _init_XFst(FstClass_ptr tfst)
  
  cdef _MutableFst _create_Fst(arc_type=?)
  
  cpdef _Fst _read(filename)
  
  cpdef _Fst _read_from_string(State)
  
  
  # Iterators.
  
  
  cdef class Arc(object):
  
    cdef unique_ptr[fst.ArcClass] _arc
  
    cpdef Arc copy(self)
  
  
  cdef Arc _init_Arc(const fst.ArcClass &arc)
  
  
  cdef class ArcIterator(object):
  
    cdef shared_ptr[fst.FstClass] _fst
    cdef unique_ptr[fst.ArcIteratorClass] _aiter
  
    cpdef bool done(self)
  
    cpdef uint32 flags(self)
  
    cpdef void next(self)
  
    cpdef size_t position(self)
  
    cpdef void reset(self)
  
    cpdef void seek(self, size_t a)
  
    cpdef void set_flags(self, uint32 flags, uint32 mask)
  
    cpdef object value(self)
  
  
  cdef class MutableArcIterator(object):
  
    cdef shared_ptr[fst.MutableFstClass] _mfst
    cdef unique_ptr[fst.MutableArcIteratorClass] _aiter
  
    cpdef bool done(self)
  
    cpdef uint32 flags(self)
  
    cpdef void next(self)
  
    cpdef size_t position(self)
  
    cpdef void reset(self)
  
    cpdef void seek(self, size_t a)
  
    cpdef void set_flags(self, uint32 flags, uint32 mask)
  
    cpdef void set_value(self, Arc arc)
  
    cpdef object value(self)
  
  
  cdef class StateIterator(object):
  
    cdef shared_ptr[fst.FstClass] _fst
    cdef unique_ptr[fst.StateIteratorClass] _siter
  
    cpdef bool done(self)
  
    cpdef void next(self)
  
    cpdef void reset(self)
  
    cpdef int64 value(self)
  
  
  # Constructive operations on Fst.
  
  
  cdef _Fst _map(_Fst ifst, float delta=?, map_type=?, double power=?, weight=?)
  
  cpdef _Fst arcmap(_Fst ifst, float delta=?, map_type=?, double power=?, weight=?)
  
  cpdef _MutableFst compose(_Fst ifst1, _Fst ifst2, compose_filter=?,
                            bool connect=?)
  
  cpdef _Fst convert(_Fst ifst, fst_type=?)
  
  cpdef _MutableFst determinize(_Fst ifst, float delta=?, det_type=?,
                                int64 nstate=?, int64 subsequential_label=?,
                                weight=?, bool increment_subsequential_label=?)
  
  cpdef _MutableFst difference(_Fst ifst1, _Fst ifst2, compose_filter=?,
                               bool connect=?)
  
  cpdef _MutableFst disambiguate(_Fst ifst, float delta=?, int64 nstate=?,
                                 int64 subsequential_label=?, weight=?)
  
  cpdef _MutableFst epsnormalize(_Fst ifst, bool eps_norm_output=?)
  
  cpdef bool equal(_Fst ifst1, _Fst ifst2, float delta=?)
  
  cpdef bool equivalent(_Fst ifst1, _Fst ifst2, float delta=?) except *
  
  cpdef _MutableFst intersect(_Fst ifst1, _Fst ifst2, compose_filter=?,
                              bool connect=?)
  
  cpdef bool isomorphic(_Fst ifst1, _Fst ifst2, float delta=?)
  
  cpdef _MutableFst prune(_Fst ifst, float delta=?, int64 nstate=?,
                          weight=?)
  
  cpdef _MutableFst push(_Fst ifst, float delta=?, bool push_weights=?,
                         bool push_labels=?, bool remove_common_affix=?,
                         bool remove_total_weight=?, bool to_final=?)
  
  cpdef bool randequivalent(_Fst ifst1, _Fst ifst2, int32 npath=?,
                            float delta=?, time_t seed=?, select=?,
                            int32 max_length=?) except *
  
  cpdef _MutableFst randgen(_Fst ifst, int32 npath=?, time_t seed=?,
                            select=?, int32 max_length=?,
                            bool remove_total_weight=?, bool weighted=?)
  
  cdef fst.ReplaceLabelType _get_replace_label_type(string rlt,
      bool epsilon_on_replace) except *
  
  cpdef _MutableFst replace(pairs, call_arc_labeling=?, return_arc_labeling=?,
                            bool epsilon_on_replace=?, int64 return_label=?)
  
  cpdef _MutableFst reverse(_Fst ifst, bool require_superinitial=?)
  
  cdef vector[fst.WeightClass] *_shortestdistance(_Fst ifst, float delta=?,
                                                  int64 nstate=?, queue_type=?,
                                                  bool reverse=?) except *
  
  cpdef _MutableFst shortestpath(_Fst ifst, float delta=?, int32 nshortest=?,
                                 int64 nstate=?, queue_type=?, bool unique=?,
                                 weight=?)
  
  cpdef _Fst statemap(_Fst ifst, map_type)
  
  cpdef _MutableFst synchronize(_Fst ifst)
  
  
  # Compiler.
  
  
  cdef class Compiler(object):
  
    cdef unique_ptr[stringstream] _sstrm
    cdef string _fst_type
    cdef string _arc_type
    cdef const fst.SymbolTable *_isymbols
    cdef const fst.SymbolTable *_osymbols
    cdef const fst.SymbolTable *_ssymbols
    cdef bool _acceptor
    cdef bool _keep_isymbols
    cdef bool _keep_osymbols
    cdef bool _keep_state_numbering
    cdef bool _allow_negative_labels
  
    cpdef _Fst compile(self)
  
    cpdef void write(self, expression)
  
  
  # FarReader.
  
  cdef class FarReader(object):
  
    cdef unique_ptr[fst.FarReaderClass] _reader
  
    cpdef string arc_type(self)
  
    cpdef bool done(self)
  
    cpdef bool error(self)
  
    cpdef string far_type(self)
  
    cpdef bool find(self, key) except *
  
    cpdef _Fst get_fst(self)
  
    cpdef string get_key(self)
  
    cpdef void next(self)
  
    cpdef void reset(self)
  
  
  # FarWriter.
  
  cdef class FarWriter(object):
  
    cdef unique_ptr[fst.FarWriterClass] _writer
  
    cpdef string arc_type(self)
  
    cdef void close(self)
  
    cpdef void add(self, key, _Fst ifst) except *
  
    cpdef bool error(self)
  
    cpdef string far_type(self)