~mshinke/nvdajp/MiscellaneousDependencies

« back to all changes in this revision

Viewing changes to include/jtalk/libopenjtalk/mecab/src/connector.h

  • Committer: Masataka Shinke
  • Date: 2012-01-12 20:01:32 UTC
  • mfrom: (26.1.42 miscdep)
  • Revision ID: mshinke@users.sourceforge.jp-20120112200132-fvksmjulcjdzu5mk
mergedĀ lp:~nishimotz/nvdajp/MiscellaneousDependenciesĀ 68

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// MeCab -- Yet Another Part-of-Speech and Morphological Analyzer
 
2
//
 
3
//
 
4
//  Copyright(C) 2001-2006 Taku Kudo <taku@chasen.org>
 
5
//  Copyright(C) 2004-2006 Nippon Telegraph and Telephone Corporation
 
6
#ifndef MECAB_CONNECTOR_H
 
7
#define MECAB_CONNECTOR_H
 
8
 
 
9
#include "mecab.h"
 
10
#include "common.h"
 
11
 
 
12
namespace MeCab {
 
13
class Param;
 
14
template <class T> class Mmap;
 
15
 
 
16
class Connector {
 
17
 private:
 
18
  Mmap<short>    *cmmap_;
 
19
  short          *matrix_;
 
20
  unsigned short  lsize_;
 
21
  unsigned short  rsize_;
 
22
  whatlog         what_;
 
23
 
 
24
 public:
 
25
 
 
26
  bool open(const Param &param);
 
27
  void close();
 
28
  void clear() {}
 
29
 
 
30
  const char *what() { return what_.str(); }
 
31
 
 
32
  size_t left_size()  const { return static_cast<size_t>(lsize_); }
 
33
  size_t right_size() const { return static_cast<size_t>(rsize_); }
 
34
 
 
35
  void set_left_size(size_t lsize)  { lsize_ = lsize; }
 
36
  void set_right_size(size_t rsize) { rsize_ = rsize; }
 
37
 
 
38
  inline int cost(const Node *lNode, const Node *rNode) const {
 
39
    return matrix_[ lNode->rcAttr + lsize_ * rNode->lcAttr ] + rNode->wcost;
 
40
  }
 
41
 
 
42
  // access to raw matrix
 
43
  short *mutable_matrix() { return &matrix_[0]; }
 
44
  const short *matrix() const { return &matrix_[0]; }
 
45
 
 
46
  bool openText(const char *filename);
 
47
  bool open(const char *filename, const char *mode = "r");
 
48
 
 
49
  bool is_valid(size_t lid, size_t rid) const {
 
50
    return (lid >= 0 && lid < rsize_ && rid >= 0 && rid < lsize_);
 
51
  }
 
52
 
 
53
  static bool compile(const char *, const char *);
 
54
 
 
55
  explicit Connector():
 
56
      cmmap_(0), matrix_(0), lsize_(0), rsize_(0) {}
 
57
 
 
58
  virtual ~Connector() { this->close(); }
 
59
};
 
60
}
 
61
#endif