File: test.pl

package info (click to toggle)
libmecab-perl 0.98-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 280 kB
  • ctags: 477
  • sloc: cpp: 4,210; perl: 286; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 1,149 bytes parent folder | download
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
#!/usr/bin/perl

use lib "../src/.libs";
use lib $ENV{PWD} . "/blib/lib";
use lib $ENV{PWD} . "/blib/arch";
use MeCab;

print $MeCab::VERSION, "\n";

my $sentence = "太郎はこの本を二郎を見た女性に渡した。";

my $c = new MeCab::Tagger(join " ", @ARGV);

print $c->parse($sentence);
for (my $m = $c->parseToNode($sentence); $m; $m = $m->{next}) {
    printf("%s\t%s\n", $m->{surface}, $m->{feature});
}

my $m = $c->parseToNode($sentence);
my $len = $m->{sentence_length};
for (my $i = 0; $i <= $len; ++$i) {
    for (my $b = $m->begin_node_list($i); $b; $b = $b->{bnext}) {
	printf("B[%d] %s\t%s\n", $i, $b->{surface}, $b->{feature});
    }
    for (my $e = $m->end_node_list($i); $e; $e = $e->{enext}) {
	printf("E[%d] %s\t%s\n", $i, $e->{surface}, $e->{feature});	
    }    
}

for (my $d = $c->dictionary_info(); $d; $d = $d->{next}) {
    printf("filename: %s\n", $d->{filename});
    printf("charset: %s\n", $d->{charset});
    printf("size: %d\n", $d->{size});
    printf("type: %d\n", $d->{type});
    printf("lsize: %d\n", $d->{lsize});
    printf("rsize: %d\n", $d->{rsize});
    printf("version: %d\n", $d->{version});
}