mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
add ControlRecombination feature function
This commit is contained in:
parent
a098227abe
commit
2590601708
@ -8,9 +8,19 @@ namespace Moses {
|
||||
|
||||
ControlRecombination::ControlRecombination(const std::string &line)
|
||||
:StatefulFeatureFunction("ControlRecombination", 0, line)
|
||||
,m_type(Output)
|
||||
{
|
||||
}
|
||||
|
||||
void ControlRecombination::SetParameter(const std::string& key, const std::string& value)
|
||||
{
|
||||
if (key == "type") {
|
||||
m_type = (Type) Scan<size_t>(value);
|
||||
} else {
|
||||
StatefulFeatureFunction::SetParameter(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
FFState* ControlRecombination::Evaluate(
|
||||
const Hypothesis& cur_hypo,
|
||||
const FFState* prev_state,
|
||||
@ -48,17 +58,27 @@ int ControlRecombinationState::Compare(const FFState& other) const
|
||||
const ControlRecombinationState &other2 = static_cast<const ControlRecombinationState&>(other);
|
||||
const Hypothesis *otherHypo = other2.m_hypo;
|
||||
|
||||
const TargetPhrase &thisTargetPhrase = m_hypo->GetCurrTargetPhrase();
|
||||
const TargetPhrase *thisTargetPhrase = &m_hypo->GetCurrTargetPhrase();
|
||||
const TargetPhrase *otherTargetPhrase = &otherHypo->GetCurrTargetPhrase();
|
||||
|
||||
int thisSize = thisTargetPhrase.GetSize();
|
||||
int thisSize = thisTargetPhrase->GetSize();
|
||||
int otherPos = otherTargetPhrase->GetSize() - 1;
|
||||
for (int thisPos = thisSize - 1; thisPos >= 0; --thisPos) {
|
||||
const Word &thisWord = thisTargetPhrase.GetWord(thisPos);
|
||||
|
||||
|
||||
--otherPos;
|
||||
for (int thisPos = thisSize - 1; thisPos >= 0; --thisPos && --otherPos) {
|
||||
if (otherPos < 0) {
|
||||
otherHypo = otherHypo->GetPrevHypo();
|
||||
if (otherHypo == NULL) {
|
||||
return -1;
|
||||
}
|
||||
otherTargetPhrase = &otherHypo->GetCurrTargetPhrase();
|
||||
otherPos = otherTargetPhrase->GetSize() - 1;
|
||||
}
|
||||
|
||||
const Word &thisWord = thisTargetPhrase->GetWord(thisPos);
|
||||
const Word &otherWord = otherTargetPhrase->GetWord(otherPos);
|
||||
int compare = thisWord.Compare(otherWord);
|
||||
if (compare) {
|
||||
return compare;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -11,8 +11,14 @@ class ControlRecombinationState;
|
||||
// force hypotheses NOT to recombine. For forced decoding
|
||||
class ControlRecombination : public StatefulFeatureFunction
|
||||
{
|
||||
|
||||
public:
|
||||
enum Type
|
||||
{
|
||||
None,
|
||||
Output,
|
||||
Segmentation
|
||||
};
|
||||
|
||||
ControlRecombination(const std::string &line);
|
||||
|
||||
bool IsUseable(const FactorMask &mask) const {
|
||||
@ -32,6 +38,9 @@ public:
|
||||
//! return the state associated with the empty hypothesis for a given sentence
|
||||
virtual const FFState* EmptyHypothesisState(const InputType &input) const;
|
||||
|
||||
void SetParameter(const std::string& key, const std::string& value);
|
||||
protected:
|
||||
Type m_type;
|
||||
};
|
||||
|
||||
class ControlRecombinationState : public FFState
|
||||
|
@ -134,6 +134,11 @@ public:
|
||||
return Compare(*this, compare) != 0;
|
||||
}
|
||||
|
||||
int Compare(const Word &other) const {
|
||||
return Compare(*this, other);
|
||||
}
|
||||
|
||||
|
||||
/* static functions */
|
||||
|
||||
/** transitive comparison of 2 word objects. Used by operator<.
|
||||
|
Loading…
Reference in New Issue
Block a user