4 #define CHECK(eval) if (! eval) { \
5 const char *e = tagger ? tagger->what() : MeCab::getTaggerError(); \
6 std::cerr << "Exception:" << e << std::endl; \
10 // Sample of MeCab::Tagger class.
11 int main (int argc, char **argv) {
12 char input[] = "太郎は次郎が持っている本を花子に渡した。";
14 MeCab::Tagger *tagger = MeCab::createTagger("");
17 // Gets tagged result in string format.
18 const char *result = tagger->parse(input);
20 std::cout << "INPUT: " << input << std::endl;
21 std::cout << "RESULT: " << result << std::endl;
23 // Gets N best results in string format.
24 result = tagger->parseNBest(3, input);
26 std::cout << "NBEST: " << std::endl << result;
28 // Gets N best results in sequence.
29 CHECK(tagger->parseNBestInit(input));
30 for (int i = 0; i < 3; ++i) {
31 std::cout << i << ":" << std::endl << tagger->next();
35 const MeCab::Node* node = tagger->parseToNode(input);
37 for (; node; node = node->next) {
38 std::cout << node->id << ' ';
39 if (node->stat == MECAB_BOS_NODE)
41 else if (node->stat == MECAB_EOS_NODE)
44 std::cout.write (node->surface, node->length);
46 std::cout << ' ' << node->feature
47 << ' ' << (int)(node->surface - input)
48 << ' ' << (int)(node->surface - input + node->length)
49 << ' ' << node->rcAttr
50 << ' ' << node->lcAttr
52 << ' ' << (int)node->char_type
53 << ' ' << (int)node->stat
54 << ' ' << (int)node->isbest
58 << ' ' << node->cost << std::endl;
62 const MeCab::DictionaryInfo *d = tagger->dictionary_info();
63 for (; d; d = d->next) {
64 std::cout << "filename: " << d->filename << std::endl;
65 std::cout << "charset: " << d->charset << std::endl;
66 std::cout << "size: " << d->size << std::endl;
67 std::cout << "type: " << d->type << std::endl;
68 std::cout << "lsize: " << d->lsize << std::endl;
69 std::cout << "rsize: " << d->rsize << std::endl;
70 std::cout << "version: " << d->version << std::endl;