| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #pragma once |
|
|
| #include "moses/Phrase.h" |
| #include "moses/Word.h" |
| #include "moses/TypeDef.h" |
| #include "Loader.h" |
|
|
| #include <istream> |
| #include <string> |
| #include <vector> |
|
|
| namespace Moses |
| { |
| class RuleTableTrie; |
|
|
| |
| class RuleTableLoaderCompact : public RuleTableLoader |
| { |
| public: |
| bool Load(AllOptions const& opts, |
| const std::vector<FactorType> &input, |
| const std::vector<FactorType> &output, |
| const std::string &inFile, |
| size_t tableLimit, |
| RuleTableTrie &); |
|
|
| private: |
| struct LineReader { |
| LineReader(std::istream &input) : m_input(input), m_lineNum(0) {} |
| void ReadLine() { |
| std::getline(m_input, m_line); |
| |
| ++m_lineNum; |
| } |
| std::istream &m_input; |
| std::string m_line; |
| size_t m_lineNum; |
| }; |
|
|
| void LoadVocabularySection(LineReader &, |
| const std::vector<FactorType> &, |
| std::vector<Word> &); |
|
|
| void LoadPhraseSection(LineReader &, |
| const std::vector<Word> &, |
| std::vector<Phrase> &, |
| std::vector<size_t> &); |
|
|
| void LoadAlignmentSection(LineReader &, |
| std::vector<const AlignmentInfo *> &, |
| std::vector<Phrase> &); |
|
|
| bool LoadRuleSection(LineReader &, |
| const std::vector<Word> &, |
| const std::vector<Phrase> &, |
| const std::vector<Phrase> &, |
| const std::vector<size_t> &, |
| const std::vector<const AlignmentInfo *> &, |
| RuleTableTrie &ruleTable); |
|
|
| |
| |
| void FindTokens(std::vector<size_t> &output, const std::string &str) const { |
| |
| size_t lastPos = str.find_first_not_of(' ', 0); |
| |
| size_t pos = str.find_first_of(' ', lastPos); |
|
|
| while (std::string::npos != pos || std::string::npos != lastPos) { |
| |
| output.push_back(lastPos); |
| |
| lastPos = str.find_first_not_of(' ', pos); |
| |
| pos = str.find_first_of(' ', lastPos); |
| } |
| } |
| }; |
|
|
| } |
|
|