#include <PhraseOrientationFeature.h>
Classes | |
struct | ReoClassData |
Public Member Functions | |
PhraseOrientationFeature (const std::string &line) | |
~PhraseOrientationFeature () | |
bool | IsUseable (const FactorMask &mask) const |
virtual const FFState * | EmptyHypothesisState (const InputType &input) const |
return the state associated with the empty hypothesis for a given sentence | |
void | SetParameter (const std::string &key, const std::string &value) |
void | Load (AllOptions::ptr const &opts) |
override to load model files | |
void | EvaluateInIsolation (const Phrase &source, const TargetPhrase &targetPhrase, ScoreComponentCollection &scoreBreakdown, ScoreComponentCollection &estimatedScores) const |
FFState * | EvaluateWhenApplied (const Hypothesis &cur_hypo, const FFState *prev_state, ScoreComponentCollection *accumulator) const |
This interface should be implemented. Notes: When evaluating the value of this feature function, you should avoid calling hypo.GetPrevHypo(). If you need something from the "previous" hypothesis, you should store it in an FFState object which will be passed in as prev_state. If you don't do this, you will get in trouble. | |
FFState * | EvaluateWhenApplied (const ChartHypothesis &cur_hypo, int featureID, ScoreComponentCollection *accumulator) const |
Protected Member Functions | |
void | LoadWordList (const std::string &filename, boost::unordered_set< const Factor * > &list) |
void | LookaheadScore (const OrientationPhraseProperty *orientationPhraseProperty, ScoreComponentCollection &scoreBreakdown, const Factor *targetPhraseLHS, bool subtract=false) const |
size_t | GetHeuristicScoreIndex (const std::vector< float > &scores, size_t weightsVectorOffset, const std::bitset< 3 > possibleFutureOrientations=0x7) const |
void | LeftBoundaryL2RScoreRecursive (int featureID, const PhraseOrientationFeatureState *state, const std::bitset< 3 > orientation, std::vector< float > &newScores, ScoreComponentCollection *scoreBreakdown) const |
void | RightBoundaryR2LScoreRecursive (int featureID, const PhraseOrientationFeatureState *state, const std::bitset< 3 > orientation, std::vector< float > &newScores, ScoreComponentCollection *scoreBreakdown) const |
void | SparseWordL2RScore (const ChartHypothesis *hypo, ScoreComponentCollection *scoreBreakdown, const std::string *o) const |
void | SparseWordR2LScore (const ChartHypothesis *hypo, ScoreComponentCollection *scoreBreakdown, const std::string *o) const |
void | SparseNonTerminalL2RScore (const Factor *nonTerminalSymbol, ScoreComponentCollection *scoreBreakdown, const std::string *o) const |
void | SparseNonTerminalR2LScore (const Factor *nonTerminalSymbol, ScoreComponentCollection *scoreBreakdown, const std::string *o) const |
const std::string * | ToString (const MosesTraining::PhraseOrientation::REO_CLASS o) const |
Protected Attributes | |
std::string | m_glueLabelStr |
const Factor * | m_glueLabel |
bool | m_noScoreBoundary |
bool | m_monotoneScoreBoundary |
bool | m_distinguishStates |
bool | m_lookaheadScore |
bool | m_heuristicScoreUseWeights |
bool | m_useSparseWord |
bool | m_useSparseNT |
size_t | m_offsetR2LScores |
std::vector< float > | m_weightsVector |
std::string | m_filenameTargetWordList |
boost::unordered_set< const Factor * > | m_targetWordList |
bool | m_useTargetWordList |
std::string | m_filenameSourceWordList |
boost::unordered_set< const Factor * > | m_sourceWordList |
bool | m_useSourceWordList |
Static Protected Attributes | |
static const std::string | MORIENT |
static const std::string | SORIENT |
static const std::string | DORIENT |
Definition at line 309 of file PhraseOrientationFeature.h.
Moses::PhraseOrientationFeature::PhraseOrientationFeature | ( | const std::string & | line | ) |
Definition at line 83 of file PhraseOrientationFeature.cpp.
References Moses::FactorCollection::AddFactor(), Moses::FeatureFunction::GetScoreProducerDescription(), Moses::FactorCollection::Instance(), m_glueLabel, m_glueLabelStr, Moses::FeatureFunction::ReadParameters(), and VERBOSE.
Moses::PhraseOrientationFeature::~PhraseOrientationFeature | ( | ) | [inline] |
Definition at line 327 of file PhraseOrientationFeature.h.
virtual const FFState* Moses::PhraseOrientationFeature::EmptyHypothesisState | ( | const InputType & | input | ) | const [inline, virtual] |
return the state associated with the empty hypothesis for a given sentence
Implements Moses::StatefulFeatureFunction.
Definition at line 334 of file PhraseOrientationFeature.h.
References m_distinguishStates, m_useSparseNT, and m_useSparseWord.
void Moses::PhraseOrientationFeature::EvaluateInIsolation | ( | const Phrase & | source, | |
const TargetPhrase & | targetPhrase, | |||
ScoreComponentCollection & | scoreBreakdown, | |||
ScoreComponentCollection & | estimatedScores | |||
) | const [virtual] |
Reimplemented from Moses::StatefulFeatureFunction.
Definition at line 165 of file PhraseOrientationFeature.cpp.
References Moses::AlignmentInfo::begin(), Moses::AlignmentInfo::end(), FEATUREVERBOSE, FEATUREVERBOSE2, Moses::TargetPhrase::GetAlignNonTerm(), Moses::TargetPhrase::GetAlignTerm(), Moses::TargetPhrase::GetProperty(), Moses::FeatureFunction::GetScoreProducerDescription(), Moses::Phrase::GetSize(), Moses::AlignmentInfo::GetSize(), Moses::TargetPhrase::GetTargetLHS(), Moses::Phrase::GetWord(), IFFEATUREVERBOSE, Moses::Word::IsOOV(), LookaheadScore(), m_glueLabel, m_lookaheadScore, MosesTraining::PhraseOrientation::REO_CLASS_DLEFT, MosesTraining::PhraseOrientation::REO_DIR_L2R, MosesTraining::PhraseOrientation::REO_DIR_R2L, Moses::TargetPhrase::SetData(), Moses::TargetPhrase::SetRuleSource(), and UTIL_THROW_IF2.
FFState * Moses::PhraseOrientationFeature::EvaluateWhenApplied | ( | const ChartHypothesis & | cur_hypo, | |
int | featureID, | |||
ScoreComponentCollection * | accumulator | |||
) | const [virtual] |
Implements Moses::StatefulFeatureFunction.
Definition at line 286 of file PhraseOrientationFeature.cpp.
References Moses::AlignmentInfo::begin(), Moses::AlignmentInfo::end(), FEATUREVERBOSE, FEATUREVERBOSE2, Moses::PhraseOrientationFeature::ReoClassData::firstNonTerminalFollowingSourceSpanIsAligned, Moses::PhraseOrientationFeature::ReoClassData::firstNonTerminalIsBoundary, Moses::PhraseOrientationFeature::ReoClassData::firstNonTerminalPreviousSourceSpanIsAligned, Moses::TargetPhrase::GetAlignNonTerm(), Moses::TargetPhrase::GetAlignTerm(), Moses::ChartHypothesis::GetCurrTargetPhrase(), Moses::TargetPhrase::GetData(), Moses::ChartHypothesis::GetFFState(), GetHeuristicScoreIndex(), Moses::OrientationPhraseProperty::GetLeftToRightProbabilityDiscontinuous(), Moses::OrientationPhraseProperty::GetLeftToRightProbabilityDleft(), Moses::OrientationPhraseProperty::GetLeftToRightProbabilityDright(), Moses::OrientationPhraseProperty::GetLeftToRightProbabilityMono(), Moses::OrientationPhraseProperty::GetLeftToRightProbabilitySwap(), Moses::AlignmentInfo::GetNonTermIndexMap(), Moses::ChartHypothesis::GetPrevHypo(), Moses::TargetPhrase::GetProperty(), Moses::OrientationPhraseProperty::GetRightToLeftProbabilityDiscontinuous(), Moses::OrientationPhraseProperty::GetRightToLeftProbabilityDleft(), Moses::OrientationPhraseProperty::GetRightToLeftProbabilityDright(), Moses::OrientationPhraseProperty::GetRightToLeftProbabilityMono(), Moses::OrientationPhraseProperty::GetRightToLeftProbabilitySwap(), Moses::TargetPhrase::GetRuleSource(), Moses::FeatureFunction::GetScoreProducerDescription(), Moses::AlignmentInfo::GetSize(), Moses::TargetPhrase::GetTargetLHS(), Moses::Phrase::GetWord(), IFFEATUREVERBOSE, Moses::Word::IsOOV(), Moses::PhraseOrientationFeature::ReoClassData::lastNonTerminalFollowingSourceSpanIsAligned, Moses::PhraseOrientationFeature::ReoClassData::lastNonTerminalIsBoundary, Moses::PhraseOrientationFeature::ReoClassData::lastNonTerminalPreviousSourceSpanIsAligned, LeftBoundaryL2RScoreRecursive(), LookaheadScore(), m_distinguishStates, Moses::PhraseOrientationFeatureState::m_leftBoundaryNonTerminalL2RPossibleFutureOrientations, Moses::PhraseOrientationFeatureState::m_leftBoundaryRecursionGuard, m_lookaheadScore, m_monotoneScoreBoundary, m_noScoreBoundary, Moses::FeatureFunction::m_numScoreComponents, m_offsetR2LScores, Moses::PhraseOrientationFeatureState::m_rightBoundaryNonTerminalR2LPossibleFutureOrientations, Moses::PhraseOrientationFeatureState::m_rightBoundaryRecursionGuard, m_useSparseNT, m_useSparseWord, Moses::PhraseOrientationFeature::ReoClassData::nonTerminalReoClassL2R, Moses::PhraseOrientationFeature::ReoClassData::nonTerminalReoClassR2L, NULL, Moses::ScoreComponentCollection::PlusEquals(), MosesTraining::PhraseOrientation::REO_CLASS_DLEFT, MosesTraining::PhraseOrientation::REO_CLASS_DRIGHT, MosesTraining::PhraseOrientation::REO_CLASS_LEFT, MosesTraining::PhraseOrientation::REO_CLASS_RIGHT, MosesTraining::PhraseOrientation::REO_CLASS_UNKNOWN, RightBoundaryR2LScoreRecursive(), Moses::PhraseOrientationFeatureState::SetLeftBoundaryL2R(), Moses::PhraseOrientationFeatureState::SetRightBoundaryR2L(), SparseNonTerminalL2RScore(), SparseNonTerminalR2LScore(), SparseWordL2RScore(), SparseWordR2LScore(), state, ToString(), Moses::TransformScore(), UTIL_THROW2, and UTIL_THROW_IF2.
FFState* Moses::PhraseOrientationFeature::EvaluateWhenApplied | ( | const Hypothesis & | cur_hypo, | |
const FFState * | prev_state, | |||
ScoreComponentCollection * | accumulator | |||
) | const [inline, virtual] |
This interface should be implemented. Notes: When evaluating the value of this feature function, you should avoid calling hypo.GetPrevHypo(). If you need something from the "previous" hypothesis, you should store it in an FFState object which will be passed in as prev_state. If you don't do this, you will get in trouble.
Implements Moses::StatefulFeatureFunction.
Definition at line 347 of file PhraseOrientationFeature.h.
References Moses::FeatureFunction::GetScoreProducerDescription(), m_distinguishStates, m_useSparseNT, m_useSparseWord, and UTIL_THROW2.
size_t Moses::PhraseOrientationFeature::GetHeuristicScoreIndex | ( | const std::vector< float > & | scores, | |
size_t | weightsVectorOffset, | |||
const std::bitset< 3 > | possibleFutureOrientations = 0x7 | |||
) | const [protected] |
Definition at line 654 of file PhraseOrientationFeature.cpp.
References FEATUREVERBOSE, FEATUREVERBOSE2, Moses::StaticData::GetAllWeights(), Moses::ScoreComponentCollection::GetScoresForProducer(), IFFEATUREVERBOSE, Moses::StaticData::Instance(), m_heuristicScoreUseWeights, and m_weightsVector.
Referenced by EvaluateWhenApplied(), and LookaheadScore().
bool Moses::PhraseOrientationFeature::IsUseable | ( | const FactorMask & | mask | ) | const [inline, virtual] |
void Moses::PhraseOrientationFeature::LeftBoundaryL2RScoreRecursive | ( | int | featureID, | |
const PhraseOrientationFeatureState * | state, | |||
const std::bitset< 3 > | orientation, | |||
std::vector< float > & | newScores, | |||
ScoreComponentCollection * | scoreBreakdown | |||
) | const [protected] |
Definition at line 706 of file PhraseOrientationFeature.cpp.
References FEATUREVERBOSE, state, and UTIL_THROW2.
Referenced by EvaluateWhenApplied().
void Moses::PhraseOrientationFeature::Load | ( | AllOptions::ptr const & | opts | ) | [virtual] |
override to load model files
Reimplemented from Moses::FeatureFunction.
Definition at line 133 of file PhraseOrientationFeature.cpp.
References LoadWordList(), m_filenameSourceWordList, m_filenameTargetWordList, Moses::FeatureFunction::m_options, m_sourceWordList, m_targetWordList, m_useSourceWordList, and m_useTargetWordList.
void Moses::PhraseOrientationFeature::LoadWordList | ( | const std::string & | filename, | |
boost::unordered_set< const Factor * > & | list | |||
) | [protected] |
Definition at line 147 of file PhraseOrientationFeature.cpp.
References Moses::FactorCollection::AddFactor(), Moses::InputFileStream::Close(), FEATUREVERBOSE, and Moses::FactorCollection::Instance().
Referenced by Load().
void Moses::PhraseOrientationFeature::LookaheadScore | ( | const OrientationPhraseProperty * | orientationPhraseProperty, | |
ScoreComponentCollection & | scoreBreakdown, | |||
const Factor * | targetPhraseLHS, | |||
bool | subtract = false | |||
) | const [protected] |
Definition at line 611 of file PhraseOrientationFeature.cpp.
References GetHeuristicScoreIndex(), Moses::OrientationPhraseProperty::GetLeftToRightProbabilityDiscontinuous(), Moses::OrientationPhraseProperty::GetLeftToRightProbabilityMono(), Moses::OrientationPhraseProperty::GetLeftToRightProbabilitySwap(), Moses::OrientationPhraseProperty::GetRightToLeftProbabilityDiscontinuous(), Moses::OrientationPhraseProperty::GetRightToLeftProbabilityMono(), Moses::OrientationPhraseProperty::GetRightToLeftProbabilitySwap(), m_glueLabel, Moses::FeatureFunction::m_index, m_offsetR2LScores, Moses::ScoreComponentCollection::PlusEquals(), and Moses::TransformScore().
Referenced by EvaluateInIsolation(), and EvaluateWhenApplied().
void Moses::PhraseOrientationFeature::RightBoundaryR2LScoreRecursive | ( | int | featureID, | |
const PhraseOrientationFeatureState * | state, | |||
const std::bitset< 3 > | orientation, | |||
std::vector< float > & | newScores, | |||
ScoreComponentCollection * | scoreBreakdown | |||
) | const [protected] |
Definition at line 767 of file PhraseOrientationFeature.cpp.
References FEATUREVERBOSE, state, and UTIL_THROW2.
Referenced by EvaluateWhenApplied().
void Moses::PhraseOrientationFeature::SetParameter | ( | const std::string & | key, | |
const std::string & | value | |||
) | [virtual] |
Reimplemented from Moses::FeatureFunction.
Definition at line 105 of file PhraseOrientationFeature.cpp.
References m_distinguishStates, m_filenameSourceWordList, m_filenameTargetWordList, m_glueLabelStr, m_heuristicScoreUseWeights, m_lookaheadScore, m_monotoneScoreBoundary, m_noScoreBoundary, m_useSparseNT, m_useSparseWord, and Moses::Scan< bool >().
void Moses::PhraseOrientationFeature::SparseNonTerminalL2RScore | ( | const Factor * | nonTerminalSymbol, | |
ScoreComponentCollection * | scoreBreakdown, | |||
const std::string * | o | |||
) | const [protected] |
Definition at line 946 of file PhraseOrientationFeature.cpp.
References StringPiece::as_string(), FEATUREVERBOSE, Moses::Factor::GetString(), m_glueLabel, and Moses::ScoreComponentCollection::PlusEquals().
Referenced by EvaluateWhenApplied().
void Moses::PhraseOrientationFeature::SparseNonTerminalR2LScore | ( | const Factor * | nonTerminalSymbol, | |
ScoreComponentCollection * | scoreBreakdown, | |||
const std::string * | o | |||
) | const [protected] |
Definition at line 960 of file PhraseOrientationFeature.cpp.
References StringPiece::as_string(), FEATUREVERBOSE, Moses::Factor::GetString(), m_glueLabel, and Moses::ScoreComponentCollection::PlusEquals().
Referenced by EvaluateWhenApplied().
void Moses::PhraseOrientationFeature::SparseWordL2RScore | ( | const ChartHypothesis * | hypo, | |
ScoreComponentCollection * | scoreBreakdown, | |||
const std::string * | o | |||
) | const [protected] |
Definition at line 828 of file PhraseOrientationFeature.cpp.
References FEATUREVERBOSE, Moses::TargetPhrase::GetAlignNonTerm(), Moses::ChartHypothesis::GetCurrSourceRange(), Moses::ChartHypothesis::GetCurrTargetPhrase(), Moses::ChartHypothesis::GetManager(), Moses::AlignmentInfo::GetNonTermIndexMap(), Moses::ChartHypothesis::GetPrevHypo(), Moses::BaseManager::GetSource(), Moses::Range::GetStartPos(), Moses::Word::GetString(), Moses::Sentence::GetWord(), Moses::Phrase::GetWord(), Moses::Word::IsNonTerminal(), m_sourceWordList, m_targetWordList, m_useSourceWordList, m_useTargetWordList, and Moses::ScoreComponentCollection::PlusEquals().
Referenced by EvaluateWhenApplied().
void Moses::PhraseOrientationFeature::SparseWordR2LScore | ( | const ChartHypothesis * | hypo, | |
ScoreComponentCollection * | scoreBreakdown, | |||
const std::string * | o | |||
) | const [protected] |
Definition at line 887 of file PhraseOrientationFeature.cpp.
References FEATUREVERBOSE, Moses::TargetPhrase::GetAlignNonTerm(), Moses::ChartHypothesis::GetCurrSourceRange(), Moses::ChartHypothesis::GetCurrTargetPhrase(), Moses::Range::GetEndPos(), Moses::ChartHypothesis::GetManager(), Moses::AlignmentInfo::GetNonTermIndexMap(), Moses::ChartHypothesis::GetPrevHypo(), Moses::Phrase::GetSize(), Moses::BaseManager::GetSource(), Moses::Word::GetString(), Moses::Sentence::GetWord(), Moses::Phrase::GetWord(), Moses::Word::IsNonTerminal(), m_sourceWordList, m_targetWordList, m_useSourceWordList, m_useTargetWordList, and Moses::ScoreComponentCollection::PlusEquals().
Referenced by EvaluateWhenApplied().
const std::string * Moses::PhraseOrientationFeature::ToString | ( | const MosesTraining::PhraseOrientation::REO_CLASS | o | ) | const [protected] |
Definition at line 974 of file PhraseOrientationFeature.cpp.
References DORIENT, Moses::FeatureFunction::GetScoreProducerDescription(), MORIENT, NULL, MosesTraining::PhraseOrientation::REO_CLASS_DLEFT, MosesTraining::PhraseOrientation::REO_CLASS_DRIGHT, MosesTraining::PhraseOrientation::REO_CLASS_LEFT, MosesTraining::PhraseOrientation::REO_CLASS_RIGHT, MosesTraining::PhraseOrientation::REO_CLASS_UNKNOWN, SORIENT, and UTIL_THROW2.
Referenced by EvaluateWhenApplied().
const std::string Moses::PhraseOrientationFeature::DORIENT [static, protected] |
bool Moses::PhraseOrientationFeature::m_distinguishStates [protected] |
Definition at line 413 of file PhraseOrientationFeature.h.
Referenced by EmptyHypothesisState(), EvaluateWhenApplied(), and SetParameter().
std::string Moses::PhraseOrientationFeature::m_filenameSourceWordList [protected] |
Definition at line 423 of file PhraseOrientationFeature.h.
Referenced by Load(), and SetParameter().
std::string Moses::PhraseOrientationFeature::m_filenameTargetWordList [protected] |
Definition at line 420 of file PhraseOrientationFeature.h.
Referenced by Load(), and SetParameter().
const Factor* Moses::PhraseOrientationFeature::m_glueLabel [protected] |
Definition at line 410 of file PhraseOrientationFeature.h.
Referenced by EvaluateInIsolation(), LookaheadScore(), PhraseOrientationFeature(), SparseNonTerminalL2RScore(), and SparseNonTerminalR2LScore().
std::string Moses::PhraseOrientationFeature::m_glueLabelStr [protected] |
Definition at line 409 of file PhraseOrientationFeature.h.
Referenced by PhraseOrientationFeature(), and SetParameter().
bool Moses::PhraseOrientationFeature::m_heuristicScoreUseWeights [protected] |
Definition at line 415 of file PhraseOrientationFeature.h.
Referenced by GetHeuristicScoreIndex(), and SetParameter().
bool Moses::PhraseOrientationFeature::m_lookaheadScore [protected] |
Definition at line 414 of file PhraseOrientationFeature.h.
Referenced by EvaluateInIsolation(), EvaluateWhenApplied(), and SetParameter().
bool Moses::PhraseOrientationFeature::m_monotoneScoreBoundary [protected] |
Definition at line 412 of file PhraseOrientationFeature.h.
Referenced by EvaluateWhenApplied(), and SetParameter().
bool Moses::PhraseOrientationFeature::m_noScoreBoundary [protected] |
Definition at line 411 of file PhraseOrientationFeature.h.
Referenced by EvaluateWhenApplied(), and SetParameter().
size_t Moses::PhraseOrientationFeature::m_offsetR2LScores [protected] |
Definition at line 418 of file PhraseOrientationFeature.h.
Referenced by EvaluateWhenApplied(), and LookaheadScore().
boost::unordered_set<const Factor*> Moses::PhraseOrientationFeature::m_sourceWordList [protected] |
Definition at line 424 of file PhraseOrientationFeature.h.
Referenced by Load(), SparseWordL2RScore(), and SparseWordR2LScore().
boost::unordered_set<const Factor*> Moses::PhraseOrientationFeature::m_targetWordList [protected] |
Definition at line 421 of file PhraseOrientationFeature.h.
Referenced by Load(), SparseWordL2RScore(), and SparseWordR2LScore().
bool Moses::PhraseOrientationFeature::m_useSourceWordList [protected] |
Definition at line 425 of file PhraseOrientationFeature.h.
Referenced by Load(), SparseWordL2RScore(), and SparseWordR2LScore().
bool Moses::PhraseOrientationFeature::m_useSparseNT [protected] |
Definition at line 417 of file PhraseOrientationFeature.h.
Referenced by EmptyHypothesisState(), EvaluateWhenApplied(), and SetParameter().
bool Moses::PhraseOrientationFeature::m_useSparseWord [protected] |
Definition at line 416 of file PhraseOrientationFeature.h.
Referenced by EmptyHypothesisState(), EvaluateWhenApplied(), and SetParameter().
bool Moses::PhraseOrientationFeature::m_useTargetWordList [protected] |
Definition at line 422 of file PhraseOrientationFeature.h.
Referenced by Load(), SparseWordL2RScore(), and SparseWordR2LScore().
std::vector<float> Moses::PhraseOrientationFeature::m_weightsVector [mutable, protected] |
const std::string Moses::PhraseOrientationFeature::MORIENT [static, protected] |
const std::string Moses::PhraseOrientationFeature::SORIENT [static, protected] |