HFST - Helsinki Finite-State Transducer Technology - C++ API  version 3.9.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HfstTransducer.h
Go to the documentation of this file.
1 // Copyright (c) 2016 University of Helsinki
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 3 of the License, or (at your option) any later version.
7 // See the file COPYING included with this distribution for more
8 // information.
9 
10 #ifndef _HFST_TRANSDUCER_H_
11 #define _HFST_TRANSDUCER_H_
12 
13 #if HAVE_CONFIG_H
14 # include <config.h>
15 #endif
16 
17 #include "FormatSpecifiers.h"
18 
19 #include "HfstDataTypes.h"
20 #include "HfstSymbolDefs.h"
22 #include "parsers/LexcCompiler.h"
23 
24 #if HAVE_SFST
26 #endif
27 
28 #if HAVE_OPENFST
31 #endif
32 
33 #if HAVE_FOMA
35 #endif
36 
37 #if HAVE_XFSM
39 #endif
40 
41 /* Include here the header file of the files that take care
42  of the interaction between HFST and your transducer library. */
43 //#if HAVE_MY_TRANSDUCER_LIBRARY
44 //#include "implementations/MyTransducerLibraryTransducer.h"
45 //#endif
46 
48 #include "HfstTokenizer.h"
50 #include "HfstExceptionDefs.h"
51 #include "HfstInputStream.h"
52 #include "HfstOutputStream.h"
53 
54 #include <string>
55 #include <cassert>
56 #include <iostream>
57 #include <vector>
58 #include <map>
59 #include <set>
60 
61 #include "hfstdll.h"
62 
69 namespace hfst
70 {
71  namespace implementations {
72  template <class T> class HfstTransitionGraph;
73  class HfstTropicalTransducerTransitionData;
74  typedef HfstTransitionGraph<HfstTropicalTransducerTransitionData>
76  }
77  class HfstCompiler;
78  class HfstTransducer;
79  namespace xfst {
80  class XfstCompiler;
81  }
82  namespace xeroxRules
83  {
84  class Rule;
85  HfstTransducer bracketedReplace( const Rule &rule, bool optional);
86  }
87 
88  using hfst::implementations::HfstOlTransducer;
89 
90 #if HAVE_SFST
91  using hfst::implementations::SfstTransducer;
92 #endif // #if HAVE_SFST
93 
94 #if HAVE_OPENFST
95  using hfst::implementations::TropicalWeightTransducer;
96  using hfst::implementations::TropicalWeightState;
97  using hfst::implementations::TropicalWeightStateIterator;
98 #if HAVE_OPENFST_LOG
99  using hfst::implementations::LogWeightTransducer;
100 #endif // #if HAVE_OPENFST_LOG
101 #endif // #if HAVE_OPENFST
102 
103 #if HAVE_FOMA
104  using hfst::implementations::FomaTransducer;
105 #endif // #if HAVE_FOMA
106 
107 #if HAVE_XFSM
108  using hfst::implementations::XfsmTransducer;
109 #endif // #if HAVE_XFSM
110 
111  /* Add here the transducer class of your transducer library. */
112  //#if HAVE_MY_TRANSDUCER_LIBRARY
113  // using hfst::implementations::MyTransducerLibraryTransducer;
114  //#endif // #if HAVE_MY_TRANSDUCER_LIBRARY
115 
116  // *** TESTING AND OPTIMIZATION...
117 
118 #if HAVE_XFSM
119  HFSTDLL void initialize_xfsm();
120 
121  class InitializeXfsm
122  {
123  public:
124  HFSTDLL InitializeXfsm();
125  };
126 #endif
127 
128  enum MinimizationAlgorithm { HOPCROFT, BRZOZOWSKI };
129  /* Which minimization algorithm is used.
130  In foma, Hopcroft is always used.
131  In OpenFst and SFST, the default algorithm is Hopcroft. */
132  HFSTDLL void set_minimization_algorithm(MinimizationAlgorithm);
133  HFSTDLL MinimizationAlgorithm get_minimization_algorithm();
134 
135  HFSTDLL void set_encode_weights(bool);
136  HFSTDLL bool get_encode_weights();
137 
138  HFSTDLL void set_minimize_even_if_already_minimal(bool);
139  HFSTDLL bool get_minimize_even_if_already_minimal();
140 
141  HFSTDLL void set_xerox_composition(bool);
142  HFSTDLL bool get_xerox_composition();
143 
144  HFSTDLL void set_flag_is_epsilon_in_composition(bool);
145  HFSTDLL bool get_flag_is_epsilon_in_composition();
146 
147  /* Whether in harmonization the smaller transducer is always harmonized
148  according to the bigger transducer. */
149  HFSTDLL void set_harmonize_smaller(bool);
150  HFSTDLL bool get_harmonize_smaller();
151 
152  /* Whether unknown and identity symbols are used. By default, they are used.
153  These symbols are always reserved for use and included in alphabets
154  of transducers, but code optimization is possible if it is known
155  that they do not appear in transducer transitions. */
156  HFSTDLL void set_unknown_symbols_in_use(bool);
157  HFSTDLL bool get_unknown_symbols_in_use();
158 
159  void set_warning_stream(std::ostream * os);
160  std::ostream * get_warning_stream();
161 
162  // *** ...TESTING AND OPTIMIZATION
163 
164 
254  {
255 
256  // ***** PROTECTED VARIABLES AND INTERFACE *****
257 
258  protected:
259 
260  /* The backend implementation type of the transducer */
261  ImplementationType type;
262 
263  bool anonymous; // currently not used
264  bool is_trie; // currently not used
265  std::string name; /* The name of the transducer */
266  std::map<std::string,std::string> props; // rest of fst metadata
267  /* The union of possible backend implementations. */
268  union TransducerImplementation
269  {
270 #if HAVE_SFST
271  hfst::implementations::Transducer * sfst;
272 #endif
273 #if HAVE_OPENFST
274  hfst::implementations::StdVectorFst * tropical_ofst;
275 #if HAVE_OPENFST_LOG
276  hfst::implementations::LogFst * log_ofst;
277 #endif
278 #endif
279 #if HAVE_FOMA
280  fsm * foma;
281 #endif
282 #if HAVE_XFSM
283  NETptr xfsm;
284 #endif
285 
286  /* Add here your own transducer backend implementation. */
287  //#if HAVE_MY_TRANSDUCER_LIBRARY
288  // hfst::implementations::MyFst * my_transducer_library;
289  //#endif
290 
291  hfst_ol::Transducer * hfst_ol;
292 
293 #if HAVE_OPENFST // is this needed?
294  hfst::implementations::StdVectorFst * internal;
295 #endif
296  };
297 
298  /* The backend implementation */
299  TransducerImplementation implementation;
300 
301  /* Interfaces through which the backend implementations can be accessed */
302 #if HAVE_SFST
303  static hfst::implementations::SfstTransducer sfst_interface;
304 #endif
305 #if HAVE_OPENFST
306  static hfst::implementations::TropicalWeightTransducer
307  tropical_ofst_interface;
308 #if HAVE_OPENFST_LOG
309  static hfst::implementations::LogWeightTransducer log_ofst_interface;
310 #endif
311 #endif
312 #if HAVE_FOMA
313  static hfst::implementations::FomaTransducer foma_interface;
314 #endif
315  static hfst::implementations::HfstOlTransducer hfst_ol_interface;
316 #if HAVE_XFSM
317  static hfst::implementations::XfsmTransducer xfsm_interface;
318 #endif
319 
320  /* Add here the class that takes care of the interaction between
321  HFST and your transducer library. */
322  //#if HAVE_MY_TRANSDUCER_LIBRARY
323  //static hfst::implementations::MyTransducerLibraryTransducer
324  // my_transducer_library_interface;
325  //#endif
326 
327  /* The same as harmonize but does not change \a another but
328  returns a harmonized version of that. If this and \a another
329  have type FOMA_TYPE, NULL is returned. */
330  HfstTransducer * harmonize_(const HfstTransducer &another);
331 
332  HfstTransducer * harmonize_symbol_encodings(const HfstTransducer &another);
333 
334  /* Check if transducer \a another has in its alphabet flag diacritics
335  that are not found in the alphabet of this transducer and insert
336  all missing flag diacritics to \a missing_flags.
337  \a return_on_first_miss defines whether the function returns as soon as
338  a missing flag is found so that only that flag is inserted to
339  \a missing flags. */
340  bool check_for_missing_flags_in(const HfstTransducer &another,
341  StringSet &missing_flags,
342  bool return_on_first_miss) const;
343 
344  /* Disjunct trie transducers efficiently so that the result is also
345  a trie.
346  Currently not implemented, TODO */
347  HfstTransducer &disjunct_as_tries(HfstTransducer &another,
348  ImplementationType type);
349 
350 
351  /* Remove paths where @..._2@ transitions immediately preceede
352  @..._1@ transitions, i.e. transitions resulting from incorrect
353  ordering of flag diacritics. */
354  HfstTransducer &remove_illegal_flag_paths(void);
355 
356 
357  /* For internal use */
358  static HfstTransducer &read_in_att_format
359  (FILE *ifile, ImplementationType type, const std::string &epsilon_symbol);
360 
361  public:
362  /* Whether the conversion requested can be done without losing
363  any information */
364  static bool is_safe_conversion(ImplementationType original,
365  ImplementationType conversion);
366 
367  /* whether HFST is linked to the transducer library
368  needed by implementation type \a type. */
369  HFSTDLL static bool is_implementation_type_available(ImplementationType type);
370 
371  HFSTDLL unsigned int number_of_states() const;
372  HFSTDLL unsigned int number_of_arcs() const;
373 
374  HFSTDLL void twosided_flag_diacritics();
375 
376  protected:
377  /* For internal use: Create a tokenizer that recognizes all symbols
378  that occur in the transducer. */
379  HfstTokenizer create_tokenizer();
380 
381  /* For internal use. Implemented only for SFST_TYPE.
382  Get all symbol pairs that occur in the transitions of the transducer. */
383  StringPairSet get_symbol_pairs();
384 
385  protected:
386 
387  /* Get the number used to represent the symbol \a symbol. */
388  unsigned int get_symbol_number(const std::string &symbol);
389 
390  /* For internal use, implemented only for SFST_TYPE. */
391  std::vector<HfstTransducer*> extract_path_transducers();
392 
393  /* For internal use:
394  Create a new transducer equivalent to \a t in format \a type. */
395  static HfstTransducer &convert
396  (const HfstTransducer &t, ImplementationType type);
397 
398  /* For internal use:
399  Create an HfstBasicTransducer equivalent to \a t end delete
400  the backend implementation of \a t. */
401  implementations::HfstBasicTransducer * convert_to_basic_transducer();
402 
403  /* For internal use:
404  Create an HfstBasicTransducer equivalent to \a t. */
405  implementations::HfstBasicTransducer * get_basic_transducer() const;
406 
407  /* For internal use:
408  Create a backend implementation of the same type that this transducer
409  has and that is equivalent to \a t and delete \a t. Assign the
410  backend implementation as the value of the implementation of this
411  transducer. */
412  HfstTransducer &convert_to_hfst_transducer
414 
415  /* \brief For internal use: Create a transducer of type \a type as
416  defined in AT&T format in file named \a filename.
417  \a epsilon_symbol defines how epsilons are represented.
418 
419  NOTE: If the transition symbols contain space characters
420  they must be represented as "@_SPACE_@" because
421  whitespace characters are used as field separators
422  in AT&T format.
423 
424  @pre The file exists, otherwise an exception is thrown.
425  @see HfstTransducer(FILE, ImplementationType, const std::string&)
426  @throws StreamNotReadableException
427  @throws NotValidAttFormatException
428  */
429  static HfstTransducer &read_in_att_format
430  (const std::string &filename, ImplementationType type,
431  const std::string &epsilon_symbol);
432 
433  public:
434  HFSTDLL static HfstTransducer * prolog_file_to_xfsm_transducer(const char * filename);
435 
436 
437  /* For debugging */
438  public:
439  HFSTDLL void print_alphabet();
440  protected:
441  static float get_profile_seconds(ImplementationType type);
442 
443 #include "hfst_apply_schemas.h"
444 
445 
446 
447  // ***** THE PUBLIC INTERFACE *****
448 
449  public:
450 
451 
452  // ------------------------------------------------
453  // ----- Constructors, destructor, assignment -----
454  // ------------------------------------------------
455 
462  HFSTDLL HfstTransducer();
463 
470  HFSTDLL HfstTransducer(ImplementationType type);
471 
490  HFSTDLL HfstTransducer(const std::string& utf8_str,
491  const HfstTokenizer &multichar_symbol_tokenizer,
492  ImplementationType type);
493 
518  HFSTDLL HfstTransducer(const std::string& input_utf8_str,
519  const std::string& output_utf8_str,
520  const HfstTokenizer &multichar_symbol_tokenizer,
521  ImplementationType type);
522 
523  /* @brief Create a transducer that recognizes the union of string pairs in
524  \a sps. The type of the transducer is defined by \a type. \a cyclic
525  defines whether the transducer recognizes any number (from zero to
526  infinity, inclusive) of consecutive string pairs in \s sps. */
527  HFSTDLL HfstTransducer(const StringPairSet & sps, ImplementationType type,
528  bool cyclic=false);
529 
530  /* \brief Create a transducer that recognizes the concatenation of
531  string pairs in \a spv. The type of the transducer is defined
532  by \a type. */
533  HFSTDLL HfstTransducer(const StringPairVector & spv, ImplementationType type);
534 
535  /* \brief Create a transducer that recognizes the concatenation of the
536  unions of string pairs in string pair sets in \a spsv. The type of
537  the transducer is defined by \a type. */
538  HFSTDLL HfstTransducer(const std::vector<StringPairSet> & spsv,
539  ImplementationType type);
540 
561  HFSTDLL HfstTransducer(HfstInputStream &in);
562 
564  HFSTDLL HfstTransducer(const HfstTransducer &another);
565 
570  ImplementationType type);
571 
576  HFSTDLL HfstTransducer(const std::string &symbol, ImplementationType type);
577 
582  HFSTDLL HfstTransducer(const std::string &isymbol, const std::string &osymbol,
583  ImplementationType type);
584 
658  HFSTDLL HfstTransducer(FILE * ifile, ImplementationType type,
659  const std::string &epsilon_symbol, unsigned int & linecount);
660 
661  HFSTDLL HfstTransducer(FILE * ifile, ImplementationType type,
662  const std::string &epsilon_symbol);
663 
664 
666  HFSTDLL virtual ~HfstTransducer(void);
667 
670  HFSTDLL HfstTransducer &operator=(const HfstTransducer &another);
671 
672  HFSTDLL HfstTransducer &assign(const HfstTransducer &another);
673 
674  // ------------------------------------------------------------
675  // ----------- Properties, comparison, conversion -------------
676  // ------------------------------------------------------------
677 
680  HFSTDLL void set_name(const std::string &name);
681 
684  HFSTDLL std::string get_name() const;
685 
695  HFSTDLL void set_property(const std::string& property, const std::string& value);
696 
701  HFSTDLL std::string get_property(const std::string& property) const;
705  HFSTDLL const std::map<std::string,std::string>& get_properties() const;
710  HFSTDLL StringSet get_alphabet() const;
711 
714  HFSTDLL StringSet get_first_input_symbols() const;
715 
724  HFSTDLL void harmonize(HfstTransducer &another);
725 
731  HFSTDLL void insert_to_alphabet(const std::string &symbol);
732  HFSTDLL void insert_to_alphabet(const std::set<std::string> &symbols);
733 
740  HFSTDLL void remove_from_alphabet(const std::string &symbol);
741  HFSTDLL void remove_from_alphabet(const std::set<std::string> &symbols);
742 
743  // For XFSM format
744  HFSTDLL void remove_symbols_from_alphabet(const StringSet & symbols);
745 
746 
758  HFSTDLL HfstTransducer &prune_alphabet(bool force=true);
759 
761  HFSTDLL bool is_cyclic(void) const;
762 
764  HFSTDLL bool is_automaton(void) const;
765 
767  HFSTDLL ImplementationType get_type(void) const;
768 
775  HFSTDLL bool compare(const HfstTransducer &another, bool harmonize=true) const;
776 
793  HFSTDLL HfstTransducer &convert(ImplementationType type, std::string options="");
794 
795 
796  // --------------------------------------------------------
797  // --- String lookup and conversion to/from AT&T format ---
798  // --------------------------------------------------------
799 
854  HFSTDLL void write_in_att_format(FILE * ofile, bool write_weights=true) const;
855 
856  HFSTDLL void write_in_att_format(char * buffer, bool write_weights=true) const;
857 
858  /* For XFSM_TYPE. */
859  HFSTDLL void write_xfsm_transducer_in_att_format(const char * filename) const;
860  HFSTDLL void write_xfsm_transducer_in_prolog_format(const char * filename) const;
861 
862  /* For other types. */
863  HFSTDLL void write_in_prolog_format(FILE * file, const std::string & name,
864  bool write_weights=true);
865 
866  HFSTDLL void write_in_att_format_number
867  (FILE * ofile, bool write_weights=true) const;
868 
869 
878  HFSTDLL void write_in_att_format(const std::string &filename,
879  bool write_weights=true) const;
880 
881 
882  public:
883  /* \brief Call \a callback with some or all string pairs recognized
884  by the transducer?
885 
886  If the callback returns false the search will be terminated.
887  The \a cycles parameter
888  indicates how many times a cycle will be followed, with negative numbers
889  indicating unlimited. Note that if the transducer is cyclic and
890  cycles aren't capped,
891  the search will not end until the callback returns false. */
892  HFSTDLL void extract_paths(ExtractStringsCb& callback, int cycles=-1) const;
893 
975  HFSTDLL void extract_paths
976  (HfstTwoLevelPaths &results, int max_num=-1, int cycles=-1) const;
977 
978  HFSTDLL void extract_random_paths
979  (HfstTwoLevelPaths &results, int max_num) const;
980 
981  HFSTDLL void extract_random_paths_fd
982  (HfstTwoLevelPaths &results, int max_num, bool filter_fd) const;
983 
984  /* \brief Call \a callback with extracted strings that are not
985  invalidated by flag diacritic rules.
986 
987  @see extract_paths(HfstTwoLevelPaths&, int, int) */
988  HFSTDLL void extract_paths_fd
989  (ExtractStringsCb& callback, int cycles=-1, bool filter_fd=true) const;
990 
991  // todo: handle flag diacritics
992  // todo: throw TransducerIsCyclicException, if cyclic
993  HFSTDLL void extract_shortest_paths
994  (HfstTwoLevelPaths &results) const;
995 
996  HFSTDLL bool extract_longest_paths
997  (HfstTwoLevelPaths &results, bool obey_flags=true /*,bool show_flags=false*/) const;
998 
999  HFSTDLL int longest_path_size(bool obey_flags=true) const;
1000 
1001  public:
1035  HFSTDLL void extract_paths_fd
1036  (HfstTwoLevelPaths &results, int max_num=-1, int cycles=-1,
1037  bool filter_fd=true) const;
1038 
1049  HFSTDLL HfstOneLevelPaths * lookup(const StringVector& s,
1050  ssize_t limit = -1,
1051  double time_cutoff = 0.0) const;
1052 
1058  HFSTDLL HfstOneLevelPaths * lookup(const std::string & s,
1059  ssize_t limit = -1,
1060  double time_cutoff = 0.0) const;
1061 
1092  HFSTDLL HfstOneLevelPaths * lookup_fd(const StringVector& s,
1093  ssize_t limit = -1,
1094  double time_cutoff = 0.0) const;
1095 
1115  HFSTDLL HfstOneLevelPaths * lookup_fd(const std::string& s,
1116  ssize_t limit = -1,
1117  double time_cutoff = 0.0) const;
1118 
1127  HFSTDLL HfstOneLevelPaths * lookup(const HfstTokenizer& tok,
1128  const std::string &s,
1129  ssize_t limit = -1,
1130  double time_cutoff = 0.0) const;
1131 
1140  HFSTDLL HfstOneLevelPaths * lookup_fd(
1141  const HfstTokenizer& tok,
1142  const std::string &s, ssize_t limit = -1,
1143  double time_cutoff = 0.0) const;
1144 
1159  HFSTDLL HfstOneLevelPaths * lookdown(const StringVector& s,
1160  ssize_t limit = -1) const;
1161 
1162  HFSTDLL HfstOneLevelPaths * lookdown(const std::string& s,
1163  ssize_t limit = -1) const;
1164 
1174  ssize_t limit = -1) const;
1175 
1176  HFSTDLL HfstOneLevelPaths * lookdown_fd(const std::string& s,
1177  ssize_t limit = -1) const;
1178 
1186  HFSTDLL bool is_lookup_infinitely_ambiguous(const StringVector & s) const;
1187  HFSTDLL bool is_lookup_infinitely_ambiguous(const std::string & s) const;
1188 
1192  HFSTDLL bool is_lookdown_infinitely_ambiguous(const StringVector& s) const;
1193 
1194  HFSTDLL bool is_infinitely_ambiguous() const ;
1195 
1196 
1197  // -------------------------------------------
1198  // --------- Optimization operations ---------
1199  // -------------------------------------------
1200 
1201  HFSTDLL HfstTransducer &eliminate_flags();
1202  HFSTDLL HfstTransducer &eliminate_flag(const std::string &flag);
1203 
1206  HFSTDLL HfstTransducer &remove_epsilons();
1207 
1209  HFSTDLL HfstTransducer &prune();
1210 
1216  HFSTDLL HfstTransducer &determinize();
1217 
1225  HFSTDLL HfstTransducer &minimize();
1226 
1242  HFSTDLL HfstTransducer &n_best(unsigned int n);
1243 
1244 
1245  // ------------------------------------------------
1246  // ------------- Algebraic operations -------------
1247  // ------------------------------------------------
1248 
1251  HFSTDLL HfstTransducer &repeat_star();
1252 
1255  HFSTDLL HfstTransducer &repeat_plus();
1256 
1258  HFSTDLL HfstTransducer &repeat_n(unsigned int n);
1259 
1262  HFSTDLL HfstTransducer &repeat_n_minus(unsigned int n);
1263 
1266  HFSTDLL HfstTransducer &repeat_n_plus(unsigned int n);
1267 
1270  HFSTDLL HfstTransducer& repeat_n_to_k(unsigned int n, unsigned int k);
1271 
1273  HFSTDLL HfstTransducer &optionalize();
1274 
1277  HFSTDLL HfstTransducer &invert();
1278 
1284  HFSTDLL HfstTransducer &reverse();
1285 
1290  HFSTDLL HfstTransducer &input_project();
1291 
1296  HFSTDLL HfstTransducer &output_project();
1297 
1299  HFSTDLL HfstTransducer &compose(const HfstTransducer &another,
1300  bool harmonize=true);
1301 
1302  HFSTDLL HfstTransducer &merge(const HfstTransducer &another, const std::map<std::string, std::set<std::string> > & list_symbols);
1303 
1304  HFSTDLL HfstTransducer &merge(const HfstTransducer &another, const struct hfst::xre::XreConstructorArguments & args);
1305 
1316  HFSTDLL HfstTransducer &compose_intersect(const HfstTransducerVector &v,
1317  bool invert=false, bool harmonize=true);
1318 
1320  HFSTDLL HfstTransducer &concatenate(const HfstTransducer &another, bool harmonize=true);
1321 
1323  HFSTDLL HfstTransducer &disjunct(const HfstTransducer &another, bool harmonize=true);
1324 
1348  HFSTDLL HfstTransducer &priority_union(const HfstTransducer &another);
1349 
1350 
1354  HFSTDLL HfstTransducer &lenient_composition(const HfstTransducer &another, bool harmonize=true);
1355 
1364  HFSTDLL HfstTransducer &cross_product(const HfstTransducer &another, bool harmonize=true);
1365 
1366 
1367  /*
1368  * \brief Shuffle this transducer with transducer \@ another.
1369  *
1370  * If transducer A accepts string "foo" and transducer B string "bar",
1371  * the transducer that results from shuffling A and B accepts all strings
1372  * [(f|b)(o|a)(o|r)].
1373  *
1374  * @pre Both transducers must be automata, i.e. map strings onto themselves.
1375  *
1376  */
1377  HFSTDLL HfstTransducer &shuffle(const HfstTransducer &another, bool harmonize=true);
1378 
1386  HFSTDLL static HfstTransducer universal_pair ( ImplementationType type );
1387 
1395  HFSTDLL static HfstTransducer identity_pair ( ImplementationType type );
1396 
1397 
1398 
1399 
1400 
1401  /* For HfstCompiler: Optimized disjunction function. */
1402  HFSTDLL HfstTransducer &disjunct(const StringPairVector &spv);
1403 
1405  HFSTDLL HfstTransducer &intersect(const HfstTransducer &another, bool harmonize=true);
1406 
1408  HFSTDLL HfstTransducer &subtract(const HfstTransducer &another, bool harmonize=true);
1409 
1410 
1411  // ------------------------------------------------
1412  // ---------- Insertion and substitution ----------
1413  // ------------------------------------------------
1414 
1425  HFSTDLL HfstTransducer &insert_freely(const StringPair &symbol_pair, bool harmonize=true);
1426 
1442  HFSTDLL HfstTransducer &insert_freely(const HfstTransducer &tr, bool harmonize=true);
1443 
1485  HFSTDLL HfstTransducer &substitute
1486  (bool (*func)(const StringPair &sp, StringPairSet &sps));
1487 
1503  HFSTDLL HfstTransducer &substitute(const std::string &old_symbol,
1504  const std::string &new_symbol,
1505  bool input_side=true,
1506  bool output_side=true);
1507 
1521  HFSTDLL HfstTransducer &substitute(const StringPair &old_symbol_pair,
1522  const StringPair &new_symbol_pair);
1523 
1536  HFSTDLL HfstTransducer &substitute(const StringPair &old_symbol_pair,
1537  const StringPairSet &new_symbol_pair_set);
1538 
1539  HFSTDLL HfstTransducer & substitute_symbol(const std::string &old_symbol, const std::string &new_symbol, bool input_side=true, bool output_side=true);
1540  HFSTDLL HfstTransducer & substitute_symbol_pair(const StringPair &old_symbol_pair, const StringPair &new_symbol_pair);
1541  HFSTDLL HfstTransducer & substitute_symbol_pair_with_set(const StringPair &old_symbol_pair, const hfst::StringPairSet &new_symbol_pair_set);
1542  HFSTDLL HfstTransducer & substitute_symbol_pair_with_transducer(const StringPair &symbol_pair, HfstTransducer &transducer, bool harmonize=true);
1543 
1544 
1554  HFSTDLL HfstTransducer &substitute(const HfstSymbolSubstitutions &substitutions);
1555 
1556  HFSTDLL HfstTransducer &substitute_symbols(const HfstSymbolSubstitutions &substitutions);
1557 
1568  HFSTDLL HfstTransducer &substitute(const HfstSymbolPairSubstitutions &substitutions);
1569 
1570  HFSTDLL HfstTransducer &substitute_symbol_pairs(const HfstSymbolPairSubstitutions &substitutions);
1571 
1588  HFSTDLL HfstTransducer &substitute(const StringPair &symbol_pair,
1589  HfstTransducer &transducer, bool harmonize=true);
1590 
1591  // -----------------------------------------------
1592  // --------------- Weight handling ---------------
1593  // -----------------------------------------------
1594 
1602  HFSTDLL HfstTransducer &set_final_weights(float weight, bool increment=false);
1603 
1626  HFSTDLL HfstTransducer &transform_weights(float (*func)(float));
1627 
1635  HFSTDLL HfstTransducer &push_weights(PushType type);
1636 
1637 
1640  HFSTDLL static HfstTransducer * read_lexc_ptr(const std::string &filename,
1641  ImplementationType type,
1642  bool verbose);
1643 
1644  HFSTDLL static HfstTransducer read_lexc(const std::string &filename,
1645  ImplementationType type,
1646  bool verbose);
1647 
1648  // *** For commandline programs. ***
1649 
1650  /* For each flag diacritic fd that is included in the alphabet of
1651  transducer \a another but not in the alphabet of this transducer,
1652  insert freely a transition fd:fd in this transducer. */
1653  HFSTDLL void insert_freely_missing_flags_from
1654  (const HfstTransducer &another);
1655 
1656  /*
1657  If both \a this and \a another contain flag diacritics, replace flag
1658  diacritic @X.Y.(.Z)@ by @X.Y_1(.Z)@ in \a this and replace it by
1659  @X.Y_2(.Z)@ in \a another.
1660 
1661  If \a insert_renamed_flags is true, then the flags from \a this are
1662  inserted freely in \a another and vice versa after replacing.
1663  */
1664  HFSTDLL void harmonize_flag_diacritics(HfstTransducer &another,
1665  bool insert_renamed_flags=true);
1666 
1667  HFSTDLL void insert_missing_symbols_to_alphabet_from(const HfstTransducer &another, bool only_special_symbols=false);
1668 
1669  HFSTDLL StringSet insert_missing_diacritics_to_alphabet_from(const HfstTransducer &another);
1670 
1671  HFSTDLL static bool is_special_symbol(const std::string & symbol);
1672 
1673  /* Whether the alphabet of transducer \a another includes flag diacritics
1674  that are not included in the alphabet of this transducer. */
1675  HFSTDLL bool check_for_missing_flags_in(const HfstTransducer &another) const;
1676 
1677  /* Return true if \a this has flag diacritics in the alphabet. */
1678  HFSTDLL bool has_flag_diacritics(void) const;
1679 
1680 
1681 
1682  // *** Friends **** //
1683 
1684  HFSTDLL friend std::ostream& operator<<(std::ostream &out, const HfstTransducer &t);
1685  HFSTDLL friend std::ostream& redirect(std::ostream &out, const HfstTransducer &t);
1686  friend class HfstInputStream;
1687  friend class HfstOutputStream;
1688  friend class hfst::implementations::HfstTransitionGraph<class C>;
1689  friend class HfstCompiler;
1690  friend class hfst::implementations::ConversionFunctions;
1691  friend class HfstGrammar;
1692  friend class xfst::XfstCompiler;
1693  //friend HfstTransducer bracketedReplace( const hfst::xeroxRules::Rule &rule, bool optional);
1695  };
1696 
1702  HFSTDLL std::ostream &operator<<(std::ostream &out,const HfstTransducer &t);
1703 
1704  HFSTDLL std::ostream &redirect(std::ostream &out,const HfstTransducer &t);
1705 
1708  namespace rules
1709  {
1710  enum ReplaceType {REPL_UP, REPL_DOWN, REPL_RIGHT, REPL_LEFT,
1711  REPL_DOWN_KARTTUNEN};
1712  enum TwolType {twol_right, twol_left, twol_both};
1713 
1714  /* helping methods */
1715  HFSTDLL HfstTransducer universal_fst
1716  (const StringPairSet &alphabet, ImplementationType type);
1717  HFSTDLL HfstTransducer negation_fst
1718  (const HfstTransducer &t, const StringPairSet &alphabet);
1719 
1720  HFSTDLL HfstTransducer replace
1721  (HfstTransducer &t, ReplaceType repl_type, bool optional,
1722  StringPairSet &alphabet);
1723  HFSTDLL HfstTransducer replace_transducer
1724  (HfstTransducer &t, std::string lm, std::string rm,
1725  ReplaceType repl_type, StringPairSet &alphabet);
1726  HFSTDLL HfstTransducer replace_context
1727  (HfstTransducer &t, std::string m1, std::string m2,
1728  StringPairSet &alphabet);
1729  HFSTDLL HfstTransducer replace_in_context
1730  (HfstTransducerPair &context, ReplaceType repl_type,
1731  HfstTransducer &t, bool optional, StringPairSet &alphabet);
1732 
1733  /* Used by hfst-calculate. */
1734  HFSTDLL HfstTransducer restriction
1735  (HfstTransducerPairVector &contexts, HfstTransducer &mapping,
1736  StringPairSet &alphabet, TwolType twol_type, int direction );
1737 
1738 
1739 
1740  // ***** THE PUBLIC INTERFACE *****
1741 
1770  HFSTDLL HfstTransducer two_level_if(HfstTransducerPair &context,
1771  StringPairSet &mappings,
1772  StringPairSet &alphabet);
1773 
1789  HFSTDLL HfstTransducer two_level_only_if(HfstTransducerPair &context,
1790  StringPairSet &mappings,
1791  StringPairSet &alphabet);
1792 
1807  HFSTDLL HfstTransducer two_level_if_and_only_if(HfstTransducerPair &context,
1808  StringPairSet &mappings,
1809  StringPairSet &alphabet);
1810 
1811 
1862  HFSTDLL HfstTransducer replace_up(HfstTransducerPair &context,
1863  HfstTransducer &mapping,
1864  bool optional,
1865  StringPairSet &alphabet);
1866 
1873  HFSTDLL HfstTransducer replace_down(HfstTransducerPair &context,
1874  HfstTransducer &mapping,
1875  bool optional,
1876  StringPairSet &alphabet);
1877 
1878  HFSTDLL HfstTransducer replace_down_karttunen(HfstTransducerPair &context,
1879  HfstTransducer &mapping,
1880  bool optional,
1881  StringPairSet &alphabet);
1882 
1890  HFSTDLL HfstTransducer replace_right(HfstTransducerPair &context,
1891  HfstTransducer &mapping,
1892  bool optional,
1893  StringPairSet &alphabet);
1894 
1902  HFSTDLL HfstTransducer replace_left(HfstTransducerPair &context,
1903  HfstTransducer &mapping,
1904  bool optional,
1905  StringPairSet &alphabet);
1906 
1907 
1912  HFSTDLL HfstTransducer replace_up(HfstTransducer &mapping,
1913  bool optional,
1914  StringPairSet &alphabet);
1915 
1920  HFSTDLL HfstTransducer replace_down(HfstTransducer &mapping,
1921  bool optional,
1922  StringPairSet &alphabet);
1923 
1932  HFSTDLL HfstTransducer left_replace_up( HfstTransducer &mapping,
1933  bool optional,
1934  StringPairSet &alphabet);
1935 
1942  HFSTDLL HfstTransducer left_replace_up( HfstTransducerPair &context,
1943  HfstTransducer &mapping,
1944  bool optional,
1945  StringPairSet &alphabet);
1950  HFSTDLL HfstTransducer left_replace_down(HfstTransducerPair &context,
1951  HfstTransducer &mapping,
1952  bool optional,
1953  StringPairSet &alphabet);
1954 
1959  HFSTDLL HfstTransducer left_replace_down_karttunen( HfstTransducerPair &context,
1960  HfstTransducer &mapping,
1961  bool optional,
1962  StringPairSet &alphabet);
1963 
1969  HFSTDLL HfstTransducer left_replace_left(HfstTransducerPair &context,
1970  HfstTransducer &mapping,
1971  bool optional,
1972  StringPairSet &alphabet);
1973 
1979  HFSTDLL HfstTransducer left_replace_right(HfstTransducerPair &context,
1980  HfstTransducer &mapping,
1981  bool optional,
1982  StringPairSet &alphabet);
1983 
1984 
1985 
1986 
1987 
1999  HFSTDLL HfstTransducer restriction(HfstTransducerPairVector &contexts,
2000  HfstTransducer &mapping,
2001  StringPairSet &alphabet);
2002 
2012  HFSTDLL HfstTransducer coercion(HfstTransducerPairVector &contexts,
2013  HfstTransducer &mapping,
2014  StringPairSet &alphabet);
2015 
2028  HFSTDLL HfstTransducer restriction_and_coercion(HfstTransducerPairVector &contexts,
2029  HfstTransducer &mapping,
2030  StringPairSet &alphabet);
2031 
2044  HFSTDLL HfstTransducer surface_restriction(HfstTransducerPairVector &contexts,
2045  HfstTransducer &mapping,
2046  StringPairSet &alphabet);
2047 
2060  HFSTDLL HfstTransducer surface_coercion(HfstTransducerPairVector &contexts,
2061  HfstTransducer &mapping,
2062  StringPairSet &alphabet);
2063 
2070  HFSTDLL HfstTransducer surface_restriction_and_coercion
2071  (HfstTransducerPairVector &contexts,
2072  HfstTransducer &mapping,
2073  StringPairSet &alphabet);
2074 
2086  HFSTDLL HfstTransducer deep_restriction(HfstTransducerPairVector &contexts,
2087  HfstTransducer &mapping,
2088  StringPairSet &alphabet);
2089 
2101  HFSTDLL HfstTransducer deep_coercion(HfstTransducerPairVector &contexts,
2102  HfstTransducer &mapping,
2103  StringPairSet &alphabet);
2104 
2111  HFSTDLL HfstTransducer deep_restriction_and_coercion
2112  (HfstTransducerPairVector &contexts,
2113  HfstTransducer &mapping,
2114  StringPairSet &alphabet);
2115  }
2116 
2117 }
2118 
2119 
2120 // vim: set ft=cpp.doxygen:
2121 #endif // #ifndef _HFST_TRANSDUCER_H_
HFSTDLL HfstOneLevelPaths * lookdown(const StringVector &s, ssize_t limit=-1) const
(Not implemented) Lookdown a single string s and return a maximum of limit results.
Definition: HfstTransducer.cc:737
HFSTDLL ImplementationType get_type(void) const
The implementation type of the transducer.
Definition: HfstTransducer.cc:1473
HFSTDLL HfstTransducer & prune()
Make transducer coaccessible.
Definition: HfstTransducer.cc:2090
Declaration of class HfstInputStream.
HFSTDLL bool is_lookdown_infinitely_ambiguous(const StringVector &s) const
(Not implemented) Whether lookdown of path s will have infinite results.
Definition: HfstTransducer.cc:795
HfstTransducer coercion(HfstTransducerPairVector &contexts, HfstTransducer &mapping, StringPairSet &alphabet)
A transducer that requires that one of the mappings defined by mapping must occur in each context in ...
Definition: HfstRules.cc:672
Declaration of class hfst::HfstTokenizer.
Class HfstTransitionGraph.
HFSTDLL HfstTransducer & priority_union(const HfstTransducer &another)
Make priority union of this transducer with another.
Definition: HfstTransducer.cc:4573
HfstTransducer surface_restriction_and_coercion(HfstTransducerPairVector &contexts, HfstTransducer &mapping, StringPairSet &alphabet)
A transducer that is equivalent to the intersection of surface_restriction and surface_coercion.
Definition: HfstRules.cc:698
HFSTDLL HfstTransducer & repeat_n_to_k(unsigned int n, unsigned int k)
A concatenation of N transducers where N is any number from n to k, inclusive.
Definition: HfstTransducer.cc:2259
HFSTDLL HfstTransducer()
Create an uninitialized transducer (use with care).
Definition: HfstTransducer.cc:823
std::pair< String, String > StringPair
A symbol pair in a transition.
Definition: HfstSymbolDefs.h:70
HFSTDLL HfstTransducer & intersect(const HfstTransducer &another, bool harmonize=true)
Intersect this transducer with another.
Definition: HfstTransducer.cc:4890
HFSTDLL HfstTransducer & prune_alphabet(bool force=true)
Remove all symbols that do not occur in transitions of the transducer from its alphabet.
Definition: HfstTransducer.cc:304
HfstTransducer deep_restriction(HfstTransducerPairVector &contexts, HfstTransducer &mapping, StringPairSet &alphabet)
A transducer that specifies that a string from the output language of the transducer mapping may only...
Definition: HfstRules.cc:705
HfstTransducer two_level_if_and_only_if(HfstTransducerPair &context, StringPairSet &mappings, StringPairSet &alphabet)
A transducer that always performs the mappings defined by mappings in the context context and only in...
Definition: HfstRules.cc:258
HFSTDLL HfstOneLevelPaths * lookdown_fd(StringVector &s, ssize_t limit=-1) const
(Not implemented) Lookdown a single string minding flag diacritics properly.
Definition: HfstTransducer.cc:744
HFSTDLL HfstTransducer & subtract(const HfstTransducer &another, bool harmonize=true)
Subtract transducer another from this transducer.
Definition: HfstTransducer.cc:4912
HFSTDLL HfstTransducer & remove_epsilons()
Remove all epsilon:epsilon transitions from the transducer so that the transducer remains equivalent...
Definition: HfstTransducer.cc:2066
A compiled transducer format, suitable for fast lookup operations.
Definition: transducer.h:833
HFSTDLL void harmonize(HfstTransducer &another)
Harmonize transducers this and another.
Definition: HfstTransducer.cc:548
HFSTDLL std::string get_property(const std::string &property) const
Get arbitrary string propert property. get_property("name") works like get_name.
Definition: HfstTransducer.cc:1492
std::vector< std::pair< std::string, std::string > > StringPairVector
A vector of string pairs.
Definition: HfstDataTypes.h:105
HFSTDLL HfstTransducer & push_weights(PushType type)
Push weights towards initial or final state(s) as defined by type.
Definition: HfstTransducer.cc:3811
static HFSTDLL HfstTransducer * read_lexc_ptr(const std::string &filename, ImplementationType type, bool verbose)
Compile a lexc file in file filename into an HfstTransducer of type type and return the transducer...
Definition: HfstTransducer.cc:5767
HFSTDLL HfstTransducer & repeat_n_minus(unsigned int n)
A concatenation of N transducers where N is any number from zero to n, inclusive. ...
Definition: HfstTransducer.cc:2238
HfstTransducer left_replace_down(HfstTransducerPair &context, HfstTransducer &mapping, bool optional, StringPairSet &alphabet)
Inversion of the replace_up and the result needs to be composed on the upper side of the input langua...
Definition: HfstRules.cc:504
A synchronous finite-state transducer.
Definition: HfstTransducer.h:253
HFSTDLL HfstTransducer & repeat_n_plus(unsigned int n)
A concatenation of N transducers where N is any number from n to infinity, inclusive.
Definition: HfstTransducer.cc:2225
HfstTransducer surface_restriction(HfstTransducerPairVector &contexts, HfstTransducer &mapping, StringPairSet &alphabet)
A transducer that specifies that a string from the input language of the transducer mapping may only ...
Definition: HfstRules.cc:685
HFSTDLL HfstTransducer & output_project()
Extract the output language of the transducer.
Definition: HfstTransducer.cc:2364
HfstTransducer two_level_only_if(HfstTransducerPair &context, StringPairSet &mappings, StringPairSet &alphabet)
A transducer that allows the mappings defined by mappings only in the context context, when the alphabet is alphabet.
Definition: HfstRules.cc:214
HFSTDLL HfstTransducer & cross_product(const HfstTransducer &another, bool harmonize=true)
Make cross product of this transducer with . It pairs every string of this with every string of ...
Definition: HfstTransducer.cc:4340
HFSTDLL bool is_lookup_infinitely_ambiguous(const StringVector &s) const
Whether lookup of path s will have infinite results.
Definition: HfstTransducer.cc:766
HFSTDLL HfstTransducer & input_project()
Extract the input language of the transducer.
Definition: HfstTransducer.cc:2343
HfstTransducer deep_coercion(HfstTransducerPairVector &contexts, HfstTransducer &mapping, StringPairSet &alphabet)
A transducer that specifies that a string from the output language of the transducer mapping always h...
Definition: HfstRules.cc:711
A file for exceptions.
HfstTransducer left_replace_down_karttunen(HfstTransducerPair &context, HfstTransducer &mapping, bool optional, StringPairSet &alphabet)
Inversion of the replace_up and the result needs to be composed on the upper side of the input langua...
Definition: HfstRules.cc:488
HFSTDLL bool is_automaton(void) const
Whether the transducer is an automaton.
Definition: HfstTransducer.cc:1583
ImplementationType
The type of an HfstTransducer.
Definition: HfstDataTypes.h:41
Declarations of functions and datatypes that form a bridge between HFST API and foma.
HfstTransducer replace_left(HfstTransducerPair &context, HfstTransducer &mapping, bool optional, StringPairSet &alphabet)
The same as replace_up, but left context matching is done on the input side of mapping and right cont...
Definition: HfstRules.cc:432
HFSTDLL HfstTransducer & minimize()
Minimize the transducer.
Definition: HfstTransducer.cc:2129
HFSTDLL HfstTransducer & concatenate(const HfstTransducer &another, bool harmonize=true)
Concatenate this transducer with another.
Definition: HfstTransducer.cc:4777
HFSTDLL HfstTransducer & reverse()
Reverse the transducer.
Definition: HfstTransducer.cc:2322
HFSTDLL HfstTransducer & optionalize()
Disjunct the transducer with an epsilon transducer.
Definition: HfstTransducer.cc:2280
A simple transition graph format that consists of states and transitions between those states...
Definition: HfstDataTypes.h:112
PushType
The type of a push operation.
Definition: HfstDataTypes.h:64
HFSTDLL bool compare(const HfstTransducer &another, bool harmonize=true) const
Whether this transducer and another are equivalent.
Definition: HfstTransducer.cc:1515
HfstTransducer left_replace_right(HfstTransducerPair &context, HfstTransducer &mapping, bool optional, StringPairSet &alphabet)
Inversion of the replace_up and the result needs to be composed on the upper side of the input langua...
Definition: HfstRules.cc:536
virtual HFSTDLL ~HfstTransducer(void)
Destructor.
Definition: HfstTransducer.cc:1310
HFSTDLL HfstTransducer & repeat_star()
A concatenation of N transducers where N is any number from zero to infinity.
Definition: HfstTransducer.cc:2159
A stream for writing binary transducers.
Definition: HfstOutputStream.h:70
HFSTDLL HfstTransducer & compose_intersect(const HfstTransducerVector &v, bool invert=false, bool harmonize=true)
Compose this transducer with the intersection of transducers in v. If invert is true, then compose the intersection of the transducers in v with this transducer.
Definition: HfstTransducer.cc:4604
std::vector< HfstTransducer > HfstTransducerVector
a vector of transducers for methods applying a cascade of automata
Definition: HfstDataTypes.h:33
std::set< HfstTwoLevelPath > HfstTwoLevelPaths
A set of two-level weighted paths.
Definition: HfstDataTypes.h:109
HFSTDLL HfstTransducer & invert()
Swap the input and output symbols of each transition in the transducer.
Definition: HfstTransducer.cc:2301
HFSTDLL HfstTransducer & compose(const HfstTransducer &another, bool harmonize=true)
Compose this transducer with another.
Definition: HfstTransducer.cc:3959
HFSTDLL HfstTransducer & insert_freely(const StringPair &symbol_pair, bool harmonize=true)
Freely insert symbol pair symbol_pair into the transducer.
Definition: HfstTransducer.cc:3343
HfstTransducer restriction_and_coercion(HfstTransducerPairVector &contexts, HfstTransducer &mapping, StringPairSet &alphabet)
A transducer that is equivalent to the intersection of restriction and coercion and requires that the...
Definition: HfstRules.cc:678
HFSTDLL HfstTransducer & repeat_n(unsigned int n)
A concatenation of n transducers.
Definition: HfstTransducer.cc:2201
Declarations of functions and datatypes that form a bridge between HFST API and OpenFst's transducers...
HFSTDLL const std::map< std::string, std::string > & get_properties() const
Get all properties form transducer.
Definition: HfstTransducer.cc:1504
Declarations of functions and datatypes that form a bridge between HFST API and OpenFst's transducers...
HfstTransducer left_replace_left(HfstTransducerPair &context, HfstTransducer &mapping, bool optional, StringPairSet &alphabet)
Inversion of the replace_up and the result needs to be composed on the upper side of the input langua...
Definition: HfstRules.cc:520
static HFSTDLL HfstTransducer universal_pair(ImplementationType type)
Create universal pair transducer of type.
Definition: HfstTransducer.cc:5580
HFSTDLL HfstTransducer & set_final_weights(float weight, bool increment=false)
Set the weights of all final states to weight. increment defines whether the old weight is incremente...
Definition: HfstTransducer.cc:3789
Datatypes that are needed when using the HFST API.
HFSTDLL HfstTransducer & determinize()
Determinize the transducer.
Definition: HfstTransducer.cc:2104
HfstTransducer replace_right(HfstTransducerPair &context, HfstTransducer &mapping, bool optional, StringPairSet &alphabet)
The same as replace_up, but left context matching is done on the output side of mapping and right con...
Definition: HfstRules.cc:423
Declaration of classes for HFST's optimized lookup transducer format.
A rule that contains mapping and context and replace type (if any). If rule is A -> B || L _ R ...
Definition: HfstXeroxRules.h:45
HfstTransducer replace_down(HfstTransducerPair &context, HfstTransducer &mapping, bool optional, StringPairSet &alphabet)
The same as replace_up, but matching is done on the output side of mapping.
Definition: HfstRules.cc:405
static HFSTDLL HfstTransducer identity_pair(ImplementationType type)
Create identity pair transducer of type.
Definition: HfstTransducer.cc:5595
A stream for reading HFST binary transducers.
Definition: HfstInputStream.h:97
HFSTDLL HfstTransducer & disjunct(const HfstTransducer &another, bool harmonize=true)
Disjunct this transducer with another.
Definition: HfstTransducer.cc:4867
std::set< StringPair > StringPairSet
A set of symbol pairs used in substituting symbol pairs and in rule functions.
Definition: HfstSymbolDefs.h:82
HFSTDLL StringSet get_first_input_symbols() const
Get first input level symbols of strings recognized (or rejected, if they end in a non-final state) b...
Definition: HfstTransducer.cc:312
HFSTDLL bool is_cyclic(void) const
Whether the transducer is cyclic.
Definition: HfstTransducer.cc:1618
std::set< HfstOneLevelPath > HfstOneLevelPaths
A set of simple paths.
Definition: HfstDataTypes.h:100
std::pair< HfstTransducer, HfstTransducer > HfstTransducerPair
A pair of transducers.
Definition: HfstDataTypes.h:78
HFSTDLL void write_in_att_format(FILE *ofile, bool write_weights=true) const
Write the transducer in AT&T format to FILE ofile. write_weights defines whether weights are written...
Definition: HfstTransducer.cc:5320
Declarations of functions for converting between transducer backend formats.
HFSTDLL void remove_from_alphabet(const std::string &symbol)
Remove symbol from the alphabet of the transducer. CURRENTLY NOT IMPLEMENTED.
Definition: HfstTransducer.cc:269
HFSTDLL HfstTransducer & operator=(const HfstTransducer &another)
Assign this transducer a new value equivalent to transducer another.
Definition: HfstTransducer.cc:5612
Declaration of class HfstOutputStream.
HFSTDLL friend std::ostream & operator<<(std::ostream &out, const HfstTransducer &t)
Write transducer t in AT&T format to ostream out.
Definition: HfstTransducer.cc:5847
HFSTDLL HfstTransducer & substitute(bool(*func)(const StringPair &sp, StringPairSet &sps))
Substitute all transition sp with transitions sps as defined by function func.
Definition: HfstTransducer.cc:3504
std::ostream & operator<<(std::ostream &out, const HfstTransducer &t)
Write transducer t in AT&T format to ostream out.
Definition: HfstTransducer.cc:5847
std::map< String, String > HfstSymbolSubstitutions
A map of substitutions used when performing multiple symbol-to-symbol substitutions.
Definition: HfstSymbolDefs.h:88
std::vector< HfstTransducerPair > HfstTransducerPairVector
A vector of transducer pairs.
Definition: HfstDataTypes.h:82
HfstTransducer two_level_if(HfstTransducerPair &context, StringPairSet &mappings, StringPairSet &alphabet)
A transducer that obligatorily performs the mappings defined by mappings in the context context when ...
Definition: HfstRules.cc:154
HFSTDLL HfstTransducer & n_best(unsigned int n)
Extract n best paths of the transducer.
Definition: HfstTransducer.cc:2780
HFSTDLL HfstTransducer & transform_weights(float(*func)(float))
Transform all transition and state weights as defined in func.
Definition: HfstTransducer.cc:3841
HfstTransducer replace_up(HfstTransducerPair &context, HfstTransducer &mapping, bool optional, StringPairSet &alphabet)
A transducer that performs an upward mapping mapping in the context context when the alphabet is alph...
Definition: HfstRules.cc:397
HFSTDLL HfstOneLevelPaths * lookup_fd(const StringVector &s, ssize_t limit=-1, double time_cutoff=0.0) const
Lookup or apply a single string s minding flag diacritics properly and store a maximum of limit resul...
Definition: HfstTransducer.cc:673
HFSTDLL std::string get_name() const
Get the name of the transducer.
Definition: HfstTransducer.cc:1478
HfstTransitionGraph< HfstTropicalTransducerTransitionData > HfstBasicTransducer
An HfstTransitionGraph with transitions of type HfstTropicalTransducerTransitionData and weight type ...
Definition: HfstDataTypes.h:113
HfstTransducer deep_restriction_and_coercion(HfstTransducerPairVector &contexts, HfstTransducer &mapping, StringPairSet &alphabet)
A transducer that is equivalent to the intersection of deep_restriction and deep_coercion.
Definition: HfstRules.cc:718
HfstTransducer surface_coercion(HfstTransducerPairVector &contexts, HfstTransducer &mapping, StringPairSet &alphabet)
A transducer that specifies that a string from the input language of the transducer mapping always ha...
Definition: HfstRules.cc:691
HfstTransducer left_replace_up(HfstTransducer &mapping, bool optional, StringPairSet &alphabet)
Inversion of the replace_up and the result needs to be composed on the upper side of the input langua...
Definition: HfstRules.cc:456
A tokenizer for creating transducers from UTF-8 strings.
Definition: HfstTokenizer.h:84
HFSTDLL void set_name(const std::string &name)
Rename the transducer name.
Definition: HfstTransducer.cc:1475
HFSTDLL void set_property(const std::string &property, const std::string &value)
Set arbitrary string property property to value. set_property("name") equals set_name(string&).
Definition: HfstTransducer.cc:1482
Declarations of functions and datatypes that form a bridge between HFST API and SFST.
std::map< StringPair, StringPair > HfstSymbolPairSubstitutions
A map of substitutions used when performing multiple symbol pair-to-symbol pair substitutions.
Definition: HfstSymbolDefs.h:94
HFSTDLL HfstOneLevelPaths * lookup(const StringVector &s, ssize_t limit=-1, double time_cutoff=0.0) const
Lookup or apply a single tokenized string s and return a maximum of limit results.
Definition: HfstTransducer.cc:661
Declarations of functions and datatypes that form a bridge between HFST API and xfsm.
Typedefs and functions for symbols, symbol pairs and sets of symbols.
HfstTransducer bracketedReplace(const Rule &rule, bool optional)
Unconditional replace, in multiple contexts first: (.* TT .*) - [( .* L1 TT R1 ...
Definition: HfstXeroxRules.cc:575
std::vector< std::string > StringVector
A vector of strings.
Definition: HfstDataTypes.h:87
HFSTDLL StringSet get_alphabet() const
Get the alphabet of the transducer.
Definition: HfstTransducer.cc:345
HFSTDLL HfstTransducer & lenient_composition(const HfstTransducer &another, bool harmonize=true)
Make lenient composition of this transducer with . A .O. B = [ A .o. B ] .P. A.
Definition: HfstTransducer.cc:4319
HFSTDLL void insert_to_alphabet(const std::string &symbol)
Explicitly insert symbol to the alphabet of the transducer.
Definition: HfstTransducer.cc:216
HFSTDLL HfstTransducer & repeat_plus()
A concatenation of N transducers where N is any number from one to infinity.
Definition: HfstTransducer.cc:2180