2014-08-08 19:30:02 +04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <boost/unordered_map.hpp>
|
|
|
|
#include <boost/unordered_set.hpp>
|
|
|
|
#include "StatelessFeatureFunction.h"
|
2015-11-16 21:58:14 +03:00
|
|
|
#include "moses/TargetPhrase.h"
|
2014-08-08 19:30:02 +04:00
|
|
|
#include "moses/Factor.h"
|
|
|
|
|
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
class SoftSourceSyntacticConstraintsFeature : public StatelessFeatureFunction
|
|
|
|
{
|
2015-01-28 23:49:04 +03:00
|
|
|
|
2014-08-08 19:30:02 +04:00
|
|
|
public:
|
2015-01-28 23:49:04 +03:00
|
|
|
|
2014-08-08 19:30:02 +04:00
|
|
|
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);
|
2015-02-19 15:27:23 +03:00
|
|
|
|
2015-12-10 06:17:36 +03:00
|
|
|
void Load(AllOptions::ptr const& opts);
|
2014-08-08 19:30:02 +04:00
|
|
|
|
|
|
|
void EvaluateInIsolation(const Phrase &source
|
2015-01-14 14:07:42 +03:00
|
|
|
, const TargetPhrase &targetPhrase
|
|
|
|
, ScoreComponentCollection &scoreBreakdown
|
2015-11-04 18:10:45 +03:00
|
|
|
, ScoreComponentCollection &estimatedScores) const {
|
2014-12-08 21:20:58 +03:00
|
|
|
targetPhrase.SetRuleSource(source);
|
|
|
|
};
|
2014-08-08 19:30:02 +04:00
|
|
|
|
|
|
|
void EvaluateWithSourceContext(const InputType &input
|
2015-01-14 14:07:42 +03:00
|
|
|
, const InputPath &inputPath
|
|
|
|
, const TargetPhrase &targetPhrase
|
|
|
|
, const StackVec *stackVec
|
|
|
|
, ScoreComponentCollection &scoreBreakdown
|
2015-11-04 18:10:45 +03:00
|
|
|
, ScoreComponentCollection *estimatedScores = NULL) const;
|
2014-08-08 19:30:02 +04:00
|
|
|
|
2015-01-06 15:56:13 +03:00
|
|
|
void EvaluateTranslationOptionListWithSourceContext(const InputType &input
|
2015-01-23 21:41:18 +03:00
|
|
|
, const TranslationOptionList &translationOptionList) const
|
|
|
|
{}
|
2015-01-06 12:46:31 +03:00
|
|
|
|
2014-08-08 19:30:02 +04:00
|
|
|
void EvaluateWhenApplied(
|
|
|
|
const Hypothesis& cur_hypo,
|
2015-01-23 21:41:18 +03:00
|
|
|
ScoreComponentCollection* accumulator) const
|
|
|
|
{};
|
2014-08-08 19:30:02 +04:00
|
|
|
|
|
|
|
void EvaluateWhenApplied(
|
|
|
|
const ChartHypothesis& cur_hypo,
|
2015-01-23 21:41:18 +03:00
|
|
|
ScoreComponentCollection* accumulator) const
|
|
|
|
{};
|
2014-08-08 19:30:02 +04:00
|
|
|
|
2015-01-28 23:49:04 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2014-08-08 19:30:02 +04:00
|
|
|
std::string m_sourceLabelSetFile;
|
|
|
|
std::string m_coreSourceLabelSetFile;
|
|
|
|
std::string m_targetSourceLHSJointCountFile;
|
|
|
|
std::string m_unknownLeftHandSideFile;
|
2015-01-27 21:15:51 +03:00
|
|
|
bool m_useCoreSourceLabels;
|
|
|
|
bool m_useLogprobs;
|
|
|
|
bool m_useSparse;
|
2015-02-26 23:27:02 +03:00
|
|
|
bool m_useSparseLabelPairs;
|
2015-01-27 21:15:51 +03:00
|
|
|
bool m_noMismatches;
|
2015-02-26 23:27:02 +03:00
|
|
|
float m_floor;
|
2014-08-08 19:30:02 +04:00
|
|
|
|
2014-08-08 19:41:07 +04:00
|
|
|
boost::unordered_map<std::string,size_t> m_sourceLabels;
|
|
|
|
std::vector<std::string> m_sourceLabelsByIndex;
|
2015-01-09 17:04:19 +03:00
|
|
|
std::vector<std::string> m_sourceLabelsByIndex_RHS_1;
|
|
|
|
std::vector<std::string> m_sourceLabelsByIndex_RHS_0;
|
|
|
|
std::vector<std::string> m_sourceLabelsByIndex_LHS_1;
|
|
|
|
std::vector<std::string> m_sourceLabelsByIndex_LHS_0;
|
2014-08-08 19:41:07 +04:00
|
|
|
boost::unordered_set<size_t> m_coreSourceLabels;
|
|
|
|
boost::unordered_map<const Factor*,size_t> m_sourceLabelIndexesByFactor;
|
|
|
|
size_t m_GlueTopLabel;
|
2014-08-08 19:30:02 +04:00
|
|
|
// 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 LoadSourceLabelSet();
|
|
|
|
void LoadCoreSourceLabelSet();
|
|
|
|
void LoadTargetSourceLeftHandSideJointCountFile();
|
|
|
|
|
2015-01-23 21:41:18 +03:00
|
|
|
void LoadLabelSet(std::string &filename, boost::unordered_set<size_t> &labelSet);
|
|
|
|
|
2015-01-14 14:07:42 +03:00
|
|
|
std::pair<float,float> GetLabelPairProbabilities(const Factor* target,
|
|
|
|
const size_t source) const;
|
2014-08-08 19:30:02 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|