mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-30 23:42:30 +03:00
PhraseOrientationFeature dummy. Does not do anything yet.
This commit is contained in:
parent
986d753a90
commit
58842b8ffb
@ -49,6 +49,7 @@
|
||||
#include "NieceTerminal.h"
|
||||
#include "SpanLength.h"
|
||||
#include "SyntaxRHS.h"
|
||||
#include "moses/FF/PhraseOrientationFeature.h"
|
||||
|
||||
#include "moses/FF/SkeletonStatelessFF.h"
|
||||
#include "moses/FF/SkeletonStatefulFF.h"
|
||||
@ -211,6 +212,7 @@ FeatureRegistry::FeatureRegistry()
|
||||
MOSES_FNAME(SparseHieroReorderingFeature);
|
||||
MOSES_FNAME(SpanLength);
|
||||
MOSES_FNAME(SyntaxRHS);
|
||||
MOSES_FNAME(PhraseOrientationFeature);
|
||||
|
||||
MOSES_FNAME(SkeletonStatelessFF);
|
||||
MOSES_FNAME(SkeletonStatefulFF);
|
||||
|
112
moses/FF/PhraseOrientationFeature.cpp
Normal file
112
moses/FF/PhraseOrientationFeature.cpp
Normal file
@ -0,0 +1,112 @@
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
#include <assert.h>
|
||||
#include "PhraseOrientationFeature.h"
|
||||
#include "moses/StaticData.h"
|
||||
#include "moses/InputFileStream.h"
|
||||
#include "moses/ScoreComponentCollection.h"
|
||||
#include "moses/Hypothesis.h"
|
||||
#include "moses/ChartHypothesis.h"
|
||||
#include "moses/ChartManager.h"
|
||||
#include "moses/FactorCollection.h"
|
||||
#include "moses/PP/OrientationPhraseProperty.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
PhraseOrientationFeature::PhraseOrientationFeature(const std::string &line)
|
||||
: StatelessFeatureFunction(8, line)
|
||||
{
|
||||
VERBOSE(1, "Initializing feature " << GetScoreProducerDescription() << " ...");
|
||||
ReadParameters();
|
||||
VERBOSE(1, " Done.");
|
||||
}
|
||||
|
||||
void PhraseOrientationFeature::SetParameter(const std::string& key, const std::string& value)
|
||||
{
|
||||
if (key == "tuneable") {
|
||||
m_tuneable = Scan<bool>(value);
|
||||
} else {
|
||||
StatelessFeatureFunction::SetParameter(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void PhraseOrientationFeature::EvaluateWhenApplied(
|
||||
const ChartHypothesis& hypo,
|
||||
ScoreComponentCollection* accumulator) const
|
||||
{
|
||||
// dense scores
|
||||
std::vector<float> newScores(m_numScoreComponents,0); // m_numScoreComponents == 8
|
||||
|
||||
// const InputType& input = hypo.GetManager().GetSource();
|
||||
|
||||
// read Orientation property
|
||||
const TargetPhrase &currTarPhr = hypo.GetCurrTargetPhrase();
|
||||
// const Factor* targetLHS = currTarPhr.GetTargetLHS()[0];
|
||||
// bool isGlueGrammarRule = false;
|
||||
bool isUnkRule = false;
|
||||
|
||||
// get index map for underlying hypotheses
|
||||
const AlignmentInfo::NonTermIndexMap &nonTermIndexMap =
|
||||
currTarPhr.GetAlignNonTerm().GetNonTermIndexMap();
|
||||
|
||||
size_t nonTerminalNumber = 0;
|
||||
|
||||
for (size_t phrasePos=0; phrasePos<currTarPhr.GetSize(); ++phrasePos) {
|
||||
// consult rule for either word or non-terminal
|
||||
const Word &word = currTarPhr.GetWord(phrasePos);
|
||||
if ( word.IsNonTerminal() ) {
|
||||
// non-terminal: consult subderivation
|
||||
size_t nonTermIndex = nonTermIndexMap[phrasePos];
|
||||
const ChartHypothesis *prevHypo = hypo.GetPrevHypo(nonTermIndex);
|
||||
const TargetPhrase &prevTarPhr = prevHypo->GetCurrTargetPhrase();
|
||||
if (const PhraseProperty *property = prevTarPhr.GetProperty("Orientation")) {
|
||||
const OrientationPhraseProperty *orientationPhraseProperty = static_cast<const OrientationPhraseProperty*>(property);
|
||||
|
||||
std::cerr << "L2R_Mono " << orientationPhraseProperty->GetLeftToRightProbabilityMono();
|
||||
std::cerr << " L2R_Swap " << orientationPhraseProperty->GetLeftToRightProbabilitySwap();
|
||||
std::cerr << " L2R_Dright " << orientationPhraseProperty->GetLeftToRightProbabilityDright();
|
||||
std::cerr << " L2R_Dleft " << orientationPhraseProperty->GetLeftToRightProbabilityDleft();
|
||||
std::cerr << " R2L_Mono " << orientationPhraseProperty->GetRightToLeftProbabilityMono();
|
||||
std::cerr << " R2L_Swap " << orientationPhraseProperty->GetRightToLeftProbabilitySwap();
|
||||
std::cerr << " R2L_Dright " << orientationPhraseProperty->GetRightToLeftProbabilityDright();
|
||||
std::cerr << " R2L_Dleft " << orientationPhraseProperty->GetRightToLeftProbabilityDleft();
|
||||
std::cerr << std::endl;
|
||||
|
||||
} else {
|
||||
// abort with error message if the phrase does not translate an unknown word
|
||||
UTIL_THROW_IF2(!currTarPhr.GetWord(0).IsOOV(), GetScoreProducerDescription()
|
||||
<< ": Missing Orientation property. "
|
||||
<< "Please check phrase table and glue rules.");
|
||||
// unknown word
|
||||
isUnkRule = true;
|
||||
}
|
||||
|
||||
const WordsRange& prevWordsRange = prevHypo->GetCurrSourceRange();
|
||||
size_t prevStartPos = prevWordsRange.GetStartPos();
|
||||
size_t prevEndPos = prevWordsRange.GetEndPos();
|
||||
|
||||
++nonTerminalNumber;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// add scores
|
||||
// newScores[0] = orientationPhraseProperty.GetLeftToRightProbabilityMono();
|
||||
// newScores[1] = orientationPhraseProperty.GetLeftToRightProbabilitySwap();
|
||||
// newScores[2] = orientationPhraseProperty.GetLeftToRightProbabilityDright();
|
||||
// newScores[3] = orientationPhraseProperty.GetLeftToRightProbabilityDleft();
|
||||
// newScores[4] = orientationPhraseProperty.GetRightToLeftProbabilityMono();
|
||||
// newScores[5] = orientationPhraseProperty.GetRightToLeftProbabilitySwap();
|
||||
// newScores[6] = orientationPhraseProperty.GetRightToLeftProbabilityDright();
|
||||
// newScores[7] = orientationPhraseProperty.GetRightToLeftProbabilityDleft();
|
||||
|
||||
accumulator->PlusEquals(this, newScores);
|
||||
}
|
||||
|
||||
}
|
||||
|
55
moses/FF/PhraseOrientationFeature.h
Normal file
55
moses/FF/PhraseOrientationFeature.h
Normal file
@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include "StatelessFeatureFunction.h"
|
||||
#include "FFState.h"
|
||||
#include "moses/Factor.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
|
||||
class PhraseOrientationFeature : public StatelessFeatureFunction
|
||||
{
|
||||
public:
|
||||
PhraseOrientationFeature(const std::string &line);
|
||||
|
||||
~PhraseOrientationFeature() {
|
||||
}
|
||||
|
||||
bool IsUseable(const FactorMask &mask) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void SetParameter(const std::string& key, const std::string& value);
|
||||
|
||||
void EvaluateInIsolation(const Phrase &source
|
||||
, const TargetPhrase &targetPhrase
|
||||
, ScoreComponentCollection &scoreBreakdown
|
||||
, ScoreComponentCollection &estimatedFutureScore) const
|
||||
{};
|
||||
|
||||
void EvaluateWithSourceContext(const InputType &input
|
||||
, const InputPath &inputPath
|
||||
, const TargetPhrase &targetPhrase
|
||||
, const StackVec *stackVec
|
||||
, ScoreComponentCollection &scoreBreakdown
|
||||
, ScoreComponentCollection *estimatedFutureScore = NULL) const
|
||||
{};
|
||||
|
||||
void EvaluateWhenApplied(
|
||||
const Hypothesis& cur_hypo,
|
||||
ScoreComponentCollection* accumulator) const
|
||||
{};
|
||||
|
||||
void EvaluateWhenApplied(
|
||||
const ChartHypothesis& cur_hypo,
|
||||
ScoreComponentCollection* accumulator) const;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user