File: test.pl

package info (click to toggle)
libmecab-perl 0.99.6-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 368 kB
  • ctags: 533
  • sloc: cpp: 6,208; perl: 374; makefile: 2
file content (52 lines) | stat: -rw-r--r-- 1,436 bytes parent folder | download | duplicates (4)
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
#!/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 $model = new MeCab::Model(join " ", @ARGV);
my $c = $model->createTagger();

print $c->parse($sentence);

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

my $lattice = new MeCab::Lattice();
$lattice->set_sentence($sentence);

if ($c->parse($lattice)) {
    for (my $i = 0; $i < $lattice->size(); ++$i) {
	for (my $b = $lattice->begin_nodes($i); $b; $b = $b->{bnext}) {
	    printf("B[%d] %s\t%s\n", $i, $b->{surface}, $b->{feature});
	}
	for (my $e = $lattice->end_nodes($i); $e; $e = $e->{enext}) {
	    printf("E[%d] %s\t%s\n", $i, $e->{surface}, $e->{feature});
	}
    }
}

$lattice->set_sentence($sentence);
$lattice->set_request_type($MeCab::MECAB_NBEST);
if ($c->parse($lattice)) {
    for (my $i = 0; $i < 10; ++$i) {
	$lattice->next();
	print $lattice->toString();
    }
}

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});
}