00001 #pragma once
00002
00003 #include <string>
00004 #include <boost/unordered_map.hpp>
00005 #include <boost/unordered_set.hpp>
00006 #include "StatelessFeatureFunction.h"
00007 #include "moses/TargetPhrase.h"
00008 #include "moses/Factor.h"
00009
00010 namespace Moses
00011 {
00012
00013
00014 class SoftSourceSyntacticConstraintsFeature : public StatelessFeatureFunction
00015 {
00016
00017 public:
00018
00019 SoftSourceSyntacticConstraintsFeature(const std::string &line);
00020
00021 ~SoftSourceSyntacticConstraintsFeature() {
00022 for (boost::unordered_map<const Factor*, std::vector< std::pair<float,float> >* >::iterator iter=m_labelPairProbabilities.begin();
00023 iter!=m_labelPairProbabilities.end(); ++iter) {
00024 delete iter->second;
00025 }
00026 }
00027
00028 bool IsUseable(const FactorMask &mask) const {
00029 return true;
00030 }
00031
00032 void SetParameter(const std::string& key, const std::string& value);
00033
00034 void Load(AllOptions::ptr const& opts);
00035
00036 void EvaluateInIsolation(const Phrase &source
00037 , const TargetPhrase &targetPhrase
00038 , ScoreComponentCollection &scoreBreakdown
00039 , ScoreComponentCollection &estimatedScores) const {
00040 targetPhrase.SetRuleSource(source);
00041 };
00042
00043 void EvaluateWithSourceContext(const InputType &input
00044 , const InputPath &inputPath
00045 , const TargetPhrase &targetPhrase
00046 , const StackVec *stackVec
00047 , ScoreComponentCollection &scoreBreakdown
00048 , ScoreComponentCollection *estimatedScores = NULL) const;
00049
00050 void EvaluateTranslationOptionListWithSourceContext(const InputType &input
00051 , const TranslationOptionList &translationOptionList) const
00052 {}
00053
00054 void EvaluateWhenApplied(
00055 const Hypothesis& cur_hypo,
00056 ScoreComponentCollection* accumulator) const
00057 {};
00058
00059 void EvaluateWhenApplied(
00060 const ChartHypothesis& cur_hypo,
00061 ScoreComponentCollection* accumulator) const
00062 {};
00063
00064
00065 protected:
00066
00067 std::string m_sourceLabelSetFile;
00068 std::string m_coreSourceLabelSetFile;
00069 std::string m_targetSourceLHSJointCountFile;
00070 std::string m_unknownLeftHandSideFile;
00071 bool m_useCoreSourceLabels;
00072 bool m_useLogprobs;
00073 bool m_useSparse;
00074 bool m_useSparseLabelPairs;
00075 bool m_noMismatches;
00076 float m_floor;
00077
00078 boost::unordered_map<std::string,size_t> m_sourceLabels;
00079 std::vector<std::string> m_sourceLabelsByIndex;
00080 std::vector<std::string> m_sourceLabelsByIndex_RHS_1;
00081 std::vector<std::string> m_sourceLabelsByIndex_RHS_0;
00082 std::vector<std::string> m_sourceLabelsByIndex_LHS_1;
00083 std::vector<std::string> m_sourceLabelsByIndex_LHS_0;
00084 boost::unordered_set<size_t> m_coreSourceLabels;
00085 boost::unordered_map<const Factor*,size_t> m_sourceLabelIndexesByFactor;
00086 size_t m_GlueTopLabel;
00087
00088
00089
00090 boost::unordered_map<const Factor*, std::vector< std::pair<float,float> >* > m_labelPairProbabilities;
00091 boost::unordered_map<size_t,float> m_unknownLHSProbabilities;
00092 float m_smoothingWeight;
00093 float m_unseenLHSSmoothingFactorForUnknowns;
00094
00095 void LoadSourceLabelSet();
00096 void LoadCoreSourceLabelSet();
00097 void LoadTargetSourceLeftHandSideJointCountFile();
00098
00099 void LoadLabelSet(std::string &filename, boost::unordered_set<size_t> &labelSet);
00100
00101 std::pair<float,float> GetLabelPairProbabilities(const Factor* target,
00102 const size_t source) const;
00103
00104 };
00105
00106
00107 }
00108