2008-06-11 14:52:57 +04:00
|
|
|
// $Id$
|
|
|
|
// vim:tabstop=2
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2006 University of Edinburgh
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
#include "TranslationOption.h"
|
|
|
|
#include "WordsBitmap.h"
|
|
|
|
#include "GenerationDictionary.h"
|
|
|
|
#include "StaticData.h"
|
|
|
|
#include "InputType.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
2009-02-05 20:37:09 +03:00
|
|
|
|
2013-08-05 19:53:15 +04:00
|
|
|
TranslationOption::TranslationOption()
|
2013-08-07 17:18:12 +04:00
|
|
|
:m_targetPhrase()
|
2013-08-13 23:36:32 +04:00
|
|
|
,m_inputPath(NULL)
|
2013-08-07 17:18:12 +04:00
|
|
|
,m_sourceWordsRange(NOT_FOUND, NOT_FOUND)
|
2013-08-05 19:53:15 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
//TODO this should be a factory function!
|
|
|
|
TranslationOption::TranslationOption(const WordsRange &wordsRange
|
2013-05-08 14:28:31 +04:00
|
|
|
, const TargetPhrase &targetPhrase)
|
2011-02-24 16:14:42 +03:00
|
|
|
: m_targetPhrase(targetPhrase)
|
2013-08-13 23:36:32 +04:00
|
|
|
, m_inputPath(NULL)
|
2011-02-24 16:14:42 +03:00
|
|
|
, m_sourceWordsRange(wordsRange)
|
2013-05-08 14:28:31 +04:00
|
|
|
, m_futureScore(targetPhrase.GetFutureScore())
|
2008-06-11 14:52:57 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TranslationOption::IsCompatible(const Phrase& phrase, const std::vector<FactorType>& featuresToCheck) const
|
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
if (featuresToCheck.size() == 1) {
|
2008-06-11 14:52:57 +04:00
|
|
|
return m_targetPhrase.IsCompatible(phrase, featuresToCheck[0]);
|
|
|
|
} else if (featuresToCheck.empty()) {
|
2011-02-24 16:14:42 +03:00
|
|
|
return true;
|
2008-06-11 14:52:57 +04:00
|
|
|
/* features already there, just update score */
|
|
|
|
} else {
|
|
|
|
return m_targetPhrase.IsCompatible(phrase, featuresToCheck);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TranslationOption::Overlap(const Hypothesis &hypothesis) const
|
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
const WordsBitmap &bitmap = hypothesis.GetWordsBitmap();
|
|
|
|
return bitmap.Overlap(GetSourceWordsRange());
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
|
|
|
|
2013-05-23 21:12:08 +04:00
|
|
|
void TranslationOption::CacheLexReorderingScores(const LexicalReordering &producer, const Scores &score)
|
|
|
|
{
|
|
|
|
m_lexReorderingScores[&producer] = score;
|
|
|
|
}
|
|
|
|
|
2013-08-08 20:35:42 +04:00
|
|
|
void TranslationOption::Evaluate(const InputType &input)
|
2013-05-23 21:12:08 +04:00
|
|
|
{
|
2013-08-13 23:36:32 +04:00
|
|
|
const InputPath &inputPath = GetInputPath();
|
|
|
|
m_targetPhrase.Evaluate(input, inputPath);
|
2013-05-23 21:12:08 +04:00
|
|
|
}
|
|
|
|
|
2013-08-13 23:36:32 +04:00
|
|
|
const InputPath &TranslationOption::GetInputPath() const
|
2013-08-07 13:28:28 +04:00
|
|
|
{
|
2013-11-19 22:52:15 +04:00
|
|
|
UTIL_THROW_IF(m_inputPath == NULL, util::Exception,
|
|
|
|
"No input path");
|
2013-08-13 23:36:32 +04:00
|
|
|
return *m_inputPath;
|
2013-08-07 13:28:28 +04:00
|
|
|
}
|
|
|
|
|
2013-08-13 23:36:32 +04:00
|
|
|
void TranslationOption::SetInputPath(const InputPath &inputPath)
|
2013-08-08 18:03:01 +04:00
|
|
|
{
|
2013-11-19 22:52:15 +04:00
|
|
|
UTIL_THROW_IF(m_inputPath, util::Exception,
|
|
|
|
"Input path already specified");
|
2013-08-13 23:36:32 +04:00
|
|
|
m_inputPath = &inputPath;
|
2013-08-08 18:03:01 +04:00
|
|
|
}
|
|
|
|
|
2013-08-07 13:28:28 +04:00
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
TO_STRING_BODY(TranslationOption);
|
|
|
|
|
|
|
|
// friend
|
|
|
|
ostream& operator<<(ostream& out, const TranslationOption& possibleTranslation)
|
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
out << possibleTranslation.GetTargetPhrase()
|
|
|
|
<< " c=" << possibleTranslation.GetFutureScore()
|
|
|
|
<< " [" << possibleTranslation.GetSourceWordsRange() << "]"
|
|
|
|
<< possibleTranslation.GetScoreBreakdown();
|
|
|
|
return out;
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|