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(AllOptions const& opts,
00040 const std::vector<FactorType> &input,
00041 const std::vector<FactorType> &output,
00042 const std::string &inFile,
00043 size_t tableLimit,
00044 RuleTableTrie &);
00045
00046 private:
00047 struct LineReader {
00048 LineReader(std::istream &input) : m_input(input), m_lineNum(0) {}
00049 void ReadLine() {
00050 std::getline(m_input, m_line);
00051
00052 ++m_lineNum;
00053 }
00054 std::istream &m_input;
00055 std::string m_line;
00056 size_t m_lineNum;
00057 };
00058
00059 void LoadVocabularySection(LineReader &,
00060 const std::vector<FactorType> &,
00061 std::vector<Word> &);
00062
00063 void LoadPhraseSection(LineReader &,
00064 const std::vector<Word> &,
00065 std::vector<Phrase> &,
00066 std::vector<size_t> &);
00067
00068 void LoadAlignmentSection(LineReader &,
00069 std::vector<const AlignmentInfo *> &,
00070 std::vector<Phrase> &);
00071
00072 bool LoadRuleSection(LineReader &,
00073 const std::vector<Word> &,
00074 const std::vector<Phrase> &,
00075 const std::vector<Phrase> &,
00076 const std::vector<size_t> &,
00077 const std::vector<const AlignmentInfo *> &,
00078 RuleTableTrie &ruleTable);
00079
00080
00081
00082 void FindTokens(std::vector<size_t> &output, const std::string &str) const {
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 }