Show
Ignore:
Timestamp:
03/13/08 10:42:55 (9 months ago)
Author:
daisuke
Message:

lang/perl/Acme-Shukugawa-Atom; more tests, more atom

Location:
lang/perl/Acme-Shukugawa-Atom/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Acme-Shukugawa-Atom/trunk/lib/Acme/Shukugawa/Atom.pm

    r7878 r7880  
    2222} 
    2323 
    24 sub preprocess 
     24# Special case handling -- this could be optimized further 
     25# put it in a sharefile later 
     26my (@SPECIAL, $EXCEPTION); 
     27BEGIN 
    2528{ 
    26     my ($self, $strref) = @_; 
    27  
    28     # Special case handling -- this could be optimized further 
    29     # put it in a sharefile later 
    30     my @special = ( 
     29    @SPECIAL = ( 
     30        '銀座' => 'ザギン', 
    3131        '別に' => 'ジリサワゴネタ', 
    3232        '予約した' => 'バミった', 
     
    3737        '(?:おおきい|大きい)(?:のか?|か)?' => 'カイデー', 
    3838    ); 
     39    $EXCEPTION = decode_utf8(join("|", 
     40        map { $SPECIAL[$_ * 2 + 1] } (0..$#SPECIAL/2) )); 
     41} 
    3942 
    40     for(0..$#special/2) { 
    41         my $pattern = $special[$_ * 2]; 
    42         my $replace = $special[$_ * 2 + 1]; 
     43sub preprocess 
     44{ 
     45    my ($self, $strref) = @_; 
     46 
     47    for(0..$#SPECIAL/2) { 
     48        my $pattern = $SPECIAL[$_ * 2]; 
     49        my $replace = $SPECIAL[$_ * 2 + 1]; 
    4350        $$strref =~ s/$pattern/$replace/g; 
    4451    } 
     
    5461    # in hiragana 
    5562    my $ret = ''; 
    56     foreach (my $node = $mecab->parse($$strref); 
    57         $node; $node = $node->next) 
    58     { 
    59         my $surface = decode_utf8($node->surface); 
    60         next unless $surface; 
    61         if ($surface =~ /^\p{InHiragana}+$/ || $surface =~ /^\p{InKatakana}+$/) { 
    62             $ret .= $surface; 
    63         } else { 
    64             my $feature = decode_utf8($node->feature); 
    6563 
    66             if (my $yomi = (split(/,/, $feature))[8]) { 
    67                 $ret .= $self->atomize($yomi) || $surface; 
     64    foreach my $text (split(/($EXCEPTION)/, $$strref)) { 
     65        if ($text =~ /$EXCEPTION/) { 
     66            $ret .= $text; 
     67            next; 
     68        } 
     69 
     70        foreach (my $node = $mecab->parse($text); $node; $node = $node->next) { 
     71            my $surface = decode_utf8($node->surface); 
     72            next unless $surface; 
     73            if ($surface =~ /^\p{InHiragana}+$/) { 
     74                $ret .= $surface; 
    6875            } else { 
    69                 $ret .= $surface; 
     76                my $feature = decode_utf8($node->feature); 
     77 
     78                if (my $yomi = (split(/,/, $feature))[8]) { 
     79                    $ret .= $self->atomize($yomi) || $surface; 
     80                } else { 
     81                    $ret .= $surface; 
     82                } 
    7083            } 
    7184        } 
     
    8194my $small    = decode_utf8("[ャュョッー]"); 
    8295my $syllable = decode_utf8("(?:.$small?)"); 
    83 my $nbar     = decode_utf8("[^ンー]"); 
     96my $nbar     = decode_utf8("^ンー"); 
    8497sub apply_shisu_rule 
    8598{ 
     
    95108    my ($self, $yomi) = @_; 
    96109 
    97     if ($yomi =~ s/^($syllable[ー]?)(..)$/$2$1/) { 
     110    if ($yomi =~ s/^(${syllable}[$nbar]?)([^$nbar].)$/$2$1/) { 
    98111        $yomi =~ s/([^ー])$/$1ー/; 
    99112        return $yomi; 
  • lang/perl/Acme-Shukugawa-Atom/trunk/t/01_basic.t

    r7852 r7880  
    11use strict; 
    22use utf8; 
    3 use Test::More (tests => 4); 
     3use Test::More (tests => 7); 
    44 
    55BEGIN 
     
    1111    "六本木の胸の大きいお姉さんがいる店を予約した" 
    1212        => "ギロッポンのパイオツカイデーチャンネーがいるセーミーをバミった" , 
     13    "ハワイ" => "ワイハー", 
     14    "寿司"   => "シースー", 
     15    "銀座" => "ザギン", 
    1316    "狼" => "カミオー", 
     17#     "鋏" => "サミハー", <- mecabの辞書にない? 
    1418    "おばあさんの口はどうして大きいの?" => 
    1519        "チャンバーのチークーはどうしてカイデー?"