Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'misc/pruneGeneration.h')
-rw-r--r--misc/pruneGeneration.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/misc/pruneGeneration.h b/misc/pruneGeneration.h
new file mode 100644
index 000000000..693c5f149
--- /dev/null
+++ b/misc/pruneGeneration.h
@@ -0,0 +1,45 @@
+#pragma once
+#include <vector>
+#include <string>
+
+class Rec
+{
+public:
+ float prob;
+ std::string line;
+
+ Rec(float aprob, const std::string &aline)
+ :prob(aprob)
+ ,line(aline)
+ {}
+
+ inline bool operator< (const Rec &compare) const {
+ return prob < compare.prob;
+ }
+};
+
+////////////////////////////////////////////////////////////
+
+void Output(int limit, std::vector<Rec> &records);
+void Prune(int limit, std::vector<Rec> &records);
+
+////////////////////////////////////////////////////////////
+inline void Tokenize(std::vector<std::string> &output
+ , const std::string& str
+ , const std::string& delimiters = " \t")
+{
+ // Skip delimiters at beginning.
+ std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
+ // Find first "non-delimiter".
+ std::string::size_type pos = str.find_first_of(delimiters, lastPos);
+
+ while (std::string::npos != pos || std::string::npos != lastPos) {
+ // Found a token, add it to the vector.
+ output.push_back(str.substr(lastPos, pos - lastPos));
+ // Skip delimiters. Note the "not_of"
+ lastPos = str.find_first_not_of(delimiters, pos);
+ // Find next "non-delimiter"
+ pos = str.find_first_of(delimiters, lastPos);
+ }
+}
+