diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2015-01-04 14:24:33 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2015-01-04 14:24:33 +0300 |
commit | b526efea2361f936a8a04c3e1ee1a5dd5b94982b (patch) | |
tree | 870a60a8ddecb7788ff46f192db72e2b6ba0fcb7 /moses/IOWrapper.cpp | |
parent | cec03c949ecaefbb34038df18e4d477317ee8a40 (diff) |
gut IOWrapper
Diffstat (limited to 'moses/IOWrapper.cpp')
-rw-r--r-- | moses/IOWrapper.cpp | 144 |
1 files changed, 0 insertions, 144 deletions
diff --git a/moses/IOWrapper.cpp b/moses/IOWrapper.cpp index e69bb3542..a5736fb31 100644 --- a/moses/IOWrapper.cpp +++ b/moses/IOWrapper.cpp @@ -97,8 +97,6 @@ IOWrapper::IOWrapper() const StaticData &staticData = StaticData::Instance(); m_inputFactorOrder = &staticData.GetInputFactorOrder(); - m_outputFactorOrder = &staticData.GetOutputFactorOrder(); - m_inputFactorUsed = FactorMask(*m_inputFactorOrder); size_t nBestSize = staticData.GetNBestSize(); string nBestFilePath = staticData.GetNBestFilePath(); @@ -258,148 +256,6 @@ GetInput(InputType* inputType) } } -void IOWrapper::OutputTranslationOptions(std::ostream &out, ApplicationContext &applicationContext, const ChartHypothesis *hypo, const Sentence &sentence, long translationId) -{ - if (hypo != NULL) { - OutputTranslationOption(out, applicationContext, hypo, sentence, translationId); - out << std::endl; - } - - // recursive - const std::vector<const ChartHypothesis*> &prevHypos = hypo->GetPrevHypos(); - std::vector<const ChartHypothesis*>::const_iterator iter; - for (iter = prevHypos.begin(); iter != prevHypos.end(); ++iter) { - const ChartHypothesis *prevHypo = *iter; - OutputTranslationOptions(out, applicationContext, prevHypo, sentence, translationId); - } -} - - -void IOWrapper::OutputTranslationOptions(std::ostream &out, ApplicationContext &applicationContext, const search::Applied *applied, const Sentence &sentence, long translationId) -{ - if (applied != NULL) { - OutputTranslationOption(out, applicationContext, applied, sentence, translationId); - out << std::endl; - } - - // recursive - const search::Applied *child = applied->Children(); - for (size_t i = 0; i < applied->GetArity(); i++) { - OutputTranslationOptions(out, applicationContext, child++, sentence, translationId); - } -} - -void IOWrapper::OutputTranslationOption(std::ostream &out, ApplicationContext &applicationContext, const ChartHypothesis *hypo, const Sentence &sentence, long translationId) -{ - ReconstructApplicationContext(*hypo, sentence, applicationContext); - out << "Trans Opt " << translationId - << " " << hypo->GetCurrSourceRange() - << ": "; - WriteApplicationContext(out, applicationContext); - out << ": " << hypo->GetCurrTargetPhrase().GetTargetLHS() - << "->" << hypo->GetCurrTargetPhrase() - << " " << hypo->GetTotalScore() << hypo->GetScoreBreakdown(); -} - -void IOWrapper::OutputTranslationOption(std::ostream &out, ApplicationContext &applicationContext, const search::Applied *applied, const Sentence &sentence, long translationId) -{ - ReconstructApplicationContext(applied, sentence, applicationContext); - const TargetPhrase &phrase = *static_cast<const TargetPhrase*>(applied->GetNote().vp); - out << "Trans Opt " << translationId - << " " << applied->GetRange() - << ": "; - WriteApplicationContext(out, applicationContext); - out << ": " << phrase.GetTargetLHS() - << "->" << phrase - << " " << applied->GetScore(); // << hypo->GetScoreBreakdown() TODO: missing in incremental search hypothesis -} - -// Given a hypothesis and sentence, reconstructs the 'application context' -- -// the source RHS symbols of the SCFG rule that was applied, plus their spans. -void IOWrapper::ReconstructApplicationContext(const ChartHypothesis &hypo, - const Sentence &sentence, - ApplicationContext &context) -{ - context.clear(); - const std::vector<const ChartHypothesis*> &prevHypos = hypo.GetPrevHypos(); - std::vector<const ChartHypothesis*>::const_iterator p = prevHypos.begin(); - std::vector<const ChartHypothesis*>::const_iterator end = prevHypos.end(); - const WordsRange &span = hypo.GetCurrSourceRange(); - size_t i = span.GetStartPos(); - while (i <= span.GetEndPos()) { - if (p == end || i < (*p)->GetCurrSourceRange().GetStartPos()) { - // Symbol is a terminal. - const Word &symbol = sentence.GetWord(i); - context.push_back(std::make_pair(symbol, WordsRange(i, i))); - ++i; - } else { - // Symbol is a non-terminal. - const Word &symbol = (*p)->GetTargetLHS(); - const WordsRange &range = (*p)->GetCurrSourceRange(); - context.push_back(std::make_pair(symbol, range)); - i = range.GetEndPos()+1; - ++p; - } - } -} - -// Given a hypothesis and sentence, reconstructs the 'application context' -- -// the source RHS symbols of the SCFG rule that was applied, plus their spans. -void IOWrapper::ReconstructApplicationContext(const search::Applied *applied, - const Sentence &sentence, - ApplicationContext &context) -{ - context.clear(); - const WordsRange &span = applied->GetRange(); - const search::Applied *child = applied->Children(); - size_t i = span.GetStartPos(); - size_t j = 0; - - while (i <= span.GetEndPos()) { - if (j == applied->GetArity() || i < child->GetRange().GetStartPos()) { - // Symbol is a terminal. - const Word &symbol = sentence.GetWord(i); - context.push_back(std::make_pair(symbol, WordsRange(i, i))); - ++i; - } else { - // Symbol is a non-terminal. - const Word &symbol = static_cast<const TargetPhrase*>(child->GetNote().vp)->GetTargetLHS(); - const WordsRange &range = child->GetRange(); - context.push_back(std::make_pair(symbol, range)); - i = range.GetEndPos()+1; - ++child; - ++j; - } - } -} - -// Emulates the old operator<<(ostream &, const DottedRule &) function. The -// output format is a bit odd (reverse order and double spacing between symbols) -// but there are scripts and tools that expect the output of -T to look like -// that. -void IOWrapper::WriteApplicationContext(std::ostream &out, - const ApplicationContext &context) -{ - assert(!context.empty()); - ApplicationContext::const_reverse_iterator p = context.rbegin(); - while (true) { - out << p->second << "=" << p->first << " "; - if (++p == context.rend()) { - break; - } - out << " "; - } -} - -void IOWrapper::Backtrack(const Hypothesis *hypo) -{ - - if (hypo->GetPrevHypo() != NULL) { - VERBOSE(3,hypo->GetId() << " <= "); - Backtrack(hypo->GetPrevHypo()); - } -} - bool IOWrapper::ReadInput(InputTypeEnum inputType, InputType*& source) { delete source; |