Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHieu Hoang <hieuhoang@gmail.com>2014-12-04 17:43:23 +0300
committerHieu Hoang <hieuhoang@gmail.com>2014-12-04 17:43:23 +0300
commit80eada0640dc3590a347851da0366636f6701742 (patch)
tree700d73d2a6e3ec02228f4daa8d555d75aba6d0f7 /moses/IOWrapper.cpp
parent5e4b27412a0db2ded959156bba42e826dac91b50 (diff)
delete unused methods in IOWrapper
Diffstat (limited to 'moses/IOWrapper.cpp')
-rw-r--r--moses/IOWrapper.cpp395
1 files changed, 0 insertions, 395 deletions
diff --git a/moses/IOWrapper.cpp b/moses/IOWrapper.cpp
index d8910dc83..ea7846e48 100644
--- a/moses/IOWrapper.cpp
+++ b/moses/IOWrapper.cpp
@@ -635,110 +635,7 @@ void IOWrapper::OutputSurface(std::ostream &out, const Phrase &phrase, const std
}
}
-void IOWrapper::OutputAlignment(size_t translationId , const Moses::ChartHypothesis *hypo)
-{
- ostringstream out;
-
- if (hypo) {
- Alignments retAlign;
- OutputAlignment(retAlign, hypo, 0);
-
- // output alignments
- Alignments::const_iterator iter;
- for (iter = retAlign.begin(); iter != retAlign.end(); ++iter) {
- const pair<size_t, size_t> &alignPoint = *iter;
- out << alignPoint.first << "-" << alignPoint.second << " ";
- }
- }
- out << endl;
-
- m_alignmentInfoCollector->Write(translationId, out.str());
-}
-
-size_t IOWrapper::OutputAlignment(Alignments &retAlign, const Moses::ChartHypothesis *hypo, size_t startTarget)
-{
- size_t totalTargetSize = 0;
- size_t startSource = hypo->GetCurrSourceRange().GetStartPos();
-
- const TargetPhrase &tp = hypo->GetCurrTargetPhrase();
-
- size_t thisSourceSize = CalcSourceSize(hypo);
-
- // position of each terminal word in translation rule, irrespective of alignment
- // if non-term, number is undefined
- vector<size_t> sourceOffsets(thisSourceSize, 0);
- vector<size_t> targetOffsets(tp.GetSize(), 0);
-
- const vector<const ChartHypothesis*> &prevHypos = hypo->GetPrevHypos();
-
- const AlignmentInfo &aiNonTerm = hypo->GetCurrTargetPhrase().GetAlignNonTerm();
- vector<size_t> sourceInd2pos = aiNonTerm.GetSourceIndex2PosMap();
- const AlignmentInfo::NonTermIndexMap &targetPos2SourceInd = aiNonTerm.GetNonTermIndexMap();
- UTIL_THROW_IF2(sourceInd2pos.size() != prevHypos.size(), "Error");
-
- size_t targetInd = 0;
- for (size_t targetPos = 0; targetPos < tp.GetSize(); ++targetPos) {
- if (tp.GetWord(targetPos).IsNonTerminal()) {
- UTIL_THROW_IF2(targetPos >= targetPos2SourceInd.size(), "Error");
- size_t sourceInd = targetPos2SourceInd[targetPos];
- size_t sourcePos = sourceInd2pos[sourceInd];
-
- const ChartHypothesis *prevHypo = prevHypos[sourceInd];
-
- // calc source size
- size_t sourceSize = prevHypo->GetCurrSourceRange().GetNumWordsCovered();
- sourceOffsets[sourcePos] = sourceSize;
-
- // calc target size.
- // Recursively look thru child hypos
- size_t currStartTarget = startTarget + totalTargetSize;
- size_t targetSize = OutputAlignment(retAlign, prevHypo, currStartTarget);
- targetOffsets[targetPos] = targetSize;
-
- totalTargetSize += targetSize;
- ++targetInd;
- } else {
- ++totalTargetSize;
- }
- }
-
- // convert position within translation rule to absolute position within
- // source sentence / output sentence
- ShiftOffsets(sourceOffsets, startSource);
- ShiftOffsets(targetOffsets, startTarget);
-
- // get alignments from this hypo
- const AlignmentInfo &aiTerm = hypo->GetCurrTargetPhrase().GetAlignTerm();
-
- // add to output arg, offsetting by source & target
- AlignmentInfo::const_iterator iter;
- for (iter = aiTerm.begin(); iter != aiTerm.end(); ++iter) {
- const std::pair<size_t,size_t> &align = *iter;
- size_t relSource = align.first;
- size_t relTarget = align.second;
- size_t absSource = sourceOffsets[relSource];
- size_t absTarget = targetOffsets[relTarget];
-
- pair<size_t, size_t> alignPoint(absSource, absTarget);
- pair<Alignments::iterator, bool> ret = retAlign.insert(alignPoint);
- UTIL_THROW_IF2(!ret.second, "Error");
-
- }
-
- return totalTargetSize;
-}
-
-size_t IOWrapper::CalcSourceSize(const Moses::ChartHypothesis *hypo)
-{
- size_t ret = hypo->GetCurrSourceRange().GetNumWordsCovered();
- const std::vector<const ChartHypothesis*> &prevHypos = hypo->GetPrevHypos();
- for (size_t i = 0; i < prevHypos.size(); ++i) {
- size_t childSize = prevHypos[i]->GetCurrSourceRange().GetNumWordsCovered();
- ret -= (childSize - 1);
- }
- return ret;
-}
//DIMw
void IOWrapper::OutputDetailedAllTranslationReport(
@@ -785,145 +682,6 @@ void IOWrapper::OutputUnknowns(const std::vector<Moses::Phrase*> &unknowns,
m_unknownsCollector->Write(translationId, out.str());
}
-void IOWrapper::OutputNBestList(const ChartKBestExtractor::KBestVec &nBestList,
- long translationId)
-{
- std::ostringstream out;
-
- if (m_nBestOutputCollector->OutputIsCout()) {
- // Set precision only if we're writing the n-best list to cout. This is to
- // preserve existing behaviour, but should probably be done either way.
- FixPrecision(out);
- }
-
- bool includeWordAlignment =
- StaticData::Instance().PrintAlignmentInfoInNbest();
-
- bool PrintNBestTrees = StaticData::Instance().PrintNBestTrees();
-
- for (ChartKBestExtractor::KBestVec::const_iterator p = nBestList.begin();
- p != nBestList.end(); ++p) {
- const ChartKBestExtractor::Derivation &derivation = **p;
-
- // get the derivation's target-side yield
- Phrase outputPhrase = ChartKBestExtractor::GetOutputPhrase(derivation);
-
- // delete <s> and </s>
- UTIL_THROW_IF2(outputPhrase.GetSize() < 2,
- "Output phrase should have contained at least 2 words (beginning and end-of-sentence)");
- outputPhrase.RemoveWord(0);
- outputPhrase.RemoveWord(outputPhrase.GetSize() - 1);
-
- // print the translation ID, surface factors, and scores
- out << translationId << " ||| ";
- OutputSurface(out, outputPhrase, *m_outputFactorOrder, false);
- out << " ||| ";
- OutputAllFeatureScores(derivation.scoreBreakdown, out);
- out << " ||| " << derivation.score;
-
- // optionally, print word alignments
- if (includeWordAlignment) {
- out << " ||| ";
- Alignments align;
- OutputAlignmentNBest(align, derivation, 0);
- for (Alignments::const_iterator q = align.begin(); q != align.end();
- ++q) {
- out << q->first << "-" << q->second << " ";
- }
- }
-
- // optionally, print tree
- if (PrintNBestTrees) {
- TreePointer tree = ChartKBestExtractor::GetOutputTree(derivation);
- out << " ||| " << tree->GetString();
- }
-
- out << std::endl;
- }
-
- assert(m_nBestOutputCollector);
- m_nBestOutputCollector->Write(translationId, out.str());
-}
-
-size_t IOWrapper::OutputAlignmentNBest(
- Alignments &retAlign,
- const Moses::ChartKBestExtractor::Derivation &derivation,
- size_t startTarget)
-{
- const ChartHypothesis &hypo = derivation.edge.head->hypothesis;
-
- size_t totalTargetSize = 0;
- size_t startSource = hypo.GetCurrSourceRange().GetStartPos();
-
- const TargetPhrase &tp = hypo.GetCurrTargetPhrase();
-
- size_t thisSourceSize = CalcSourceSize(&hypo);
-
- // position of each terminal word in translation rule, irrespective of alignment
- // if non-term, number is undefined
- vector<size_t> sourceOffsets(thisSourceSize, 0);
- vector<size_t> targetOffsets(tp.GetSize(), 0);
-
- const AlignmentInfo &aiNonTerm = hypo.GetCurrTargetPhrase().GetAlignNonTerm();
- vector<size_t> sourceInd2pos = aiNonTerm.GetSourceIndex2PosMap();
- const AlignmentInfo::NonTermIndexMap &targetPos2SourceInd = aiNonTerm.GetNonTermIndexMap();
-
- UTIL_THROW_IF2(sourceInd2pos.size() != derivation.subderivations.size(),
- "Error");
-
- size_t targetInd = 0;
- for (size_t targetPos = 0; targetPos < tp.GetSize(); ++targetPos) {
- if (tp.GetWord(targetPos).IsNonTerminal()) {
- UTIL_THROW_IF2(targetPos >= targetPos2SourceInd.size(), "Error");
- size_t sourceInd = targetPos2SourceInd[targetPos];
- size_t sourcePos = sourceInd2pos[sourceInd];
-
- const Moses::ChartKBestExtractor::Derivation &subderivation =
- *derivation.subderivations[sourceInd];
-
- // calc source size
- size_t sourceSize = subderivation.edge.head->hypothesis.GetCurrSourceRange().GetNumWordsCovered();
- sourceOffsets[sourcePos] = sourceSize;
-
- // calc target size.
- // Recursively look thru child hypos
- size_t currStartTarget = startTarget + totalTargetSize;
- size_t targetSize = OutputAlignmentNBest(retAlign, subderivation,
- currStartTarget);
- targetOffsets[targetPos] = targetSize;
-
- totalTargetSize += targetSize;
- ++targetInd;
- } else {
- ++totalTargetSize;
- }
- }
-
- // convert position within translation rule to absolute position within
- // source sentence / output sentence
- ShiftOffsets(sourceOffsets, startSource);
- ShiftOffsets(targetOffsets, startTarget);
-
- // get alignments from this hypo
- const AlignmentInfo &aiTerm = hypo.GetCurrTargetPhrase().GetAlignTerm();
-
- // add to output arg, offsetting by source & target
- AlignmentInfo::const_iterator iter;
- for (iter = aiTerm.begin(); iter != aiTerm.end(); ++iter) {
- const std::pair<size_t,size_t> &align = *iter;
- size_t relSource = align.first;
- size_t relTarget = align.second;
- size_t absSource = sourceOffsets[relSource];
- size_t absTarget = targetOffsets[relTarget];
-
- pair<size_t, size_t> alignPoint(absSource, absTarget);
- pair<Alignments::iterator, bool> ret = retAlign.insert(alignPoint);
- UTIL_THROW_IF2(!ret.second, "Error");
- }
-
- return totalTargetSize;
-}
-
//////////////////////////////////////////////////////////////////////////
/***
* print surface factor only for the given phrase
@@ -1295,159 +1053,6 @@ void IOWrapper::OutputBestHypo(const Syntax::SHyperedge *best,
m_singleBestOutputCollector->Write(translationId, out.str());
}
-void IOWrapper::OutputNBestList(
- const Syntax::KBestExtractor::KBestVec &nBestList, long translationId)
-{
- std::ostringstream out;
-
- if (m_nBestOutputCollector->OutputIsCout()) {
- // Set precision only if we're writing the n-best list to cout. This is to
- // preserve existing behaviour, but should probably be done either way.
- FixPrecision(out);
- }
-
- bool includeWordAlignment =
- StaticData::Instance().PrintAlignmentInfoInNbest();
-
- bool PrintNBestTrees = StaticData::Instance().PrintNBestTrees();
-
- for (Syntax::KBestExtractor::KBestVec::const_iterator p = nBestList.begin();
- p != nBestList.end(); ++p) {
- const Syntax::KBestExtractor::Derivation &derivation = **p;
-
- // get the derivation's target-side yield
- Phrase outputPhrase = Syntax::KBestExtractor::GetOutputPhrase(derivation);
-
- // delete <s> and </s>
- UTIL_THROW_IF2(outputPhrase.GetSize() < 2,
- "Output phrase should have contained at least 2 words (beginning and end-of-sentence)");
- outputPhrase.RemoveWord(0);
- outputPhrase.RemoveWord(outputPhrase.GetSize() - 1);
-
- // print the translation ID, surface factors, and scores
- out << translationId << " ||| ";
- OutputSurface(out, outputPhrase, *m_outputFactorOrder, false);
- out << " ||| ";
- OutputAllFeatureScores(derivation.scoreBreakdown, out);
- out << " ||| " << derivation.score;
-
- // optionally, print word alignments
- if (includeWordAlignment) {
- out << " ||| ";
- Alignments align;
- OutputAlignmentNBest(align, derivation, 0);
- for (Alignments::const_iterator q = align.begin(); q != align.end();
- ++q) {
- out << q->first << "-" << q->second << " ";
- }
- }
-
- // optionally, print tree
- if (PrintNBestTrees) {
- TreePointer tree = Syntax::KBestExtractor::GetOutputTree(derivation);
- out << " ||| " << tree->GetString();
- }
-
- out << std::endl;
- }
-
- assert(m_nBestOutputCollector);
- m_nBestOutputCollector->Write(translationId, out.str());
-}
-
-size_t IOWrapper::CalcSourceSize(const Syntax::KBestExtractor::Derivation &d) const
-{
- using namespace Moses::Syntax;
-
- const Syntax::SHyperedge &shyperedge = d.edge->shyperedge;
- size_t ret = shyperedge.head->pvertex->span.GetNumWordsCovered();
- for (size_t i = 0; i < shyperedge.tail.size(); ++i) {
- size_t childSize = shyperedge.tail[i]->pvertex->span.GetNumWordsCovered();
- ret -= (childSize - 1);
- }
- return ret;
-}
-
-size_t IOWrapper::OutputAlignmentNBest(
- Alignments &retAlign,
- const Syntax::KBestExtractor::Derivation &derivation,
- size_t startTarget)
-{
- const Syntax::SHyperedge &shyperedge = derivation.edge->shyperedge;
-
- size_t totalTargetSize = 0;
- size_t startSource = shyperedge.head->pvertex->span.GetStartPos();
-
- const TargetPhrase &tp = *(shyperedge.translation);
-
- size_t thisSourceSize = CalcSourceSize(derivation);
-
- // position of each terminal word in translation rule, irrespective of alignment
- // if non-term, number is undefined
- vector<size_t> sourceOffsets(thisSourceSize, 0);
- vector<size_t> targetOffsets(tp.GetSize(), 0);
-
- const AlignmentInfo &aiNonTerm = shyperedge.translation->GetAlignNonTerm();
- vector<size_t> sourceInd2pos = aiNonTerm.GetSourceIndex2PosMap();
- const AlignmentInfo::NonTermIndexMap &targetPos2SourceInd = aiNonTerm.GetNonTermIndexMap();
-
- UTIL_THROW_IF2(sourceInd2pos.size() != derivation.subderivations.size(),
- "Error");
-
- size_t targetInd = 0;
- for (size_t targetPos = 0; targetPos < tp.GetSize(); ++targetPos) {
- if (tp.GetWord(targetPos).IsNonTerminal()) {
- UTIL_THROW_IF2(targetPos >= targetPos2SourceInd.size(), "Error");
- size_t sourceInd = targetPos2SourceInd[targetPos];
- size_t sourcePos = sourceInd2pos[sourceInd];
-
- const Moses::Syntax::KBestExtractor::Derivation &subderivation =
- *derivation.subderivations[sourceInd];
-
- // calc source size
- size_t sourceSize =
- subderivation.edge->head->svertex.pvertex->span.GetNumWordsCovered();
- sourceOffsets[sourcePos] = sourceSize;
-
- // calc target size.
- // Recursively look thru child hypos
- size_t currStartTarget = startTarget + totalTargetSize;
- size_t targetSize = OutputAlignmentNBest(retAlign, subderivation,
- currStartTarget);
- targetOffsets[targetPos] = targetSize;
-
- totalTargetSize += targetSize;
- ++targetInd;
- } else {
- ++totalTargetSize;
- }
- }
-
- // convert position within translation rule to absolute position within
- // source sentence / output sentence
- ShiftOffsets(sourceOffsets, startSource);
- ShiftOffsets(targetOffsets, startTarget);
-
- // get alignments from this hypo
- const AlignmentInfo &aiTerm = shyperedge.translation->GetAlignTerm();
-
- // add to output arg, offsetting by source & target
- AlignmentInfo::const_iterator iter;
- for (iter = aiTerm.begin(); iter != aiTerm.end(); ++iter) {
- const std::pair<size_t,size_t> &align = *iter;
- size_t relSource = align.first;
- size_t relTarget = align.second;
- size_t absSource = sourceOffsets[relSource];
- size_t absTarget = targetOffsets[relTarget];
-
- pair<size_t, size_t> alignPoint(absSource, absTarget);
- pair<Alignments::iterator, bool> ret = retAlign.insert(alignPoint);
- UTIL_THROW_IF2(!ret.second, "Error");
- }
-
- return totalTargetSize;
-}
-
void IOWrapper::OutputUnknowns(const std::set<Moses::Word> &unknowns,
long translationId)
{