12 #ifndef _HFST_TRANSDUCER_H_
13 #define _HFST_TRANSDUCER_H_
19 #include "FormatSpecifiers.h"
24 #include "parsers/LexcCompiler.h"
67 namespace implementations {
68 template <
class T>
class HfstTransitionGraph;
69 class HfstTropicalTransducerTransitionData;
70 typedef HfstTransitionGraph<HfstTropicalTransducerTransitionData>
84 using hfst::implementations::HfstOlTransducer;
87 using hfst::implementations::SfstTransducer;
88 #endif // #if HAVE_SFST
91 using hfst::implementations::TropicalWeightTransducer;
92 using hfst::implementations::TropicalWeightState;
93 using hfst::implementations::TropicalWeightStateIterator;
95 using hfst::implementations::LogWeightTransducer;
96 #endif // #if HAVE_OPENFST_LOG
97 #endif // #if HAVE_OPENFST
100 using hfst::implementations::FomaTransducer;
101 #endif // #if HAVE_FOMA
108 HfstFile hfst_open(
const char * filename,
const char * mode);
109 HfstFile hfst_stdout();
110 HfstFile hfst_stdin();
114 enum MinimizationAlgorithm { HOPCROFT, BRZOZOWSKI };
118 void set_minimization_algorithm(MinimizationAlgorithm);
119 MinimizationAlgorithm get_minimization_algorithm();
121 void set_encode_weights(
bool);
122 bool get_encode_weights();
126 void set_harmonize_smaller(
bool);
127 bool get_harmonize_smaller();
133 void set_unknown_symbols_in_use(
bool);
134 bool get_unknown_symbols_in_use();
240 std::map<std::string,std::string> props;
242 union TransducerImplementation
245 hfst::implementations::Transducer * sfst;
248 hfst::implementations::StdVectorFst * tropical_ofst;
250 hfst::implementations::LogFst * log_ofst;
264 #if HAVE_OPENFST // is this needed?
265 hfst::implementations::StdVectorFst *
internal;
270 TransducerImplementation implementation;
274 static hfst::implementations::SfstTransducer sfst_interface;
277 static hfst::implementations::TropicalWeightTransducer
278 tropical_ofst_interface;
280 static hfst::implementations::LogWeightTransducer log_ofst_interface;
284 static hfst::implementations::FomaTransducer foma_interface;
286 static hfst::implementations::HfstOlTransducer hfst_ol_interface;
309 StringSet &missing_flags,
310 bool return_on_first_miss)
const;
339 unsigned int number_of_states()
const;
340 unsigned int number_of_arcs()
const;
354 unsigned int get_symbol_number(
const std::string &symbol);
357 std::vector<HfstTransducer*> extract_path_transducers();
397 const std::string &epsilon_symbol);
402 void print_alphabet();
482 const std::string& output_utf8_str,
545 HfstTransducer(
const std::string &isymbol,
const std::string &osymbol,
622 const std::string &epsilon_symbol,
unsigned int & linecount);
625 const std::string &epsilon_symbol);
628 const std::string &epsilon_symbol);
646 void set_name(
const std::string &name);
661 void set_property(
const std::string& property,
const std::string& value);
667 std::string
get_property(
const std::string& property)
const;
822 void write_in_att_format_number
823 (FILE * ofile,
bool write_weights=
true)
const;
835 bool write_weights=
true)
const;
847 void extract_paths(ExtractStringsCb& callback,
int cycles=-1)
const;
933 void extract_random_paths
936 void extract_random_paths_fd
943 void extract_paths_fd
944 (ExtractStringsCb& callback,
int cycles=-1,
bool filter_fd=
true)
const;
948 void extract_shortest_paths
951 bool extract_longest_paths
954 int longest_path_size(
bool obey_flags=
true)
const;
990 void extract_paths_fd
992 bool filter_fd=
true)
const;
1005 ssize_t limit = -1)
const;
1013 ssize_t limit = -1)
const;
1045 ssize_t limit = -1)
const;
1062 ssize_t limit = -1)
const;
1073 const std::string &s, ssize_t limit = -1)
const;
1085 const std::string &s, ssize_t limit = -1)
const;
1102 ssize_t limit = -1)
const;
1105 ssize_t limit = -1)
const;
1116 ssize_t limit = -1)
const;
1119 ssize_t limit = -1)
const;
1136 bool is_infinitely_ambiguous()
const ;
1242 bool harmonize=
true);
1255 bool invert=
false,
bool harmonize=
true);
1442 const std::string &new_symbol,
1443 bool input_side=
true,
1444 bool output_side=
true);
1585 void insert_freely_missing_flags_from
1597 bool insert_renamed_flags=
true);
1599 void insert_missing_symbols_to_alphabet_from(
const HfstTransducer &another,
bool only_special_symbols=
false);
1601 static bool is_special_symbol(
const std::string & symbol);
1605 bool check_for_missing_flags_in(
const HfstTransducer &another)
const;
1608 bool has_flag_diacritics(
void)
const;
1615 friend std::ostream& redirect(std::ostream &out,
const HfstTransducer &t);
1619 friend class HfstCompiler;
1620 friend class hfst::implementations::ConversionFunctions;
1621 friend class HfstGrammar;
1622 friend class xfst::XfstCompiler;
1634 std::ostream &redirect(std::ostream &out,
const HfstTransducer &t);
1640 enum ReplaceType {REPL_UP, REPL_DOWN, REPL_RIGHT, REPL_LEFT,
1641 REPL_DOWN_KARTTUNEN};
1642 enum TwolType {twol_right, twol_left, twol_both};
1645 HfstTransducer universal_fst
1647 HfstTransducer negation_fst
1650 HfstTransducer replace
1651 (HfstTransducer &t, ReplaceType repl_type,
bool optional,
1653 HfstTransducer replace_transducer
1654 (HfstTransducer &t, std::string lm, std::string rm,
1656 HfstTransducer replace_context
1657 (HfstTransducer &t, std::string m1, std::string m2,
1659 HfstTransducer replace_in_context
1664 HfstTransducer restriction
1666 StringPairSet &alphabet, TwolType twol_type,
int direction );
1793 HfstTransducer &mapping,
1804 HfstTransducer &mapping,
1809 HfstTransducer &mapping,
1821 HfstTransducer &mapping,
1833 HfstTransducer &mapping,
1842 HfstTransducer
replace_up(HfstTransducer &mapping,
1873 HfstTransducer &mapping,
1881 HfstTransducer &mapping,
1890 HfstTransducer &mapping,
1900 HfstTransducer &mapping,
1910 HfstTransducer &mapping,
1930 HfstTransducer &mapping,
1943 HfstTransducer &mapping,
1959 HfstTransducer &mapping,
1975 HfstTransducer &mapping,
1991 HfstTransducer &mapping,
2002 HfstTransducer &mapping,
2017 HfstTransducer &mapping,
2032 HfstTransducer &mapping,
2043 HfstTransducer &mapping,
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
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
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
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
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