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

PhraseDictionaryTree.h « src « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ebe43a61816e7bbad91e0af727fdff0656d889be (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// $Id$

#ifndef moses_PhraseDictionaryTree_h
#define moses_PhraseDictionaryTree_h

#include <string>
#include <vector>
#include <iostream>

#ifdef WITH_THREADS
#include <boost/thread/mutex.hpp>
#endif

#include "TypeDef.h"
#include "Dictionary.h"


#include "PrefixTree.h"
#include "File.h"
#include "ObjectPool.h"
#include "LexicalReorderingTable.h"
#include "LVoc.h"
#include "TypeDef.h"
#include "Util.h"

namespace Moses
{

class Phrase;
class Word;
class ConfusionNet;
class PDTimp;

typedef PrefixTreeF<LabelId,OFF_T> PTF;

//typedef std::pair<std::vector<std::string const*>,Scores > StringTgtCand;
struct StringTgtCand
{
  typedef std::vector<std::string const*> Tokens;
  Tokens tokens;
  Scores scores;
  Tokens fnames;
  std::vector<FValue> fvalues;

};

class PhraseDictionaryTree : public Dictionary
{
  PDTimp *imp; //implementation

  PhraseDictionaryTree(); // not implemented
  PhraseDictionaryTree(const PhraseDictionaryTree&); //not implemented
  void operator=(const PhraseDictionaryTree&); //not implemented
public:
  PhraseDictionaryTree(size_t numScoreComponent);

  void UseWordAlignment(bool a);
  bool UseWordAlignment();

  void PrintWordAlignment(bool a);
  bool PrintWordAlignment();


  virtual ~PhraseDictionaryTree();

  DecodeType GetDecodeType() const {
    return Translate;
  }
  size_t GetSize() const {
    return 0;
  }

  // convert from ascii phrase table format
  // note: only creates table, does not keep it in memory
  //        -> use Read(outFileNamePrefix);
  int Create(std::istream& in,const std::string& outFileNamePrefix);

  int Read(const std::string& fileNamePrefix);

  // free memory used by the prefix tree etc.
  void FreeMemory() const;


  /**************************************
   *   access with full source phrase   *
   **************************************/
  // print target candidates for a given phrase, mainly for debugging
  void PrintTargetCandidates(const std::vector<std::string>& src,
                             std::ostream& out) const;

  // get the target candidates for a given phrase
  void GetTargetCandidates(const std::vector<std::string>& src,
                           std::vector<StringTgtCand>& rv) const;
                           

  // get the target candidates for a given phrase
  void GetTargetCandidates(const std::vector<std::string>& src,
                           std::vector<StringTgtCand>& rv,
                           std::vector<std::string>& wa) const;

  /*****************************
   *   access to prefix tree   *
   *****************************/

  // 'pointer' into prefix tree
  // the only permitted direct operation is a check for NULL,
  // e.g. PrefixPtr p; if(p) ...
  // other usage only through PhraseDictionaryTree-functions below

  class PrefixPtr
  {
    PPimp* imp;
    friend class PDTimp;
  public:
    PrefixPtr(PPimp* x=0) : imp(x) {}
    operator bool() const;
  };

  // return pointer to root node
  PrefixPtr GetRoot() const;
  // extend pointer with a word/Factorstring and return the resulting successor
  // pointer. If there is no such successor node, the result will evaluate to
  // false. Requirement: the input pointer p evaluates to true.
  PrefixPtr Extend(PrefixPtr p,const std::string& s) const;

  // get the target candidates for a given prefix pointer
  // requirement: the pointer has to evaluate to true
  void GetTargetCandidates(PrefixPtr p,
                           std::vector<StringTgtCand>& rv) const;
  void GetTargetCandidates(PrefixPtr p,
                           std::vector<StringTgtCand>& rv,
                           std::vector<std::string>& wa) const;

  // print target candidates for a given prefix pointer to a stream, mainly
  // for debugging
  void PrintTargetCandidates(PrefixPtr p,std::ostream& out) const;
  std::string GetScoreProducerDescription(unsigned) const;
  std::string GetScoreProducerWeightShortName(unsigned) const {
    return "tm";
  }
};


}

#endif