| 1 | package Lingua::JA::Romaji::Valid; | ||||||||||||
| 2 | |||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 4 | our $VERSION = '0.03'; | |||||||||||
| 7 | |||||||||||||
| 8 | 4 | my %aliases = ( | |||||||||||
| 9 | loose => 'ISO3602Loose', | ||||||||||||
| 10 | liberal => 'Liberal', | ||||||||||||
| 11 | kunrei => 'ISO3602', | ||||||||||||
| 12 | japanese => 'ISO3602Strict', | ||||||||||||
| 13 | passport => 'HepburnPassport', | ||||||||||||
| 14 | railway => 'HepburnRailway', | ||||||||||||
| 15 | traditional => 'Hepburn', | ||||||||||||
| 16 | hepburn => 'HepburnRevised', | ||||||||||||
| 17 | international => 'HepburnRevisedInternational', | ||||||||||||
| 18 | ); | ||||||||||||
| 19 | |||||||||||||
| 20 | 308 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 21 | 308 | my ($class, $rule) = @_; | |||||||||||
| 22 | 308 | my $self = bless {}, $class; | |||||||||||
| 23 | |||||||||||||
| 24 | 308 | ▶ | $rule ||= 'ISO3602Loose'; | ||||||||||
|
Condition100%2/2
$rule ||= "ISO3602Loose"
MC/DC100%1/1
$rule ||= "ISO3602Loose"
$rule
Truth table100%2/2
A
A= $rule
| |||||||||||||
| 25 | 308 | ▶ | $rule = $aliases{$rule} if exists $aliases{$rule}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | |||||||||||||
| 27 | 308 | my $package = 'Lingua::JA::Romaji::Valid::Rule::'.$rule; | |||||||||||
| 28 | 308 | ▶ | eval "require $package"; die $@ if $@; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | 308 | $self->{rule} = $package->new; | |||||||||||
| 30 | |||||||||||||
| 31 | 308 | $self; | |||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | 1 | ▶ | sub aliases { sort keys %aliases } | ||||||||||
|
Subroutine
aliases: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 35 | 322 | ▶ | sub verbose { shift->{rule}->verbose(@_) } | ||||||||||
|
Subroutine
verbose: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 36 | |||||||||||||
| 37 | 313 | ▶ | sub as_romaji { | ||||||||||
|
Subroutine
as_romaji: called CC=7 SCAR=19.6
Pod
documented
| |||||||||||||
| 38 | 313 | my ($self, $word, @extra_filters) = @_; | |||||||||||
| 39 | |||||||||||||
| 40 | 313 | ▶ | return unless defined $word; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | |||||||||||||
| 42 | 313 | $word = quotemeta lc $word; | |||||||||||
| 43 | |||||||||||||
| 44 | 313 | ▶ | return unless $self->{rule}->_prepare( \$word, @extra_filters ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 45 | |||||||||||||
| 46 | 313 | my @kanas = $word =~ /((?:[^aeiou]*)(?:[aeioun]))/g; | |||||||||||
| 47 | 313 | my $got = join '', @kanas; | |||||||||||
| 48 | 313 | my ($rest) = $word =~ /^$got(.+)/; | |||||||||||
| 49 | |||||||||||||
| 50 | 313 | ▶ | if ( $rest ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 51 | # always prohibit consonant ending but 'n' | ||||||||||||
| 52 | 16 | ▶ | warn "consonant ending: $rest" if $self->verbose; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 53 | 16 | return; | |||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | 297 | foreach my $kana ( @kanas ) { | |||||||||||
| 57 | 764 | ▶ | return unless $self->{rule}->is_valid( $kana, @extra_filters ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | } | ||||||||||||
| 59 | 179 | return 1; | |||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | 29 | ▶ | sub as_name { | ||||||||||
|
Subroutine
as_name: called CC=7 SCAR=20.1
Pod
documented
| |||||||||||||
| 63 | 29 | my ($self, $word, @extra_filters) = @_; | |||||||||||
| 64 | |||||||||||||
| 65 | 29 | ▶ | return unless defined $word; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | |||||||||||||
| 67 | 26 | $word = quotemeta lc $word; | |||||||||||
| 68 | |||||||||||||
| 69 | 26 | push @extra_filters, qw( | |||||||||||
| 70 | prohibit_initial_n | ||||||||||||
| 71 | prohibit_initial_wo | ||||||||||||
| 72 | prohibit_foreign_kanas | ||||||||||||
| 73 | ); | ||||||||||||
| 74 | 26 | ▶ | return unless $self->{rule}->_prepare( \$word, @extra_filters ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 75 | |||||||||||||
| 76 | 24 | my @kanas = $word =~ /((?:[^aeiou]*)(?:[aeioun]))/g; | |||||||||||
| 77 | 24 | my $got = join '', @kanas; | |||||||||||
| 78 | 24 | my ($rest) = $word =~ /^$got(.+)/; | |||||||||||
| 79 | |||||||||||||
| 80 | 24 | ▶ | if ( $rest ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 81 | # always prohibit consonant ending but 'n' | ||||||||||||
| 82 | 0 | ▶ | warn "consonant ending: $rest" if $self->verbose; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | 0 | return; | |||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | 24 | foreach my $kana ( @kanas ) { | |||||||||||
| 87 | 38 | ▶ | return unless $self->{rule}->is_valid( $kana, @extra_filters ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 88 | } | ||||||||||||
| 89 | 8 | return 1; | |||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | 3 | ▶ | sub as_fullname { | ||||||||||
|
Subroutine
as_fullname: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||
| 93 | 3 | my ($self, $word, @extra_filters) = @_; | |||||||||||
| 94 | |||||||||||||
| 95 | 3 | ▶ | return unless defined $word; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 96 | |||||||||||||
| 97 | 3 | $word = quotemeta lc $word; | |||||||||||
| 98 | |||||||||||||
| 99 | # XXX: allow comma separated name: should this be optional? | ||||||||||||
| 100 | 3 | my $rule = qr/(?:\\?\s)+|(?:\\?\s)*(?:\\?,)(?:\\?\s)*/; | |||||||||||
| 101 | 3 | my @parts = split $rule, $word; | |||||||||||
| 102 | |||||||||||||
| 103 | # Japanese full name should have both first and last names | ||||||||||||
| 104 | # but not a middle name | ||||||||||||
| 105 | 3 | ▶ | return unless @parts == 2; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 106 | |||||||||||||
| 107 | 1 | foreach my $part ( @parts ) { | |||||||||||
| 108 | 2 | ▶ | return unless $self->as_name( $part, @extra_filters ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 109 | } | ||||||||||||
| 110 | 1 | return 1; | |||||||||||
| 111 | } | ||||||||||||
| 112 | |||||||||||||
| 113 | 4 | 1; | |||||||||||
| 114 | |||||||||||||
| 115 | __END__ | ||||||||||||