Skip to content

Commit

Permalink
neta*
Browse files Browse the repository at this point in the history
  • Loading branch information
bayashi committed Jun 2, 2009
1 parent 843a640 commit df24272
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Revision history for Acme-Yomeru

0.0.4 Tue Jun 03 00:19:19 2009
neta*

0.0.3 Sun May 24 13:13:13 2009
tests are likely to fail. but you can force install and run it. ;-P

Expand Down
30 changes: 20 additions & 10 deletions lib/Acme/Yomeru.pm
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
package Acme::Yomeru;
use Moose;
use utf8;

use Carp qw(croak);

our $VERSION = '0.0.3';
our $VERSION = '0.0.4';

use Moose;
has 'text' => (
is => 'rw',
isa => 'Str',
required => 1,
);

has '_convert_text' => (
is => 'rw',
isa => 'Str',
);

has 'parser' => (
is => 'rw',
does => 'Acme::Yomeru::Parser',
Expand All @@ -20,6 +25,14 @@ has 'parser' => (
handles => [ 'parse' ]
);

before 'cambridgize' => sub {
my $self = shift;
my $text = $self->text;
$text =~ tr/[0-9]/[0-9]/;
$self->_convert_text($text);
return $self;
};

__PACKAGE__->meta->make_immutable;

no Moose;
Expand All @@ -29,19 +42,16 @@ sub cambridgize {

croak 'text is blank!' if $self->text eq '';

$self->_randomize( $self->parse($self->_smoothing) );
}
$self->parse($self)->_randomize;

sub _smoothing {
my $self = shift;
my $text = $self->text;
$text =~ tr/[0-9]/[0-9]/;
return $text;
}



sub _randomize {
my $self = shift;
my $parsed_text = shift;

my $parsed_text = $self->_convert_text;

srand(length $parsed_text);

Expand Down
12 changes: 8 additions & 4 deletions lib/Acme/Yomeru/Parser/TextMeCab.pm
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package Acme::Yomeru::Parser::TextMeCab;
use Moose;
use utf8;

use Text::MeCab;
use Encode qw(decode_utf8);

use Moose;

with 'Acme::Yomeru::Parser';

__PACKAGE__->meta->make_immutable;
Expand All @@ -13,10 +14,10 @@ no Moose;

sub parse {
my $self = shift;
my $text = shift;
my $obj = shift;

my $parsed_text;

my $text = $obj->text;
my $mecab = Text::MeCab->new;

for (my $node = $mecab->parse($text); $node; $node = $node->next) {
Expand All @@ -30,7 +31,10 @@ sub parse {

$parsed_text =~ tr/ァ-ン/ぁ-ん/;

return $parsed_text;
$obj->_convert_text($parsed_text);

return $obj;

}

1;
Expand Down
11 changes: 7 additions & 4 deletions lib/Acme/Yomeru/Parser/YahooAPI.pm
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package Acme::Yomeru::Parser::YahooAPI;
use Moose;
use utf8;

use Carp qw(croak);
Expand All @@ -9,6 +8,8 @@ use LWP::Simple;
use XML::Simple;
use Encode qw(encode_utf8 decode_utf8);

use Moose;

with 'Acme::Yomeru::Parser';

has 'api_key' => (
Expand All @@ -23,15 +24,15 @@ no Moose;

sub parse {
my $self = shift;
my $text = shift;
my $obj = shift;

croak 'api_key is blank!' if $self->api_key eq '';

my $uri = URI->new('http://jlp.yahooapis.jp/MAService/V1/parse');

$uri->query_form(
appid => $self->api_key,
sentence => encode_utf8($text),
sentence => encode_utf8($obj->text),
);

my $node_list = XMLin( get($uri) )->{ma_result}{word_list}{word};
Expand All @@ -49,7 +50,9 @@ sub parse {

$parsed_text =~ tr/ァ-ン/ぁ-ん/;

return $parsed_text;
$obj->_convert_text($parsed_text);

return $obj;
}

1;
Expand Down

0 comments on commit df24272

Please sign in to comment.