@kyanny's blog

My thoughts, my life. Views/opinions are my own.

Lingua::JA::Summarize 入門

Lingua::JA::Summarize sample · GitHub

#!/usr/bin/env perl
use strict;
use warnings;
use Lingua::JA::Summarize;
use Perl6::Say;
use Encode;

my $in = do { local $/; <>; };
my $s = Lingua::JA::Summarize->new({
    charset => 'utf8',
    mecab_charset => 'utf8',
    default_cost => 1.8,
    singlechar_factor => 0.2,
});
$s->analyze($in);
my @keywords = $s->keywords({
    threshold => 4,
    maxwords => 10,
    minwords => 3,
});

for my $keyword (@keywords) {
    say $keyword;
}
  • mecab の辞書 (ipadic) は --with-charset=utf-8 で作ってある
  • new() にオプションを渡さないといろいろ化ける
  • charset => 'utf8' ... Lingua::JA::Summarize に対する charset 指定
  • mecab_charset => 'utf8' ... mecab に対する charset 指定
  • 両方 utf8 にしないと化けたのでこれで