mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
span length
This commit is contained in:
parent
742d342fbb
commit
4a3ac7411d
@ -1311,6 +1311,16 @@
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/moses/FF/SourceWordDeletionFeature.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>FF/SpanLength.cpp</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/moses/FF/SpanLength.cpp</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>FF/SpanLength.h</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/moses/FF/SpanLength.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>FF/StatefulFeatureFunction.cpp</name>
|
||||
<type>1</type>
|
||||
@ -1621,6 +1631,11 @@
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-3-PROJECT_LOC/moses/PP/PhraseProperty.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>PP/SpanLengthPhraseProperty.h</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-1-ECLIPSE_HOME/github/mosesdecoder.hieu/moses/PP/SpanLengthPhraseProperty.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>PP/TreeStructurePhraseProperty.h</name>
|
||||
<type>1</type>
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "RuleScope.h"
|
||||
#include "MaxSpanFreeNonTermSource.h"
|
||||
#include "NieceTerminal.h"
|
||||
#include "SpanLength.h"
|
||||
|
||||
#include "moses/FF/SkeletonStatelessFF.h"
|
||||
#include "moses/FF/SkeletonStatefulFF.h"
|
||||
@ -189,6 +190,7 @@ FeatureRegistry::FeatureRegistry()
|
||||
MOSES_FNAME(RuleScope);
|
||||
MOSES_FNAME(MaxSpanFreeNonTermSource);
|
||||
MOSES_FNAME(NieceTerminal);
|
||||
MOSES_FNAME(SpanLength);
|
||||
|
||||
MOSES_FNAME(SkeletonStatelessFF);
|
||||
MOSES_FNAME(SkeletonStatefulFF);
|
||||
|
77
moses/FF/SpanLength.cpp
Normal file
77
moses/FF/SpanLength.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include "SpanLength.h"
|
||||
#include "moses/StaticData.h"
|
||||
#include "moses/Word.h"
|
||||
#include "moses/ChartCellLabel.h"
|
||||
#include "moses/WordsRange.h"
|
||||
#include "moses/StackVec.h"
|
||||
#include "moses/TargetPhrase.h"
|
||||
#include "moses/PP/PhraseProperty.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
SpanLength::SpanLength(const std::string &line)
|
||||
:StatelessFeatureFunction(1, line)
|
||||
,m_smoothingMethod(None)
|
||||
{
|
||||
}
|
||||
|
||||
void SpanLength::Evaluate(const Phrase &source
|
||||
, const TargetPhrase &targetPhrase
|
||||
, ScoreComponentCollection &scoreBreakdown
|
||||
, ScoreComponentCollection &estimatedFutureScore) const
|
||||
{
|
||||
targetPhrase.SetRuleSource(source);
|
||||
}
|
||||
|
||||
void SpanLength::Evaluate(const InputType &input
|
||||
, const InputPath &inputPath
|
||||
, const TargetPhrase &targetPhrase
|
||||
, const StackVec *stackVec
|
||||
, ScoreComponentCollection &scoreBreakdown
|
||||
, ScoreComponentCollection *estimatedFutureScore) const
|
||||
{
|
||||
assert(stackVec);
|
||||
|
||||
boost::shared_ptr<PhraseProperty> property;
|
||||
bool hasProperty = targetPhrase.GetProperty("SpanLength", &property);
|
||||
|
||||
|
||||
const Phrase *ruleSource = targetPhrase.GetRuleSource();
|
||||
assert(ruleSource);
|
||||
cerr << *ruleSource << endl;
|
||||
|
||||
for (size_t i = 0; i < stackVec->size(); ++i) {
|
||||
const ChartCellLabel &cell = *stackVec->at(i);
|
||||
const WordsRange &ntRange = cell.GetCoverage();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SpanLength::SetParameter(const std::string& key, const std::string& value)
|
||||
{
|
||||
if (key == "smoothing") {
|
||||
if (value == "plus-constant") {
|
||||
m_smoothingMethod = PlusConst;
|
||||
}
|
||||
else if (value == "none") {
|
||||
m_smoothingMethod = None;
|
||||
}
|
||||
else {
|
||||
UTIL_THROW(util::Exception, "Unknown smoothing type " << value);
|
||||
}
|
||||
}
|
||||
else if (key == "constant") {
|
||||
m_const = Scan<float>(value);
|
||||
}
|
||||
else {
|
||||
StatelessFeatureFunction::SetParameter(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
52
moses/FF/SpanLength.h
Normal file
52
moses/FF/SpanLength.h
Normal file
@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include "StatelessFeatureFunction.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
|
||||
// Rule Scope - not quite completely implemented yet
|
||||
class SpanLength : public StatelessFeatureFunction
|
||||
{
|
||||
public:
|
||||
SpanLength(const std::string &line);
|
||||
|
||||
virtual bool IsUseable(const FactorMask &mask) const
|
||||
{ return true; }
|
||||
|
||||
virtual void Evaluate(const Phrase &source
|
||||
, const TargetPhrase &targetPhrase
|
||||
, ScoreComponentCollection &scoreBreakdown
|
||||
, ScoreComponentCollection &estimatedFutureScore) const;
|
||||
|
||||
virtual void Evaluate(const InputType &input
|
||||
, const InputPath &inputPath
|
||||
, const TargetPhrase &targetPhrase
|
||||
, const StackVec *stackVec
|
||||
, ScoreComponentCollection &scoreBreakdown
|
||||
, ScoreComponentCollection *estimatedFutureScore = NULL) const;
|
||||
|
||||
|
||||
virtual void Evaluate(const Hypothesis& hypo,
|
||||
ScoreComponentCollection* accumulator) const
|
||||
{}
|
||||
|
||||
virtual void EvaluateChart(const ChartHypothesis &hypo,
|
||||
ScoreComponentCollection* accumulator) const
|
||||
{}
|
||||
|
||||
void SetParameter(const std::string& key, const std::string& value);
|
||||
|
||||
protected:
|
||||
enum SmoothingMethod
|
||||
{
|
||||
None,
|
||||
PlusConst,
|
||||
};
|
||||
SmoothingMethod m_smoothingMethod;
|
||||
|
||||
float m_const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "moses/PP/TreeStructurePhraseProperty.h"
|
||||
#include "moses/PP/SpanLengthPhraseProperty.h"
|
||||
|
||||
namespace Moses
|
||||
{
|
||||
@ -51,6 +52,7 @@ PhrasePropertyFactory::PhrasePropertyFactory()
|
||||
#define MOSES_PNAME2(name, type) Add(name, new DefaultPhrasePropertyCreator< type >());
|
||||
|
||||
MOSES_PNAME2("Tree",TreeStructurePhraseProperty);
|
||||
MOSES_PNAME2("SpanLength", SpanLengthPhraseProperty);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user