Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SoftSourceSyntacticConstraintsFeature.h « FF « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 53b6c678e122b1b005d5605d35bd876de099b242 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#pragma once

#include <string>
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
#include "StatelessFeatureFunction.h"
#include "moses/TargetPhrase.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 Load();

  void EvaluateInIsolation(const Phrase &source
                           , const TargetPhrase &targetPhrase
                           , ScoreComponentCollection &scoreBreakdown
                           , ScoreComponentCollection &estimatedScores) const {
    targetPhrase.SetRuleSource(source);
  };

  void EvaluateWithSourceContext(const InputType &input
                                 , const InputPath &inputPath
                                 , const TargetPhrase &targetPhrase
                                 , const StackVec *stackVec
                                 , ScoreComponentCollection &scoreBreakdown
                                 , ScoreComponentCollection *estimatedScores = NULL) const;

  void EvaluateTranslationOptionListWithSourceContext(const InputType &input
      , const TranslationOptionList &translationOptionList) const
  {}

  void EvaluateWhenApplied(
    const Hypothesis& cur_hypo,
    ScoreComponentCollection* accumulator) const
  {};

  void EvaluateWhenApplied(
    const ChartHypothesis& cur_hypo,
    ScoreComponentCollection* accumulator) const
  {};


protected:

  std::string m_sourceLabelSetFile;
  std::string m_coreSourceLabelSetFile;
  std::string m_targetSourceLHSJointCountFile;
  std::string m_unknownLeftHandSideFile;
  bool m_useCoreSourceLabels;
  bool m_useLogprobs;
  bool m_useSparse;
  bool m_useSparseLabelPairs;
  bool m_noMismatches;
  float m_floor;

  boost::unordered_map<std::string,size_t> m_sourceLabels;
  std::vector<std::string> m_sourceLabelsByIndex;
  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;
  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 LoadSourceLabelSet();
  void LoadCoreSourceLabelSet();
  void LoadTargetSourceLeftHandSideJointCountFile();

  void LoadLabelSet(std::string &filename, boost::unordered_set<size_t> &labelSet);

  std::pair<float,float> GetLabelPairProbabilities(const Factor* target,
      const size_t source) const;

};


}