mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
option to sort translation options after EvaluateAfterSourceContext
This commit is contained in:
parent
ec547fa56a
commit
ad6f3a8026
@ -51,6 +51,18 @@ ChartTranslationOptions::~ChartTranslationOptions()
|
||||
|
||||
}
|
||||
|
||||
//! functor to compare (chart) hypotheses by (descending) score
|
||||
class ChartTranslationOptionScoreOrderer
|
||||
{
|
||||
public:
|
||||
bool operator()(const boost::shared_ptr<ChartTranslationOption> &transOptA
|
||||
, const boost::shared_ptr<ChartTranslationOption> &transOptB) const {
|
||||
const ScoreComponentCollection &scoresA = transOptA->GetScores();
|
||||
const ScoreComponentCollection &scoresB = transOptB->GetScores();
|
||||
return scoresA.GetWeightedScore() > scoresB.GetWeightedScore();
|
||||
}
|
||||
};
|
||||
|
||||
void ChartTranslationOptions::EvaluateWithSourceContext(const InputType &input, const InputPath &inputPath)
|
||||
{
|
||||
SetInputPath(&inputPath);
|
||||
@ -79,6 +91,15 @@ void ChartTranslationOptions::EvaluateWithSourceContext(const InputType &input,
|
||||
|
||||
size_t newSize = m_collection.size() - numDiscard;
|
||||
m_collection.resize(newSize);
|
||||
|
||||
// sort if necessary
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
if (staticData.RequireSortingAfterSourceContext()) {
|
||||
std::sort(m_collection.begin()
|
||||
, m_collection.begin() + newSize
|
||||
, ChartTranslationOptionScoreOrderer());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ChartTranslationOptions::SetInputPath(const InputPath *inputPath)
|
||||
|
@ -46,6 +46,7 @@ void FeatureFunction::CallChangeSource(InputType *&input)
|
||||
FeatureFunction::
|
||||
FeatureFunction(const std::string& line)
|
||||
: m_tuneable(true)
|
||||
, m_requireSortingAfterSourceContext(false)
|
||||
, m_verbosity(std::numeric_limits<std::size_t>::max())
|
||||
, m_numScoreComponents(1)
|
||||
{
|
||||
@ -56,6 +57,7 @@ FeatureFunction::
|
||||
FeatureFunction(size_t numScoreComponents,
|
||||
const std::string& line)
|
||||
: m_tuneable(true)
|
||||
, m_requireSortingAfterSourceContext(false)
|
||||
, m_verbosity(std::numeric_limits<std::size_t>::max())
|
||||
, m_numScoreComponents(numScoreComponents)
|
||||
{
|
||||
@ -118,6 +120,8 @@ void FeatureFunction::SetParameter(const std::string& key, const std::string& va
|
||||
{
|
||||
if (key == "tuneable") {
|
||||
m_tuneable = Scan<bool>(value);
|
||||
} else if (key == "require-sorting-after-source-context") {
|
||||
m_requireSortingAfterSourceContext = Scan<bool>(value);
|
||||
} else if (key == "verbosity") {
|
||||
m_verbosity = Scan<size_t>(value);
|
||||
} else if (key == "filterable") { //ignore
|
||||
|
@ -36,6 +36,7 @@ protected:
|
||||
std::string m_description, m_argLine;
|
||||
std::vector<std::vector<std::string> > m_args;
|
||||
bool m_tuneable;
|
||||
bool m_requireSortingAfterSourceContext;
|
||||
size_t m_verbosity;
|
||||
size_t m_numScoreComponents;
|
||||
//In case there's multiple producers with the same description
|
||||
@ -88,6 +89,11 @@ public:
|
||||
virtual bool IsTuneable() const {
|
||||
return m_tuneable;
|
||||
}
|
||||
|
||||
virtual bool RequireSortingAfterSourceContext() const {
|
||||
return m_requireSortingAfterSourceContext;
|
||||
}
|
||||
|
||||
virtual std::vector<float> DefaultWeights() const;
|
||||
|
||||
//! Called before search and collecting of translation options
|
||||
|
@ -66,6 +66,7 @@ StaticData::StaticData()
|
||||
,m_isAlwaysCreateDirectTranslationOption(false)
|
||||
,m_currentWeightSetting("default")
|
||||
,m_useS2TDecoder(false)
|
||||
,m_requireSortingAfterSourceContext(false)
|
||||
,m_treeStructure(NULL)
|
||||
{
|
||||
m_xmlBrackets.first="<";
|
||||
@ -878,6 +879,10 @@ void StaticData::LoadFeatureFunctions()
|
||||
FeatureFunction *ff = *iter;
|
||||
bool doLoad = true;
|
||||
|
||||
if (ff->RequireSortingAfterSourceContext()) {
|
||||
m_requireSortingAfterSourceContext = true;
|
||||
}
|
||||
|
||||
// if (PhraseDictionary *ffCast = dynamic_cast<PhraseDictionary*>(ff)) {
|
||||
if (dynamic_cast<PhraseDictionary*>(ff)) {
|
||||
doLoad = false;
|
||||
|
@ -112,6 +112,7 @@ protected:
|
||||
bool m_sourceStartPosMattersForRecombination;
|
||||
bool m_recoverPath;
|
||||
bool m_outputHypoScore;
|
||||
bool m_requireSortingAfterSourceContext;
|
||||
|
||||
SearchAlgorithm m_searchAlgorithm;
|
||||
InputTypeEnum m_inputType;
|
||||
@ -793,6 +794,10 @@ public:
|
||||
return m_printNBestTrees;
|
||||
}
|
||||
|
||||
bool RequireSortingAfterSourceContext() const {
|
||||
return m_requireSortingAfterSourceContext;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user