13 #ifndef _EXTRACT_STRINGS_H_
14 #define _EXTRACT_STRINGS_H_
31 using std::stringstream;
42 template<
class W>
class WeightedPath
63 WeightedPath(
const std::string &is,
const std::string &os,W w)
64 { weight = w; istring = is; ostring = os; is_spv_in_use=
false; }
66 bool operator< (
const WeightedPath &another)
const
67 {
if (weight == another.weight)
68 {
if (istring == another.istring)
69 {
if (ostring == another.ostring)
71 if (not is_spv_in_use)
73 unsigned int common_length
74 = (spv.size()<another.spv.size())?
75 spv.size() : another.spv.size();
77 for (
unsigned int i=0; i<common_length; i++) {
78 if (spv[i].first == another.spv[i].first)
79 {
if (spv[i].second == another.spv[i].second)
81 return (spv[i].second < another.spv[i].second); }
82 return (spv[i].first < another.spv[i].first);
85 return (spv.size() < another.spv.size());
87 return ostring < another.ostring; }
88 return istring < another.istring; }
89 return weight < another.weight; }
91 std::string to_string(
void)
const
92 { stringstream s_stream(ios::out);
93 s_stream << istring <<
":" << ostring <<
"\t" << weight;
95 return s_stream.str();
98 WeightedPath<W> &reverse(
void)
99 {
for(
size_t i = 0; i < (istring.size() / 2); ++i)
100 {
char c = istring[i];
101 istring[i] = istring[istring.size() - i - 1];
102 istring[istring.size() - i - 1] = c; }
104 for(
size_t i = 0; i < (ostring.size() / 2); ++i)
105 {
char c = ostring[i];
106 ostring[i] = ostring[ostring.size() - i - 1];
107 ostring[ostring.size() - i - 1] = c; }
110 WeightedPath &add(
const WeightedPath &another,
bool in_front=
true)
113 istring = another.istring + istring;
114 ostring = another.ostring + ostring;
115 weight = weight + another.weight;
120 istring = istring + another.istring;
121 ostring = ostring + another.ostring;
122 weight = weight + another.weight;
126 void operator=(
const WeightedPath &another)
127 {
if (
this == &another) {
return; }
128 this->istring = another.istring;
129 this->ostring = another.ostring;
130 this->weight = another.weight; }
143 template<
class W>
class WeightedPaths
147 typedef std::vector< WeightedPath<W> > Vector;
149 typedef std::set< WeightedPath<W> > Set;
151 static void add(Vector &v,WeightedPath<W> &s)
153 for (
typename Vector::iterator it = v.begin(); it != v.end(); ++it)
154 { it->add(s,
false); }
157 static void add(WeightedPath<W> &s,Vector &v)
159 for (
typename Vector::iterator it = v.begin(); it != v.end(); ++it)
163 static void cat(Vector &v,
const Vector &another_v)
165 v.insert(v.end(),another_v.begin(),another_v.end());
168 static void reverse_strings(Vector &v)
170 for (
typename Vector::iterator it = v.begin(); it != v.end(); ++it)
176 class ExtractStringsCb
184 RetVal(
bool s,
bool p): continueSearch(s), continuePath(p) {}
185 void operator=(
const RetVal& o)
187 continueSearch = o.continueSearch;
188 continuePath = o.continuePath;
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::pair< float, StringPairVector > HfstTwoLevelPath
A path of two level of arcs with collected weight.
Definition: HfstDataTypes.h:108
Typedefs and functions for symbols, symbol pairs and sets of symbols.