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

osmHyp.h « OSM « FF « moses2 « contrib - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c2893d366f564aa63bb8ce659fffe2f30d67a6b7 (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
109
110
111
#pragma once

# include <set>
# include <map>
# include <string>
# include <vector>
#include "KenOSM.h"
# include "../FFState.h"
# include "../../legacy/Bitmap.h"

namespace Moses2
{

class osmState : public FFState
{
public:
  osmState()
  {}

  void setState(const lm::ngram::State & val);

  virtual size_t hash() const;
  virtual bool operator==(const FFState& other) const;

  virtual std::string ToString() const
  { return "osmState"; }

  void saveState(int jVal, int eVal, std::map <int , std::string> & gapVal);
  int getJ()const {
    return j;
  }
  int getE()const {
    return E;
  }
  std::map <int , std::string> getGap() const {
    return gap;
  }

  lm::ngram::State getLMState() const {
    return lmState;
  }

  void print() const;
  std::string getName() const;

protected:
  int j, E;
  std::map <int,std::string> gap;
  lm::ngram::State lmState;
};

class osmHypothesis
{

private:


  std::vector <std::string> operations; // List of operations required to generated this hyp ...
  std::map <int,std::string> gap; // Maintains gap history ...
  int j;  // Position after the last source word generated ...
  int E; // Position after the right most source word so far generated ...
  lm::ngram::State lmState; // KenLM's Model State ...

  int gapCount; // Number of gaps inserted ...
  int deletionCount;
  int openGapCount;
  int gapWidth;
  double opProb;

  std::vector <std::string> currE;
  std::vector <std::string> currF;
  std::vector < std::pair < std::set <int> , std::set <int> > > ceptsInPhrase;
  std::set <int> targetNullWords;
  std::set <int> sourceNullWords;

  int closestGap(std::map <int,std::string> gap,int j1, int & gp);
  int firstOpenGap(std::vector <int> & coverageVector);
  std::string intToString(int);
  int  getOpenGaps();
  int isTranslationOperation(int j);
  void removeReorderingOperations();

  void getMeCepts ( std::set <int> & eSide , std::set <int> & fSide , std::map <int , std::vector <int> > & tS , std::map <int , std::vector <int> > & sT);

public:

  osmHypothesis();
  ~osmHypothesis() {};
  void generateOperations(int & startIndex, int j1 , int contFlag , Bitmap & coverageVector , std::string english , std::string german , std::set <int> & targetNullWords , std::vector <std::string> & currF);
  void generateDeleteOperations(std::string english, int currTargetIndex, std::set <int> doneTargetIndexes);
  void calculateOSMProb(OSMLM& ptrOp);
  void computeOSMFeature(int startIndex , Bitmap & coverageVector);
  void constructCepts(std::vector <int> & align , int startIndex , int endIndex, int targetPhraseLength);
  void setPhrases(std::vector <std::string> & val1 , std::vector <std::string> & val2) {
    currF = val1;
    currE = val2;
  }
  void setState(const FFState* prev_state);
  void saveState(osmState &state);
  void print();
  void populateScores(std::vector <float> & scores , const int numFeatures);
  void setState(const lm::ngram::State & val) {
    lmState = val;
  }

};

} // namespace