diff options
author | Hieu Hoang <hieu@hoang.co.uk> | 2013-07-18 20:00:07 +0400 |
---|---|---|
committer | Hieu Hoang <hieu@hoang.co.uk> | 2013-07-18 20:00:07 +0400 |
commit | f81d7a446f1947fdd4f4ecc8874264555dfb66f9 (patch) | |
tree | 5667d0f17ab13603ee0e09b847d6e63e5cfe67c8 /moses/Sentence.cpp | |
parent | 415c5ab6938536b34ea4bfca8f4a2d91a75bc54e (diff) |
starting placeholder
Diffstat (limited to 'moses/Sentence.cpp')
-rw-r--r-- | moses/Sentence.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/moses/Sentence.cpp b/moses/Sentence.cpp index 2d28f6069..0ceb1db2a 100644 --- a/moses/Sentence.cpp +++ b/moses/Sentence.cpp @@ -121,15 +121,22 @@ int Sentence::Read(std::istream& in,const std::vector<FactorType>& factorOrder) //const StaticData &staticData = StaticData::Instance(); std::vector<XmlOption*> xmlOptionsList(0); std::vector< size_t > xmlWalls; + std::vector< std::pair<size_t, std::string> > placeholders; + if (staticData.GetXmlInputType() != XmlPassThrough) { - if (!ProcessAndStripXMLTags(line, xmlOptionsList, m_reorderingConstraint, xmlWalls, staticData.GetXmlBrackets().first, staticData.GetXmlBrackets().second)) { + if (!ProcessAndStripXMLTags(line, xmlOptionsList, m_reorderingConstraint, xmlWalls, placeholders, + staticData.GetXmlBrackets().first, staticData.GetXmlBrackets().second)) { const string msg("Unable to parse XML in line: " + line); TRACE_ERR(msg << endl); throw runtime_error(msg); } } + Phrase::CreateFromString(Input, factorOrder, line, factorDelimiter, NULL); + // placeholders + ProcessPlaceholders(placeholders); + if (staticData.IsChart()) { InitStartEndWord(); } @@ -194,6 +201,22 @@ void Sentence::InitStartEndWord() AddWord(endWord); } +void Sentence::ProcessPlaceholders(const std::vector< std::pair<size_t, std::string> > &placeholders) +{ + FactorType factorType = StaticData::Instance().GetPlaceholderFactor(); + if (factorType == NOT_FOUND) { + return; + } + + for (size_t i = 0; i < placeholders.size(); ++i) { + size_t pos = placeholders[i].first; + const string &str = placeholders[i].second; + const Factor *factor = FactorCollection::Instance().AddFactor(str); + Word &word = Phrase::GetWord(pos); + word[factorType] = factor; + } +} + TranslationOptionCollection* Sentence::CreateTranslationOptionCollection() const { |