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

vocab.h « data « src - github.com/marian-nmt/marian.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 391083a1f12fc0bc93390843f832e3c424df988b (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
#pragma once

#include <map>
#include <string>
#include <vector>

#include "common/file_stream.h"
#include "data/types.h"

namespace marian {

class Vocab {
public:
  Vocab();

  size_t operator[](const std::string& word) const;

  Words operator()(const std::vector<std::string>& lineTokens,
                   bool addEOS = true) const;

  Words operator()(const std::string& line, bool addEOS = true) const;

  std::vector<std::string> operator()(const Words& sentence,
                                      bool ignoreEOS = true) const;

  const std::string& operator[](size_t id) const;

  size_t size() const;

  int loadOrCreate(const std::string& vocabPath,
                   const std::string& textPath,
                   int max = 0);
  int load(const std::string& vocabPath, int max = 0);
  void create(const std::string& vocabPath, const std::string& trainPath);
  void create(InputFileStream& trainStrm,
              OutputFileStream& vocabStrm,
              size_t maxSize = 0);
    
  Word GetEosId() const { return eosId_; }
  Word GetUnkId() const { return unkId_; }

private:
  typedef std::map<std::string, size_t> Str2Id;
  Str2Id str2id_;

  typedef std::vector<std::string> Id2Str;
  Id2Str id2str_;

  Word eosId_ = -1;
  Word unkId_ = -1;

  class VocabFreqOrderer;
};
}