HFST - Helsinki Finite-State Transducer Technology API  version 3.7.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HfstTransducer.h
Go to the documentation of this file.
1 // This program is free software: you can redistribute it and/or modify
2 // it under the terms of the GNU General Publirmoc License as published by
3 // the Free Software Foundation, version 3 of the License.
4 //
5 // This program is distributed in the hope that it will be useful,
6 // but WITHOUT ANY WARRANTY; without even the implied warranty of
7 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8 // GNU General Public License for more details.
9 //
10 // You should have received a copy of the GNU General Public License
11 // along with this program. If not, see <http://www.gnu.org/licenses/>.
12 #ifndef _HFST_TRANSDUCER_H_
13 #define _HFST_TRANSDUCER_H_
14 
15 #if HAVE_CONFIG_H
16 # include <config.h>
17 #endif
18 
19 #include "FormatSpecifiers.h"
20 
21 #include "HfstDataTypes.h"
22 #include "HfstSymbolDefs.h"
24 #include "parsers/LexcCompiler.h"
25 
26 #if HAVE_SFST
28 #endif
29 
30 #if HAVE_OPENFST
33 #endif
34 
35 #if HAVE_FOMA
37 #endif
38 
39 /* Include here the header file of the files that take care
40  of the interaction between HFST and your transducer library. */
41 //#if HAVE_MY_TRANSDUCER_LIBRARY
42 //#include "implementations/MyTransducerLibraryTransducer.h"
43 //#endif
44 
46 #include "HfstTokenizer.h"
48 #include "HfstExceptionDefs.h"
49 #include "HfstInputStream.h"
50 #include "HfstOutputStream.h"
51 
52 #include <string>
53 #include <cassert>
54 #include <iostream>
55 #include <vector>
56 #include <map>
57 #include <set>
58 
65 namespace hfst
66 {
67  namespace implementations {
68  template <class T> class HfstTransitionGraph;
69  class HfstTropicalTransducerTransitionData;
70  typedef HfstTransitionGraph<HfstTropicalTransducerTransitionData>
72  }
73  class HfstCompiler;
74  class HfstTransducer;
75  namespace xfst {
76  class XfstCompiler;
77  }
78  namespace xeroxRules
79  {
80  class Rule;
81  HfstTransducer bracketedReplace( const Rule &rule, bool optional);
82  }
83 
84  using hfst::implementations::HfstOlTransducer;
85 
86 #if HAVE_SFST
87  using hfst::implementations::SfstTransducer;
88 #endif // #if HAVE_SFST
89 
90 #if HAVE_OPENFST
91  using hfst::implementations::TropicalWeightTransducer;
92  using hfst::implementations::TropicalWeightState;
93  using hfst::implementations::TropicalWeightStateIterator;
94 #if HAVE_OPENFST_LOG
95  using hfst::implementations::LogWeightTransducer;
96 #endif // #if HAVE_OPENFST_LOG
97 #endif // #if HAVE_OPENFST
98 
99 #if HAVE_FOMA
100  using hfst::implementations::FomaTransducer;
101 #endif // #if HAVE_FOMA
102 
103  /* Add here the transducer class of your transducer library. */
104  //#if HAVE_MY_TRANSDUCER_LIBRARY
105  // using hfst::implementations::MyTransducerLibraryTransducer;
106  //#endif // #if HAVE_MY_TRANSDUCER_LIBRARY
107 
108  HfstFile hfst_open(const char * filename, const char * mode);
109  HfstFile hfst_stdout();
110  HfstFile hfst_stdin();
111 
112  // *** TESTING AND OPTIMIZATION...
113 
114  enum MinimizationAlgorithm { HOPCROFT, BRZOZOWSKI };
115  /* Which minimization algorithm is used.
116  In foma, Hopcroft is always used.
117  In OpenFst and SFST, the default algorithm is Hopcroft. */
118  void set_minimization_algorithm(MinimizationAlgorithm);
119  MinimizationAlgorithm get_minimization_algorithm();
120 
121  void set_encode_weights(bool);
122  bool get_encode_weights();
123 
124  /* Whether in harmonization the smaller transducer is always harmonized
125  according to the bigger transducer. */
126  void set_harmonize_smaller(bool);
127  bool get_harmonize_smaller();
128 
129  /* Whether unknown and identity symbols are used. By default, they are used.
130  These symbols are always reserved for use and included in alphabets
131  of transducers, but code optimization is possible if it is known
132  that they do not appear in transducer transitions. */
133  void set_unknown_symbols_in_use(bool);
134  bool get_unknown_symbols_in_use();
135 
136  // *** ...TESTING AND OPTIMIZATION
137 
138 
228  {
229 
230  // ***** PROTECTED VARIABLES AND INTERFACE *****
231 
232  protected:
233 
234  /* The backend implementation type of the transducer */
235  ImplementationType type;
236 
237  bool anonymous; // currently not used
238  bool is_trie; // currently not used
239  std::string name; /* The name of the transducer */
240  std::map<std::string,std::string> props; // rest of fst metadata
241  /* The union of possible backend implementations. */
242  union TransducerImplementation
243  {
244 #if HAVE_SFST
245  hfst::implementations::Transducer * sfst;
246 #endif
247 #if HAVE_OPENFST
248  hfst::implementations::StdVectorFst * tropical_ofst;
249 #if HAVE_OPENFST_LOG
250  hfst::implementations::LogFst * log_ofst;
251 #endif
252 #endif
253 #if HAVE_FOMA
254  fsm * foma;
255 #endif
256 
257  /* Add here your own transducer backend implementation. */
258  //#if HAVE_MY_TRANSDUCER_LIBRARY
259  // hfst::implementations::MyFst * my_transducer_library;
260  //#endif
261 
262  hfst_ol::Transducer * hfst_ol;
263 
264 #if HAVE_OPENFST // is this needed?
265  hfst::implementations::StdVectorFst * internal;
266 #endif
267  };
268 
269  /* The backend implementation */
270  TransducerImplementation implementation;
271 
272  /* Interfaces through which the backend implementations can be accessed */
273 #if HAVE_SFST
274  static hfst::implementations::SfstTransducer sfst_interface;
275 #endif
276 #if HAVE_OPENFST
277  static hfst::implementations::TropicalWeightTransducer
278  tropical_ofst_interface;
279 #if HAVE_OPENFST_LOG
280  static hfst::implementations::LogWeightTransducer log_ofst_interface;
281 #endif
282 #endif
283 #if HAVE_FOMA
284  static hfst::implementations::FomaTransducer foma_interface;
285 #endif
286  static hfst::implementations::HfstOlTransducer hfst_ol_interface;
287 
288  /* Add here the class that takes care of the interaction between
289  HFST and your transducer library. */
290  //#if HAVE_MY_TRANSDUCER_LIBRARY
291  //static hfst::implementations::MyTransducerLibraryTransducer
292  // my_transducer_library_interface;
293  //#endif
294 
295  /* The same as harmonize but does not change \a another but
296  returns a harmonized version of that. If this and \a another
297  have type FOMA_TYPE, NULL is returned. */
298  HfstTransducer * harmonize_(const HfstTransducer &another);
299 
300  HfstTransducer * harmonize_symbol_encodings(const HfstTransducer &another);
301 
302  /* Check if transducer \a another has in its alphabet flag diacritics
303  that are not found in the alphabet of this transducer and insert
304  all missing flag diacritics to \a missing_flags.
305  \a return_on_first_miss defines whether the function returns as soon as
306  a missing flag is found so that only that flag is inserted to
307  \a missing flags. */
308  bool check_for_missing_flags_in(const HfstTransducer &another,
309  StringSet &missing_flags,
310  bool return_on_first_miss) const;
311 
312  /* Disjunct trie transducers efficiently so that the result is also
313  a trie.
314  Currently not implemented, TODO */
315  HfstTransducer &disjunct_as_tries(HfstTransducer &another,
316  ImplementationType type);
317 
318 
319  /* Remove paths where @..._2@ transitions immediately preceede
320  @..._1@ transitions, i.e. transitions resulting from incorrect
321  ordering of flag diacritics. */
322  HfstTransducer &remove_illegal_flag_paths(void);
323 
324  /* Whether the conversion requested can be done without losing
325  any information */
326  static bool is_safe_conversion(ImplementationType original,
327  ImplementationType conversion);
328 
329 
330  /* For internal use */
331  static HfstTransducer &read_in_att_format
332  (FILE *ifile, ImplementationType type, const std::string &epsilon_symbol);
333 
334  public:
335  /* whether HFST is linked to the transducer library
336  needed by implementation type \a type. */
337  static bool is_implementation_type_available(ImplementationType type);
338 
339  unsigned int number_of_states() const;
340  unsigned int number_of_arcs() const;
341 
342  protected:
343  /* For internal use: Create a tokenizer that recognizes all symbols
344  that occur in the transducer. */
345  HfstTokenizer create_tokenizer();
346 
347  /* For internal use. Implemented only for SFST_TYPE.
348  Get all symbol pairs that occur in the transitions of the transducer. */
349  StringPairSet get_symbol_pairs();
350 
351  protected:
352 
353  /* Get the number used to represent the symbol \a symbol. */
354  unsigned int get_symbol_number(const std::string &symbol);
355 
356  /* For internal use, implemented only for SFST_TYPE. */
357  std::vector<HfstTransducer*> extract_path_transducers();
358 
359  /* For internal use:
360  Create a new transducer equivalent to \a t in format \a type. */
361  static HfstTransducer &convert
362  (const HfstTransducer &t, ImplementationType type);
363 
364  /* For internal use:
365  Create an HfstBasicTransducer equivalent to \a t end delete
366  the backend implementation of \a t. */
367  implementations::HfstBasicTransducer * convert_to_basic_transducer();
368 
369  /* For internal use:
370  Create an HfstBasicTransducer equivalent to \a t. */
371  implementations::HfstBasicTransducer * get_basic_transducer() const;
372 
373  /* For internal use:
374  Create a backend implementation of the same type that this transducer
375  has and that is equivalent to \a t and delete \a t. Assign the
376  backend implementation as the value of the implementation of this
377  transducer. */
378  HfstTransducer &convert_to_hfst_transducer
380 
381  /* \brief For internal use: Create a transducer of type \a type as
382  defined in AT&T format in file named \a filename.
383  \a epsilon_symbol defines how epsilons are represented.
384 
385  NOTE: If the transition symbols contain space characters
386  they must be represented as "@_SPACE_@" because
387  whitespace characters are used as field separators
388  in AT&T format.
389 
390  @pre The file exists, otherwise an exception is thrown.
391  @see HfstTransducer(FILE, ImplementationType, const std::string&)
392  @throws StreamNotReadableException
393  @throws NotValidAttFormatException
394  */
395  static HfstTransducer &read_in_att_format
396  (const std::string &filename, ImplementationType type,
397  const std::string &epsilon_symbol);
398 
399 
400  /* For debugging */
401  public:
402  void print_alphabet();
403  protected:
404  static float get_profile_seconds(ImplementationType type);
405 
406 #include "hfst_apply_schemas.h"
407 
408 
409 
410  // ***** THE PUBLIC INTERFACE *****
411 
412  public:
413 
414 
415  // ------------------------------------------------
416  // ----- Constructors, destructor, assignment -----
417  // ------------------------------------------------
418 
425  HfstTransducer();
426 
434 
453  HfstTransducer(const std::string& utf8_str,
454  const HfstTokenizer &multichar_symbol_tokenizer,
455  ImplementationType type);
456 
481  HfstTransducer(const std::string& input_utf8_str,
482  const std::string& output_utf8_str,
483  const HfstTokenizer &multichar_symbol_tokenizer,
484  ImplementationType type);
485 
486  /* @brief Create a transducer that recognizes the union of string pairs in
487  \a sps. The type of the transducer is defined by \a type. \a cyclic
488  defines whether the transducer recognizes any number (from zero to
489  infinity, inclusive) of consecutive string pairs in \s sps. */
491  bool cyclic=false);
492 
493  /* \brief Create a transducer that recognizes the concatenation of
494  string pairs in \a spv. The type of the transducer is defined
495  by \a type. */
497 
498  /* \brief Create a transducer that recognizes the concatenation of the
499  unions of string pairs in string pair sets in \a spsv. The type of
500  the transducer is defined by \a type. */
501  HfstTransducer(const std::vector<StringPairSet> & spsv,
502  ImplementationType type);
503 
525 
527  HfstTransducer(const HfstTransducer &another);
528 
533  ImplementationType type);
534 
539  HfstTransducer(const std::string &symbol, ImplementationType type);
540 
545  HfstTransducer(const std::string &isymbol, const std::string &osymbol,
546  ImplementationType type);
547 
621  HfstTransducer(FILE * ifile, ImplementationType type,
622  const std::string &epsilon_symbol, unsigned int & linecount);
623 
624  HfstTransducer(FILE * ifile, ImplementationType type,
625  const std::string &epsilon_symbol);
626 
627  HfstTransducer(HfstFile &ifile, ImplementationType type,
628  const std::string &epsilon_symbol);
629 
630 
632  virtual ~HfstTransducer(void);
633 
636  HfstTransducer &operator=(const HfstTransducer &another);
637 
638  HfstTransducer &assign(const HfstTransducer &another);
639 
640  // ------------------------------------------------------------
641  // ----------- Properties, comparison, conversion -------------
642  // ------------------------------------------------------------
643 
646  void set_name(const std::string &name);
647 
650  std::string get_name() const;
651 
661  void set_property(const std::string& property, const std::string& value);
662 
667  std::string get_property(const std::string& property) const;
671  const std::map<std::string,std::string>& get_properties() const;
676  StringSet get_alphabet() const;
677 
680  StringSet get_first_input_symbols() const;
681 
690  void harmonize(HfstTransducer &another);
691 
697  void insert_to_alphabet(const std::string &symbol);
698  void insert_to_alphabet(const std::set<std::string> &symbols);
699 
706  void remove_from_alphabet(const std::string &symbol);
707  void remove_from_alphabet(const std::set<std::string> &symbols);
708 
720  HfstTransducer &prune_alphabet(bool force=true);
721 
723  bool is_cyclic(void) const;
724 
726  bool is_automaton(void) const;
727 
729  ImplementationType get_type(void) const;
730 
737  bool compare(const HfstTransducer &another, bool harmonize=true) const;
738 
755  HfstTransducer &convert(ImplementationType type, std::string options="");
756 
757 
758  // --------------------------------------------------------
759  // --- String lookup and conversion to/from AT&T format ---
760  // --------------------------------------------------------
761 
816  void write_in_att_format(FILE * ofile, bool write_weights=true) const;
817 
818  void write_in_att_format(HfstFile & ofile, bool write_weights=true) const;
819 
820  void write_in_att_format(char * buffer, bool write_weights=true) const;
821 
822  void write_in_att_format_number
823  (FILE * ofile, bool write_weights=true) const;
824 
825 
834  void write_in_att_format(const std::string &filename,
835  bool write_weights=true) const;
836 
837  public:
838  /* \brief Call \a callback with some or all string pairs recognized
839  by the transducer?
840 
841  If the callback returns false the search will be terminated.
842  The \a cycles parameter
843  indicates how many times a cycle will be followed, with negative numbers
844  indicating unlimited. Note that if the transducer is cyclic and
845  cycles aren't capped,
846  the search will not end until the callback returns false. */
847  void extract_paths(ExtractStringsCb& callback, int cycles=-1) const;
848 
930  void extract_paths
931  (HfstTwoLevelPaths &results, int max_num=-1, int cycles=-1) const;
932 
933  void extract_random_paths
934  (HfstTwoLevelPaths &results, int max_num) const;
935 
936  void extract_random_paths_fd
937  (HfstTwoLevelPaths &results, int max_num, bool filter_fd) const;
938 
939  /* \brief Call \a callback with extracted strings that are not
940  invalidated by flag diacritic rules.
941 
942  @see extract_paths(HfstTwoLevelPaths&, int, int) */
943  void extract_paths_fd
944  (ExtractStringsCb& callback, int cycles=-1, bool filter_fd=true) const;
945 
946  // todo: handle flag diacritics
947  // todo: throw TransducerIsCyclicException, if cyclic
948  void extract_shortest_paths
949  (HfstTwoLevelPaths &results) const;
950 
951  bool extract_longest_paths
952  (HfstTwoLevelPaths &results, bool obey_flags=true /*,bool show_flags=false*/) const;
953 
954  int longest_path_size(bool obey_flags=true) const;
955 
956  public:
990  void extract_paths_fd
991  (HfstTwoLevelPaths &results, int max_num=-1, int cycles=-1,
992  bool filter_fd=true) const;
993 
1005  ssize_t limit = -1) const;
1006 
1012  HfstOneLevelPaths * lookup(const std::string & s,
1013  ssize_t limit = -1) const;
1014 
1045  ssize_t limit = -1) const;
1046 
1061  HfstOneLevelPaths * lookup_fd(const std::string& s,
1062  ssize_t limit = -1) const;
1063 
1072  HfstOneLevelPaths * lookup(const HfstTokenizer& tok,
1073  const std::string &s, ssize_t limit = -1) const;
1074 
1084  const HfstTokenizer& tok,
1085  const std::string &s, ssize_t limit = -1) const;
1086 
1102  ssize_t limit = -1) const;
1103 
1104  HfstOneLevelPaths * lookdown(const std::string& s,
1105  ssize_t limit = -1) const;
1106 
1116  ssize_t limit = -1) const;
1117 
1118  HfstOneLevelPaths * lookdown_fd(const std::string& s,
1119  ssize_t limit = -1) const;
1120 
1128  bool is_lookup_infinitely_ambiguous(const StringVector & s) const;
1129  bool is_lookup_infinitely_ambiguous(const std::string & s) const;
1130 
1134  bool is_lookdown_infinitely_ambiguous(const StringVector& s) const;
1135 
1136  bool is_infinitely_ambiguous() const ;
1137 
1138 
1139  // -------------------------------------------
1140  // --------- Optimization operations ---------
1141  // -------------------------------------------
1142 
1143  HfstTransducer &eliminate_flags();
1144  HfstTransducer &eliminate_flag(const std::string &flag);
1145 
1149 
1151  HfstTransducer &prune();
1152 
1159 
1168 
1184  HfstTransducer &n_best(unsigned int n);
1185 
1186 
1187  // ------------------------------------------------
1188  // ------------- Algebraic operations -------------
1189  // ------------------------------------------------
1190 
1194 
1198 
1200  HfstTransducer &repeat_n(unsigned int n);
1201 
1204  HfstTransducer &repeat_n_minus(unsigned int n);
1205 
1208  HfstTransducer &repeat_n_plus(unsigned int n);
1209 
1212  HfstTransducer& repeat_n_to_k(unsigned int n, unsigned int k);
1213 
1216 
1220 
1227 
1233 
1239 
1241  HfstTransducer &compose(const HfstTransducer &another,
1242  bool harmonize=true);
1243 
1255  bool invert=false, bool harmonize=true);
1256 
1258  HfstTransducer &concatenate(const HfstTransducer &another, bool harmonize=true);
1259 
1261  HfstTransducer &disjunct(const HfstTransducer &another, bool harmonize=true);
1262 
1286  HfstTransducer &priority_union(const HfstTransducer &another, bool harmonize=true);
1287 
1288 
1292  HfstTransducer &lenient_composition(const HfstTransducer &another, bool harmonize=true);
1293 
1302  HfstTransducer &cross_product(const HfstTransducer &another, bool harmonize=true);
1303 
1304 
1305  /*
1306  * \brief Shuffle this transducer with transducer \@ another.
1307  *
1308  * If transducer A accepts string "foo" and transducer B string "bar",
1309  * the transducer that results from shuffling A and B accepts all strings
1310  * [(f|b)(o|a)(o|r)].
1311  *
1312  * @pre Both transducers must be automata, i.e. map strings onto themselves.
1313  *
1314  */
1315  HfstTransducer &shuffle(const HfstTransducer &another, bool harmonize=true);
1316 
1325 
1334 
1335 
1336 
1337 
1338 
1339  /* For HfstCompiler: Optimized disjunction function. */
1341 
1343  HfstTransducer &intersect(const HfstTransducer &another, bool harmonize=true);
1344 
1346  HfstTransducer &subtract(const HfstTransducer &another, bool harmonize=true);
1347 
1348 
1349  // ------------------------------------------------
1350  // ---------- Insertion and substitution ----------
1351  // ------------------------------------------------
1352 
1363  HfstTransducer &insert_freely(const StringPair &symbol_pair, bool harmonize=true);
1364 
1380  HfstTransducer &insert_freely(const HfstTransducer &tr, bool harmonize=true);
1381 
1424  (bool (*func)(const StringPair &sp, StringPairSet &sps));
1425 
1441  HfstTransducer &substitute(const std::string &old_symbol,
1442  const std::string &new_symbol,
1443  bool input_side=true,
1444  bool output_side=true);
1445 
1459  HfstTransducer &substitute(const StringPair &old_symbol_pair,
1460  const StringPair &new_symbol_pair);
1461 
1474  HfstTransducer &substitute(const StringPair &old_symbol_pair,
1475  const StringPairSet &new_symbol_pair_set);
1476 
1486  HfstTransducer &substitute(const HfstSymbolSubstitutions &substitutions);
1487 
1488  HfstTransducer &substitute_symbols(const HfstSymbolSubstitutions &substitutions);
1489 
1500  HfstTransducer &substitute(const HfstSymbolPairSubstitutions &substitutions);
1501 
1502  HfstTransducer &substitute_symbol_pairs(const HfstSymbolPairSubstitutions &substitutions);
1503 
1520  HfstTransducer &substitute(const StringPair &symbol_pair,
1521  HfstTransducer &transducer, bool harmonize=true);
1522 
1523  // -----------------------------------------------
1524  // --------------- Weight handling ---------------
1525  // -----------------------------------------------
1526 
1534  HfstTransducer &set_final_weights(float weight, bool increment=false);
1535 
1558  HfstTransducer &transform_weights(float (*func)(float));
1559 
1568 
1569 
1572  static HfstTransducer * read_lexc_ptr(const std::string &filename,
1573  ImplementationType type,
1574  bool verbose);
1575 
1576  static HfstTransducer read_lexc(const std::string &filename,
1577  ImplementationType type,
1578  bool verbose);
1579 
1580  // *** For commandline programs. ***
1581 
1582  /* For each flag diacritic fd that is included in the alphabet of
1583  transducer \a another but not in the alphabet of this transducer,
1584  insert freely a transition fd:fd in this transducer. */
1585  void insert_freely_missing_flags_from
1586  (const HfstTransducer &another);
1587 
1588  /*
1589  If both \a this and \a another contain flag diacritics, replace flag
1590  diacritic @X.Y.(.Z)@ by @X.Y_1(.Z)@ in \a this and replace it by
1591  @X.Y_2(.Z)@ in \a another.
1592 
1593  If \a insert_renamed_flags is true, then the flags from \a this are
1594  inserted freely in \a another and vice versa after replacing.
1595  */
1596  void harmonize_flag_diacritics(HfstTransducer &another,
1597  bool insert_renamed_flags=true);
1598 
1599  void insert_missing_symbols_to_alphabet_from(const HfstTransducer &another, bool only_special_symbols=false);
1600 
1601  static bool is_special_symbol(const std::string & symbol);
1602 
1603  /* Whether the alphabet of transducer \a another includes flag diacritics
1604  that are not included in the alphabet of this transducer. */
1605  bool check_for_missing_flags_in(const HfstTransducer &another) const;
1606 
1607  /* Return true if \a this has flag diacritics in the alphabet. */
1608  bool has_flag_diacritics(void) const;
1609 
1610 
1611 
1612  // *** Friends **** //
1613 
1614  friend std::ostream& operator<<(std::ostream &out, const HfstTransducer &t);
1615  friend std::ostream& redirect(std::ostream &out, const HfstTransducer &t);
1616  friend class HfstInputStream;
1617  friend class HfstOutputStream;
1618  friend class hfst::implementations::HfstTransitionGraph<class C>;
1619  friend class HfstCompiler;
1620  friend class hfst::implementations::ConversionFunctions;
1621  friend class HfstGrammar;
1622  friend class xfst::XfstCompiler;
1623  //friend HfstTransducer bracketedReplace( const hfst::xeroxRules::Rule &rule, bool optional);
1625  };
1626 
1632  std::ostream &operator<<(std::ostream &out,const HfstTransducer &t);
1633 
1634  std::ostream &redirect(std::ostream &out,const HfstTransducer &t);
1635 
1638  namespace rules
1639  {
1640  enum ReplaceType {REPL_UP, REPL_DOWN, REPL_RIGHT, REPL_LEFT,
1641  REPL_DOWN_KARTTUNEN};
1642  enum TwolType {twol_right, twol_left, twol_both};
1643 
1644  /* helping methods */
1645  HfstTransducer universal_fst
1646  (const StringPairSet &alphabet, ImplementationType type);
1647  HfstTransducer negation_fst
1648  (const HfstTransducer &t, const StringPairSet &alphabet);
1649 
1650  HfstTransducer replace
1651  (HfstTransducer &t, ReplaceType repl_type, bool optional,
1652  StringPairSet &alphabet);
1653  HfstTransducer replace_transducer
1654  (HfstTransducer &t, std::string lm, std::string rm,
1655  ReplaceType repl_type, StringPairSet &alphabet);
1656  HfstTransducer replace_context
1657  (HfstTransducer &t, std::string m1, std::string m2,
1658  StringPairSet &alphabet);
1659  HfstTransducer replace_in_context
1660  (HfstTransducerPair &context, ReplaceType repl_type,
1661  HfstTransducer &t, bool optional, StringPairSet &alphabet);
1662 
1663  /* Used by hfst-calculate. */
1664  HfstTransducer restriction
1665  (HfstTransducerPairVector &contexts, HfstTransducer &mapping,
1666  StringPairSet &alphabet, TwolType twol_type, int direction );
1667 
1668 
1669 
1670  // ***** THE PUBLIC INTERFACE *****
1671 
1700  HfstTransducer two_level_if(HfstTransducerPair &context,
1701  StringPairSet &mappings,
1702  StringPairSet &alphabet);
1703 
1719  HfstTransducer two_level_only_if(HfstTransducerPair &context,
1720  StringPairSet &mappings,
1721  StringPairSet &alphabet);
1722 
1737  HfstTransducer two_level_if_and_only_if(HfstTransducerPair &context,
1738  StringPairSet &mappings,
1739  StringPairSet &alphabet);
1740 
1741 
1792  HfstTransducer replace_up(HfstTransducerPair &context,
1793  HfstTransducer &mapping,
1794  bool optional,
1795  StringPairSet &alphabet);
1796 
1803  HfstTransducer replace_down(HfstTransducerPair &context,
1804  HfstTransducer &mapping,
1805  bool optional,
1806  StringPairSet &alphabet);
1807 
1808  HfstTransducer replace_down_karttunen(HfstTransducerPair &context,
1809  HfstTransducer &mapping,
1810  bool optional,
1811  StringPairSet &alphabet);
1812 
1820  HfstTransducer replace_right(HfstTransducerPair &context,
1821  HfstTransducer &mapping,
1822  bool optional,
1823  StringPairSet &alphabet);
1824 
1832  HfstTransducer replace_left(HfstTransducerPair &context,
1833  HfstTransducer &mapping,
1834  bool optional,
1835  StringPairSet &alphabet);
1836 
1837 
1842  HfstTransducer replace_up(HfstTransducer &mapping,
1843  bool optional,
1844  StringPairSet &alphabet);
1845 
1850  HfstTransducer replace_down(HfstTransducer &mapping,
1851  bool optional,
1852  StringPairSet &alphabet);
1853 
1862  HfstTransducer left_replace_up( HfstTransducer &mapping,
1863  bool optional,
1864  StringPairSet &alphabet);
1865 
1872  HfstTransducer left_replace_up( HfstTransducerPair &context,
1873  HfstTransducer &mapping,
1874  bool optional,
1875  StringPairSet &alphabet);
1880  HfstTransducer left_replace_down(HfstTransducerPair &context,
1881  HfstTransducer &mapping,
1882  bool optional,
1883  StringPairSet &alphabet);
1884 
1889  HfstTransducer left_replace_down_karttunen( HfstTransducerPair &context,
1890  HfstTransducer &mapping,
1891  bool optional,
1892  StringPairSet &alphabet);
1893 
1899  HfstTransducer left_replace_left(HfstTransducerPair &context,
1900  HfstTransducer &mapping,
1901  bool optional,
1902  StringPairSet &alphabet);
1903 
1909  HfstTransducer left_replace_right(HfstTransducerPair &context,
1910  HfstTransducer &mapping,
1911  bool optional,
1912  StringPairSet &alphabet);
1913 
1914 
1915 
1916 
1917 
1929  HfstTransducer restriction(HfstTransducerPairVector &contexts,
1930  HfstTransducer &mapping,
1931  StringPairSet &alphabet);
1932 
1942  HfstTransducer coercion(HfstTransducerPairVector &contexts,
1943  HfstTransducer &mapping,
1944  StringPairSet &alphabet);
1945 
1958  HfstTransducer restriction_and_coercion(HfstTransducerPairVector &contexts,
1959  HfstTransducer &mapping,
1960  StringPairSet &alphabet);
1961 
1974  HfstTransducer surface_restriction(HfstTransducerPairVector &contexts,
1975  HfstTransducer &mapping,
1976  StringPairSet &alphabet);
1977 
1990  HfstTransducer surface_coercion(HfstTransducerPairVector &contexts,
1991  HfstTransducer &mapping,
1992  StringPairSet &alphabet);
1993 
2000  HfstTransducer surface_restriction_and_coercion
2001  (HfstTransducerPairVector &contexts,
2002  HfstTransducer &mapping,
2003  StringPairSet &alphabet);
2004 
2016  HfstTransducer deep_restriction(HfstTransducerPairVector &contexts,
2017  HfstTransducer &mapping,
2018  StringPairSet &alphabet);
2019 
2031  HfstTransducer deep_coercion(HfstTransducerPairVector &contexts,
2032  HfstTransducer &mapping,
2033  StringPairSet &alphabet);
2034 
2041  HfstTransducer deep_restriction_and_coercion
2042  (HfstTransducerPairVector &contexts,
2043  HfstTransducer &mapping,
2044  StringPairSet &alphabet);
2045  }
2046 
2047 }
2048 
2049 
2050 // vim: set ft=cpp.doxygen:
2051 #endif // #ifndef _HFST_TRANSDUCER_H_
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:629
ImplementationType get_type(void) const
The implementation type of the transducer.
Definition: HfstTransducer.cc:1296
HfstTransducer & prune()
Make transducer coaccessible.
Definition: HfstTransducer.cc:1843
Declaration of class HfstInputStream.
bool is_lookdown_infinitely_ambiguous(const StringVector &s) const
(Not implemented) Whether lookdown of path s will have infinite results.
Definition: HfstTransducer.cc:687
Declaration of class hfst::HfstTokenizer.
Class HfstTransitionGraph.
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:425
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:1982
HfstTransducer()
Create an uninitialized transducer (use with care).
Definition: HfstTransducer.cc:715
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:490
std::pair< String, String > StringPair
A symbol pair in a transition.
Definition: HfstSymbolDefs.h:71
HfstTransducer & intersect(const HfstTransducer &another, bool harmonize=true)
Intersect this transducer with another.
Definition: HfstTransducer.cc:4104
HfstOneLevelPaths * lookup_fd(const StringVector &s, ssize_t limit=-1) const
Lookup or apply a single string s minding flag diacritics properly and store a maximum of limit resul...
Definition: HfstTransducer.cc:571
HfstTransducer & prune_alphabet(bool force=true)
Remove all symbols that do not occur in transitions of the transducer from its alphabet.
Definition: HfstTransducer.cc:239
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:458
HfstOneLevelPaths * lookdown_fd(StringVector &s, ssize_t limit=-1) const
(Not implemented) Lookdown a single string minding flag diacritics properly.
Definition: HfstTransducer.cc:636
HfstTransducer & subtract(const HfstTransducer &another, bool harmonize=true)
Subtract transducer another from this transducer.
Definition: HfstTransducer.cc:4123
HfstTransducer & remove_epsilons()
Remove all epsilon:epsilon transitions from the transducer so that the transducer remains equivalent...
Definition: HfstTransducer.cc:1822
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:686
A compiled transducer format, suitable for fast lookup operations.
Definition: 3831_transducer.h:804
void harmonize(HfstTransducer &another)
Harmonize transducers this and another.
Definition: HfstTransducer.cc:457
std::string get_property(const std::string &property) const
Get arbitrary string propert property. get_property("name") works like get_name.
Definition: HfstTransducer.cc:1315
std::vector< std::pair< std::string, std::string > > StringPairVector
A vector of string pairs.
Definition: HfstDataTypes.h:106
HfstTransducer & push_weights(PushType type)
Push weights towards initial or final state(s) as defined by type.
Definition: HfstTransducer.cc:3188
static 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:4963
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:1964
A synchronous finite-state transducer.
Definition: HfstTransducer.h:227
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:1958
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:156
HfstTransducer & output_project()
Extract the output language of the transducer.
Definition: HfstTransducer.cc:2068
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:3572
bool is_lookup_infinitely_ambiguous(const StringVector &s) const
Whether lookup of path s will have infinite results.
Definition: HfstTransducer.cc:658
HfstTransducer & input_project()
Extract the input language of the transducer.
Definition: HfstTransducer.cc:2050
A file for exceptions.
bool is_automaton(void) const
Whether the transducer is an automaton.
Definition: HfstTransducer.cc:1400
ImplementationType
The type of an HfstTransducer.
Definition: HfstDataTypes.h:43
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:399
Declarations of functions and datatypes that form a bridge between HFST API and foma.
HfstTransducer & minimize()
Minimize the transducer.
Definition: HfstTransducer.cc:1874
HfstTransducer & concatenate(const HfstTransducer &another, bool harmonize=true)
Concatenate this transducer with another.
Definition: HfstTransducer.cc:3997
HfstTransducer & reverse()
Reverse the transducer.
Definition: HfstTransducer.cc:2032
HfstTransducer & optionalize()
Disjunct the transducer with an epsilon transducer.
Definition: HfstTransducer.cc:1996
HfstTransducer & priority_union(const HfstTransducer &another, bool harmonize=true)
Make priority union of this transducer with another.
Definition: HfstTransducer.cc:3797
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:434
A simple transition graph format that consists of states and transitions between those states...
Definition: HfstDataTypes.h:113
PushType
The type of a push operation.
Definition: HfstDataTypes.h:65
declarations for HFST functions that take two or more parameters
bool compare(const HfstTransducer &another, bool harmonize=true) const
Whether this transducer and another are equivalent.
Definition: HfstTransducer.cc:1338
friend std::ostream & operator<<(std::ostream &out, const HfstTransducer &t)
Write transducer t in AT&T format to ostream out.
Definition: HfstTransducer.cc:5038
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:506
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:679
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:712
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:719
virtual ~HfstTransducer(void)
Destructor.
Definition: HfstTransducer.cc:1152
HfstTransducer & repeat_star()
A concatenation of N transducers where N is any number from zero to infinity.
Definition: HfstTransducer.cc:1901
A stream for writing binary transducers.
Definition: HfstOutputStream.h:67
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:3828
std::vector< HfstTransducer > HfstTransducerVector
a vector of transducers for methods applying a cascade of automata
Definition: HfstDataTypes.h:35
std::set< HfstTwoLevelPath > HfstTwoLevelPaths
A set of two-level weighted paths.
Definition: HfstDataTypes.h:110
HfstTransducer & invert()
Swap the input and output symbols of each transition in the transducer.
Definition: HfstTransducer.cc:2014
HfstTransducer & compose(const HfstTransducer &another, bool harmonize=true)
Compose this transducer with another.
Definition: HfstTransducer.cc:3289
HfstTransducer & insert_freely(const StringPair &symbol_pair, bool harmonize=true)
Freely insert symbol pair symbol_pair into the transducer.
Definition: HfstTransducer.cc:2766
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:407
HfstTransducer & repeat_n(unsigned int n)
A concatenation of n transducers.
Definition: HfstTransducer.cc:1937
Declarations of functions and datatypes that form a bridge between HFST API and OpenFst's transducers...
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:260
const std::map< std::string, std::string > & get_properties() const
Get all properties form transducer.
Definition: HfstTransducer.cc:1327
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:522
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:216
static HfstTransducer universal_pair(ImplementationType type)
Create universal pair transducer of type.
Definition: HfstTransducer.cc:4780
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:3166
Datatypes that are needed when using the HFST API.
HfstTransducer & determinize()
Determinize the transducer.
Definition: HfstTransducer.cc:1856
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:538
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:51
static HfstTransducer identity_pair(ImplementationType type)
Create identity pair transducer of type.
Definition: HfstTransducer.cc:4795
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:699
A stream for reading HFST binary transducers.
Definition: HfstInputStream.h:94
HfstTransducer & disjunct(const HfstTransducer &another, bool harmonize=true)
Disjunct this transducer with another.
Definition: HfstTransducer.cc:4084
std::set< StringPair > StringPairSet
A set of symbol pairs used in substituting symbol pairs and in rule functions.
Definition: HfstSymbolDefs.h:83
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:247
bool is_cyclic(void) const
Whether the transducer is cyclic.
Definition: HfstTransducer.cc:1431
std::set< HfstOneLevelPath > HfstOneLevelPaths
A set of simple paths.
Definition: HfstDataTypes.h:101
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:692
std::pair< HfstTransducer, HfstTransducer > HfstTransducerPair
A pair of transducers.
Definition: HfstDataTypes.h:79
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:4504
Declarations of functions for converting between transducer backend formats.
void remove_from_alphabet(const std::string &symbol)
Remove symbol from the alphabet of the transducer. CURRENTLY NOT IMPLEMENTED.
Definition: HfstTransducer.cc:214
HfstTransducer & operator=(const HfstTransducer &another)
Assign this transducer a new value equivalent to transducer another.
Definition: HfstTransducer.cc:4812
Declaration of class HfstOutputStream.
HfstTransducer & substitute(bool(*func)(const StringPair &sp, StringPairSet &sps))
Substitute all transition sp with transitions sps as defined by function func.
Definition: HfstTransducer.cc:2918
std::map< String, String > HfstSymbolSubstitutions
A map of substitutions used when performing multiple symbol-to-symbol substitutions.
Definition: HfstSymbolDefs.h:89
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:673
std::vector< HfstTransducerPair > HfstTransducerPairVector
A vector of transducer pairs.
Definition: HfstDataTypes.h:83
HfstTransducer & n_best(unsigned int n)
Extract n best paths of the transducer.
Definition: HfstTransducer.cc:2481
HfstTransducer & transform_weights(float(*func)(float))
Transform all transition and state weights as defined in func.
Definition: HfstTransducer.cc:3218
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:706
std::string get_name() const
Get the name of the transducer.
Definition: HfstTransducer.cc:1301
HfstTransitionGraph< HfstTropicalTransducerTransitionData > HfstBasicTransducer
An HfstTransitionGraph with transitions of type HfstTropicalTransducerTransitionData and weight type ...
Definition: HfstDataTypes.h:114
A tokenizer for creating transducers from UTF-8 strings.
Definition: HfstTokenizer.h:85
void set_name(const std::string &name)
Rename the transducer name.
Definition: HfstTransducer.cc:1298
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:1305
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:95
Typedefs and functions for symbols, symbol pairs and sets of symbols.
HfstTransducer bracketedReplace(const Rule &rule, bool optional)
Unconditional replace, in multiple contexts first: (.* T<a:b>T .*) - [( .* L1 T<a:b>T R1 ...
Definition: HfstXeroxRules.cc:447
HfstOneLevelPaths * lookup(const StringVector &s, ssize_t limit=-1) const
Lookup or apply a single tokenized string s and return a maximum of limit results.
Definition: HfstTransducer.cc:559
std::vector< std::string > StringVector
A vector of strings.
Definition: HfstDataTypes.h:88
StringSet get_alphabet() const
Get the alphabet of the transducer.
Definition: HfstTransducer.cc:276
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:3555
void insert_to_alphabet(const std::string &symbol)
Explicitly insert symbol to the alphabet of the transducer.
Definition: HfstTransducer.cc:183
HfstTransducer & repeat_plus()
A concatenation of N transducers where N is any number from one to infinity.
Definition: HfstTransducer.cc:1919
std::ostream & operator<<(std::ostream &out, const HfstTransducer &t)
Write transducer t in AT&T format to ostream out.
Definition: HfstTransducer.cc:5038