HFST - Helsinki Finite-State Transducer Technology API  version 3.7.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HfstSymbolDefs.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 Public 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 
13 #ifndef _SYMBOL_DEFS_H_
14 #define _SYMBOL_DEFS_H_
15 #include <vector>
16 #include <string>
17 #include <map>
18 #include <set>
19 
24 /* Macros that can be used instead of hfsT::internal_epsilon etc
25  if there are problems with variable initialization. */
26 #define INTERNAL_EPSILON "@_EPSILON_SYMBOL_@"
27 #define INTERNAL_UNKNOWN "@_UNKNOWN_SYMBOL_@"
28 #define INTERNAL_IDENTITY "@_IDENTITY_SYMBOL_@"
29 #define INTERNAL_DEFAULT "@_DEFAULT_SYMBOL_@"
30 
31 
32 namespace hfst
33 {
34 
60  typedef std::string String;
61 
62  /* A set of strings. */
63  typedef std::set<String> StringSet;
64 
65  typedef std::vector<String> StringVector;
66 
71  typedef std::pair<String, String> StringPair;
72 
76  typedef std::vector<StringPair> StringPairVector;
77 
83  typedef std::set<StringPair> StringPairSet;
84 
89  typedef std::map<String, String> HfstSymbolSubstitutions;
90 
95  typedef std::map<StringPair, StringPair> HfstSymbolPairSubstitutions;
96 
97  typedef std::pair<float, StringPairVector> HfstTwoLevelPath;
98  typedef std::set<HfstTwoLevelPath> HfstTwoLevelPaths;
99 
100 /* The internal representations */
101  const std::string internal_epsilon = "@_EPSILON_SYMBOL_@";
102  const std::string internal_unknown = "@_UNKNOWN_SYMBOL_@";
103  const std::string internal_identity = "@_IDENTITY_SYMBOL_@";
104  const std::string internal_default = "@_DEFAULT_SYMBOL_@";
105 
106  /* Check whether a string is equal to reserved internal representation. */
107  bool is_epsilon(std::string const & str);
108  bool is_unknown(std::string const & str);
109  bool is_identity(std::string const & str);
110  bool is_default(std::string const & str);
111  bool is_epsilon(const char * str);
112  bool is_unknown(const char * str);
113  bool is_identity(const char * str);
114  bool is_default(const char * str);
115 
116  /* For internal use */
117  typedef std::pair<unsigned int, unsigned int> NumberPair;
118  typedef std::vector<NumberPair> NumberPairVector;
119  typedef std::set<NumberPair> NumberPairSet;
120  typedef std::map<String,unsigned int> StringNumberMap;
121  typedef std::map<unsigned int,unsigned int> NumberNumberMap;
122 
123  namespace symbols {
124  void collect_unknown_sets(StringSet &s1, StringSet &unknown1,
125  StringSet &s2, StringSet &unknown2);
126  int longest_path_length(const hfst::HfstTwoLevelPaths & paths, bool equally_long=false);
127  hfst::HfstTwoLevelPaths get_longest_paths(const hfst::HfstTwoLevelPaths & paths);
128  StringVector to_string_vector(const hfst::HfstTwoLevelPath & path);
129  std::string to_string(const StringVector & sv, bool spaces=false);
130  std::string to_string(const StringPairVector & sv, bool spaces=false);
131  hfst::HfstTwoLevelPaths remove_flags(const hfst::HfstTwoLevelPaths & paths);
132  hfst::HfstTwoLevelPath remove_flags(const hfst::HfstTwoLevelPath & path);
133  StringPairSet to_string_pair_set(const StringSet & ss);
134  StringPairVector remove_flags(const StringPairVector &v);
135  StringVector remove_flags(const StringVector &v);
136  }
137 }
138 #endif
std::pair< String, String > StringPair
A symbol pair in a transition.
Definition: HfstSymbolDefs.h:71
std::string String
A UTF-8 symbol in a transition.
Definition: HfstSymbolDefs.h:60
std::vector< std::pair< std::string, std::string > > StringPairVector
A vector of string pairs.
Definition: HfstDataTypes.h:106
std::set< HfstTwoLevelPath > HfstTwoLevelPaths
A set of two-level weighted paths.
Definition: HfstDataTypes.h:110
std::set< StringPair > StringPairSet
A set of symbol pairs used in substituting symbol pairs and in rule functions.
Definition: HfstSymbolDefs.h:83
std::map< String, String > HfstSymbolSubstitutions
A map of substitutions used when performing multiple symbol-to-symbol substitutions.
Definition: HfstSymbolDefs.h:89
std::pair< float, StringPairVector > HfstTwoLevelPath
A path of two level of arcs with collected weight.
Definition: HfstDataTypes.h:108
std::map< StringPair, StringPair > HfstSymbolPairSubstitutions
A map of substitutions used when performing multiple symbol pair-to-symbol pair substitutions.
Definition: HfstSymbolDefs.h:95
std::vector< std::string > StringVector
A vector of strings.
Definition: HfstDataTypes.h:88