mosesdecoder/moses/FF/SoftSourceSyntacticConstraintsFeature.h
2014-08-08 16:41:07 +01:00

88 lines
2.6 KiB
C++

#pragma once
#include <string>
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
#include "StatelessFeatureFunction.h"
#include "FFState.h"
#include "moses/Factor.h"
namespace Moses
{
class SoftSourceSyntacticConstraintsFeature : public StatelessFeatureFunction
{
public:
SoftSourceSyntacticConstraintsFeature(const std::string &line);
~SoftSourceSyntacticConstraintsFeature() {
for (boost::unordered_map<const Factor*, std::vector< std::pair<float,float> >* >::iterator iter=m_labelPairProbabilities.begin();
iter!=m_labelPairProbabilities.end(); ++iter) {
delete iter->second;
}
}
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:
std::string m_sourceLabelSetFile;
std::string m_coreSourceLabelSetFile;
std::string m_targetSourceLHSJointCountFile;
std::string m_unknownLeftHandSideFile;
size_t m_featureVariant;
boost::unordered_map<std::string,size_t> m_sourceLabels;
std::vector<std::string> m_sourceLabelsByIndex;
boost::unordered_set<size_t> m_coreSourceLabels;
boost::unordered_map<const Factor*,size_t> m_sourceLabelIndexesByFactor;
size_t m_GlueTopLabel;
// mutable size_t m_XRHSLabel;
// mutable size_t m_XLHSLabel;
boost::unordered_map<const Factor*, std::vector< std::pair<float,float> >* > m_labelPairProbabilities;
boost::unordered_map<size_t,float> m_unknownLHSProbabilities;
float m_smoothingWeight;
float m_unseenLHSSmoothingFactorForUnknowns;
void Load();
void LoadSourceLabelSet();
void LoadCoreSourceLabelSet();
void LoadTargetSourceLeftHandSideJointCountFile();
std::pair<float,float> GetLabelPairProbabilities(const Factor* target,
const size_t source) const;
};
}