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

ProbingPT.h « ProbingPT « TranslationModel « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 953a2dc2f5854f4c2befe8803df176c5291d8ba8 (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

#pragma once
#include <boost/iostreams/device/mapped_file.hpp>
#include <boost/bimap.hpp>
#include <boost/unordered_map.hpp>
#include "../PhraseDictionary.h"


namespace Moses
{
class ChartParser;
class ChartCellCollectionBase;
class ChartRuleLookupManager;
class QueryEngine;
class target_text;

class ProbingPT : public PhraseDictionary
{
  friend std::ostream& operator<<(std::ostream&, const ProbingPT&);

public:
  ProbingPT(const std::string &line);
  ~ProbingPT();

  void Load(AllOptions::ptr const& opts);

  void InitializeForInput(ttasksptr const& ttask);

  // for phrase-based model
  void GetTargetPhraseCollectionBatch(const InputPathList &inputPathQueue) const;

  // for syntax/hiero model (CKY+ decoding)
  virtual ChartRuleLookupManager *CreateRuleLookupManager(
    const ChartParser &,
    const ChartCellCollectionBase &,
    std::size_t);

  TO_STRING();


protected:
  QueryEngine *m_engine;
  uint64_t m_unkId;

  std::vector<uint64_t> m_sourceVocab; // factor id -> pt id
  std::vector<const Factor*> m_targetVocab; // pt id -> factor*
  std::vector<const AlignmentInfo*> m_aligns;

  boost::iostreams::mapped_file_source file;
  const char *data;

  // caching
  typedef boost::unordered_map<uint64_t, TargetPhraseCollection*> CachePb;
  CachePb m_cachePb;

  void CreateAlignmentMap(const std::string path);

  TargetPhraseCollection::shared_ptr CreateTargetPhrase(const Phrase &sourcePhrase) const;

  std::pair<bool, uint64_t> GetKey(const Phrase &sourcePhrase) const;
  void GetSourceProbingIds(const Phrase &sourcePhrase, bool &ok,
                           uint64_t probingSource[]) const;
  uint64_t GetSourceProbingId(const Word &word) const;
  uint64_t GetSourceProbingId(const Factor *factor) const;

  TargetPhraseCollection *CreateTargetPhrases(
    const Phrase &sourcePhrase, uint64_t key) const;
  TargetPhrase *CreateTargetPhrase(
    const char *&offset) const;

  inline const Factor *GetTargetFactor(uint32_t probingId) const {
    if (probingId >= m_targetVocab.size()) {
      return NULL;
    }
    return m_targetVocab[probingId];
  }

};

}  // namespace Moses