summaryrefslogtreecommitdiff
path: root/decoder/tdict.h
blob: 6b90becbb6a768c3ca72ae42c6cd23a30a752a1b (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
#ifndef _TDICT_H_
#define _TDICT_H_

#include <string>
#include <vector>
#include "wordid.h"

class Vocab;

struct TD {
  static Vocab dict_;
  static void ConvertSentence(std::string const& sent, std::vector<WordID>* ids);
  static void GetWordIDs(const std::vector<std::string>& strings, std::vector<WordID>* ids);
  static std::string GetString(const std::vector<WordID>& str);
  static int AppendString(const WordID& w, int pos, int bufsize, char* buffer) {
    const char* word = TD::Convert(w);
    const char* const end_buf = buffer + bufsize;
    char* dest = buffer + pos;
    while(dest < end_buf && *word) {
      *dest = *word;
      ++dest;
      ++word;
    }
    return (dest - buffer);
  }
  static unsigned int NumWords();
  static WordID Convert(const std::string& s);
  static WordID Convert(char const* s);
  static const char* Convert(const WordID& w);
};

struct ToTD {
  typedef WordID result_type;
  result_type operator()(std::string const& t) const {
    return TD::Convert(t);
  }
};


#endif