10 #ifndef _EXTRACT_STRINGS_H_
11 #define _EXTRACT_STRINGS_H_
28 using std::stringstream;
39 template<
class W>
class WeightedPath
60 WeightedPath(
const std::string &is,
const std::string &os,W w)
61 { weight = w; istring = is; ostring = os; is_spv_in_use=
false; }
63 bool operator< (
const WeightedPath &another)
const
64 {
if (weight == another.weight)
65 {
if (istring == another.istring)
66 {
if (ostring == another.ostring)
68 if (not is_spv_in_use)
70 unsigned int common_length
71 = (spv.size()<another.spv.size())?
72 spv.size() : another.spv.size();
74 for (
unsigned int i=0; i<common_length; i++) {
75 if (spv[i].first == another.spv[i].first)
76 {
if (spv[i].second == another.spv[i].second)
78 return (spv[i].second < another.spv[i].second); }
79 return (spv[i].first < another.spv[i].first);
82 return (spv.size() < another.spv.size());
84 return ostring < another.ostring; }
85 return istring < another.istring; }
86 return weight < another.weight; }
88 std::string to_string(
void)
const
89 { stringstream s_stream(ios::out);
90 s_stream << istring <<
":" << ostring <<
"\t" << weight;
92 return s_stream.str();
95 WeightedPath<W> &reverse(
void)
96 {
for(
size_t i = 0; i < (istring.size() / 2); ++i)
97 {
char c = istring[i];
98 istring[i] = istring[istring.size() - i - 1];
99 istring[istring.size() - i - 1] = c; }
101 for(
size_t i = 0; i < (ostring.size() / 2); ++i)
102 {
char c = ostring[i];
103 ostring[i] = ostring[ostring.size() - i - 1];
104 ostring[ostring.size() - i - 1] = c; }
107 WeightedPath &add(
const WeightedPath &another,
bool in_front=
true)
110 istring = another.istring + istring;
111 ostring = another.ostring + ostring;
112 weight = weight + another.weight;
117 istring = istring + another.istring;
118 ostring = ostring + another.ostring;
119 weight = weight + another.weight;
123 void operator=(
const WeightedPath &another)
124 {
if (
this == &another) {
return; }
125 this->istring = another.istring;
126 this->ostring = another.ostring;
127 this->weight = another.weight; }
140 template<
class W>
class WeightedPaths
144 typedef std::vector< WeightedPath<W> > Vector;
146 typedef std::set< WeightedPath<W> > Set;
148 static void add(Vector &v,WeightedPath<W> &s)
150 for (
typename Vector::iterator it = v.begin(); it != v.end(); ++it)
151 { it->add(s,
false); }
154 static void add(WeightedPath<W> &s,Vector &v)
156 for (
typename Vector::iterator it = v.begin(); it != v.end(); ++it)
160 static void cat(Vector &v,
const Vector &another_v)
162 v.insert(v.end(),another_v.begin(),another_v.end());
165 static void reverse_strings(Vector &v)
167 for (
typename Vector::iterator it = v.begin(); it != v.end(); ++it)
173 class ExtractStringsCb
181 RetVal(
bool s,
bool p): continueSearch(s), continuePath(p) {}
182 void operator=(
const RetVal& o)
184 continueSearch = o.continueSearch;
185 continuePath = o.continuePath;
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::pair< float, StringPairVector > HfstTwoLevelPath
A path of two level of arcs with collected weight.
Definition: HfstDataTypes.h:107
Typedefs and functions for symbols, symbol pairs and sets of symbols.