00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #pragma once
00021
00022 #include "moses/Phrase.h"
00023 #include "moses/Word.h"
00024 #include "moses/TypeDef.h"
00025 #include "Loader.h"
00026
00027 #include <istream>
00028 #include <string>
00029 #include <vector>
00030
00031 namespace Moses
00032 {
00033 class RuleTableTrie;
00034
00036 class RuleTableLoaderCompact : public RuleTableLoader
00037 {
00038 public:
00039 bool Load(const std::vector<FactorType> &input,
00040 const std::vector<FactorType> &output,
00041 const std::string &inFile,
00042 size_t tableLimit,
00043 RuleTableTrie &);
00044
00045 private:
00046 struct LineReader {
00047 LineReader(std::istream &input) : m_input(input), m_lineNum(0) {}
00048 void ReadLine() {
00049 std::getline(m_input, m_line);
00050
00051 ++m_lineNum;
00052 }
00053 std::istream &m_input;
00054 std::string m_line;
00055 size_t m_lineNum;
00056 };
00057
00058 void LoadVocabularySection(LineReader &,
00059 const std::vector<FactorType> &,
00060 std::vector<Word> &);
00061
00062 void LoadPhraseSection(LineReader &,
00063 const std::vector<Word> &,
00064 std::vector<Phrase> &,
00065 std::vector<size_t> &);
00066
00067 void LoadAlignmentSection(LineReader &,
00068 std::vector<const AlignmentInfo *> &,
00069 std::vector<Phrase> &);
00070
00071 bool LoadRuleSection(LineReader &,
00072 const std::vector<Word> &,
00073 const std::vector<Phrase> &,
00074 const std::vector<Phrase> &,
00075 const std::vector<size_t> &,
00076 const std::vector<const AlignmentInfo *> &,
00077 RuleTableTrie &ruleTable);
00078
00079
00080
00081 void FindTokens(std::vector<size_t> &output, const std::string &str) const
00082 {
00083
00084 size_t lastPos = str.find_first_not_of(' ', 0);
00085
00086 size_t pos = str.find_first_of(' ', lastPos);
00087
00088 while (std::string::npos != pos || std::string::npos != lastPos) {
00089
00090 output.push_back(lastPos);
00091
00092 lastPos = str.find_first_not_of(' ', pos);
00093
00094 pos = str.find_first_of(' ', lastPos);
00095 }
00096 }
00097 };
00098
00099 }