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