Text::MeCabで遊んでみる

MeCabのインストール

$ sudo aptitude install mecab libmecab-dev
$ su -
# cpan
cpan>install Text::MeCab
t/04-dclone....................1/? Can't call method "surface" on an undefined value at t/04-dclone.t line 22.

うーん。とりあえずforce。

cpan>force install Text::MeCab

インストール完了。

Twitterのfriends_timelineをGETして、Mecabで分解。

#!/usr/bin/perl

use strict;
use Net::Twitter;
use Jcode;
use Text::MeCab;

my $twit = Net::Twitter->new(username=>"USERNAME", password=>"PASSWORD") ;
my $result = $twit->friends_timeline();

my $i = 0;
my $j = 0;
my @DATA = ();
my @words = ();

foreach my $hash (@$result) {
$DATA[$i] = $hash->{'text'};
$i++;
}

for ($j=0; $j<$i; $j++){
my $mec = Text::MeCab->new;
for (my $nod = $mec->parse($DATA[$j]); $nod; $nod=$nod->next ) {
push @words, $nod->surface if length $nod->surface;
}
}
print join ' ', @words;
exit;

このブログの人気の投稿

転職のお知らせ

40代の減量戦略 〜体重-14kg、体脂肪率-12%を実現した具体的な方法〜

45歳になりました