| 1 | package Wiktionary::Parser::Section::Pronunciation; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | 3 | ▶ | use Wiktionary::Parser::Section; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 3 | ▶ | use Wiktionary::Parser::Section::Pronunciation::Audio; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 3 | ▶ | use Wiktionary::Parser::Section::Pronunciation::Representation; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | |||||||||||||||||||||||
| 7 | 3 | ▶ | use base qw(Wiktionary::Parser::Section); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | 4 | ▶ | sub new { | ||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 10 | 4 | my $class = shift; | |||||||||||||||||||||
| 11 | 4 | my %args = @_; | |||||||||||||||||||||
| 12 | 4 | my $self = bless Wiktionary::Parser::Section->new(%args), $class; | |||||||||||||||||||||
| 13 | 4 | return $self; | |||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | # add a line of content to this section and parse it into its component parts | ||||||||||||||||||||||
| 18 | 14 | ▶ | sub add_content { | ||||||||||||||||||||
|
Subroutine
add_content: called CC=14 SCAR=29.0
Pod
undocumented
| |||||||||||||||||||||||
| 19 | 14 | my $self = shift; | |||||||||||||||||||||
| 20 | 14 | my $line = shift; | |||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | 14 | push @{$self->{content}}, $line; | |||||||||||||||||||||
| 23 | |||||||||||||||||||||||
| 24 | 14 | ▶ | return unless $line; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 25 | 14 | $line =~ s/^[\*\s]+//i; | |||||||||||||||||||||
| 26 | 14 | my @meta = $line =~ m/\{\{([^\}]+)\}\}/g; | |||||||||||||||||||||
| 27 | 14 | ▶ | if (@meta) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 28 | 14 | my @context; | |||||||||||||||||||||
| 29 | my @senses; | ||||||||||||||||||||||
| 30 | 14 | for my $meta (@meta) { | |||||||||||||||||||||
| 31 | 22 | my @parts = split(/\|/,$meta); | |||||||||||||||||||||
| 32 | |||||||||||||||||||||||
| 33 | 22 | ▶ | if ($parts[0] eq 'sense') { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 34 | 0 | ▶ | if (@parts > 1) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 35 | 0 | ▶ | push @senses, grep {$_ && $_ ne 'sense'} @parts | ||||||||||||||||||||
|
Condition0%0/3
$_ && $_ ne 'sense'
MC/DC0%0/2
$_ && $_ ne 'sense'
$_
$_ ne 'sense'
Truth table0%0/3
A && B
A= $_B= $_ ne 'sense'
| |||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||
| 37 | } elsif ($parts[0] eq 'a') { | ||||||||||||||||||||||
| 38 | 3 | ▶ | if (@parts > 1) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 39 | 3 | ▶ | push @context, grep {$_ && $_ ne 'a'} @parts | ||||||||||||||||||||
|
Condition66%2/3
$_ && $_ ne 'a'
MC/DC50%1/2
$_ && $_ ne 'a'
$_
$_ ne 'a'
Truth table66%2/3
A && B
A= $_B= $_ ne 'a'
| |||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||
| 41 | } elsif ($parts[0] eq 'audio') { | ||||||||||||||||||||||
| 42 | 5 | my $lang = $self->get_language(); | |||||||||||||||||||||
| 43 | |||||||||||||||||||||||
| 44 | 5 | $self->add_audio( | |||||||||||||||||||||
| 45 | language => $lang, | ||||||||||||||||||||||
| 46 | file => $parts[1], | ||||||||||||||||||||||
| 47 | text => $parts[2], | ||||||||||||||||||||||
| 48 | context => \@context, | ||||||||||||||||||||||
| 49 | senses => \@senses, | ||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||
| 51 | } elsif ($parts[0] =~ m/(rhyme|homophone|hyphenation)/) { | ||||||||||||||||||||||
| 52 | |||||||||||||||||||||||
| 53 | 4 | my $meta = $self->parse_template(@parts); | |||||||||||||||||||||
| 54 | 4 | ▶ | $meta->{lang} ||= $self->get_language(); | ||||||||||||||||||||
|
Condition66%2/3
$meta->{"lang"} ||= $self->get_language
MC/DC0%0/2
$meta->{"lang"} ||= $self->get_language
$meta->{"lang"}
$self->get_language
Truth table66%2/3
A ||= B
A= $meta->{"lang"}B= $self->get_language
| |||||||||||||||||||||||
| 55 | |||||||||||||||||||||||
| 56 | $self->add_category( | ||||||||||||||||||||||
| 57 | category => $1, | ||||||||||||||||||||||
| 58 | language => $meta->{lang}, | ||||||||||||||||||||||
| 59 | representation => $meta->{representation}, | ||||||||||||||||||||||
| 60 | pronunciation => $meta->{pronunciation}, | ||||||||||||||||||||||
| 61 | 4 | context => \@context, | |||||||||||||||||||||
| 62 | senses => \@senses, | ||||||||||||||||||||||
| 63 | ); | ||||||||||||||||||||||
| 64 | |||||||||||||||||||||||
| 65 | } else { | ||||||||||||||||||||||
| 66 | 10 | my $meta = $self->parse_template(@parts); | |||||||||||||||||||||
| 67 | 10 | ▶ | $meta->{lang} ||= $self->get_language(); | ||||||||||||||||||||
|
Condition66%2/3
$meta->{"lang"} ||= $self->get_language
MC/DC0%0/2
$meta->{"lang"} ||= $self->get_language
$meta->{"lang"}
$self->get_language
Truth table66%2/3
A ||= B
A= $meta->{"lang"}B= $self->get_language
| |||||||||||||||||||||||
| 68 | |||||||||||||||||||||||
| 69 | $self->add_pronunciation( | ||||||||||||||||||||||
| 70 | language => $meta->{lang}, | ||||||||||||||||||||||
| 71 | representation => $meta->{representation}, | ||||||||||||||||||||||
| 72 | pronunciation => $meta->{pronunciation}, | ||||||||||||||||||||||
| 73 | 10 | context => \@context, | |||||||||||||||||||||
| 74 | senses => \@senses, | ||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||
| 80 | |||||||||||||||||||||||
| 81 | 14 | ▶ | sub parse_template { | ||||||||||||||||||||
|
Subroutine
parse_template: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||
| 82 | 14 | my $self = shift; | |||||||||||||||||||||
| 83 | 14 | my @parts = @_; | |||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 85 | 14 | my %meta; | |||||||||||||||||||||
| 86 | my $representation; | ||||||||||||||||||||||
| 87 | 14 | my $lang; | |||||||||||||||||||||
| 88 | 14 | my @pronunciation = []; | |||||||||||||||||||||
| 89 | 14 | for my $i (0..$#parts) { | |||||||||||||||||||||
| 90 | 37 | ▶ | if ($parts[$i] =~ m/rhyme|homophone|hyphenation/) { | ||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | } elsif ($parts[$i] =~ m/(IPA|enPR|AHD|SAMPA)/) { | ||||||||||||||||||||||
| 93 | 10 | $meta{representation} = $parts[$i]; | |||||||||||||||||||||
| 94 | } elsif ($parts[$i] =~ m/lang=(.+)/) { | ||||||||||||||||||||||
| 95 | 4 | $meta{lang} = $1; | |||||||||||||||||||||
| 96 | } else { | ||||||||||||||||||||||
| 97 | 19 | push @{$meta{pronunciation}}, $parts[$i]; | |||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||
| 100 | 14 | return \%meta; | |||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||
| 102 | |||||||||||||||||||||||
| 103 | 10 | ▶ | sub add_pronunciation { | ||||||||||||||||||||
|
Subroutine
add_pronunciation: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||
| 104 | 10 | my $self = shift; | |||||||||||||||||||||
| 105 | 10 | my %args = @_; | |||||||||||||||||||||
| 106 | |||||||||||||||||||||||
| 107 | 10 | my $meta = {}; | |||||||||||||||||||||
| 108 | 10 | ▶ | my $lang = $args{language} || '__language_undefined__'; | ||||||||||||||||||||
|
Condition50%1/2
$args{'language'} || '__language_undefined__'
MC/DC0%0/1
$args{'language'} || '__language_undefined__'
$args{'language'}
Truth table50%1/2
A
A= $args{'language'}
| |||||||||||||||||||||||
| 109 | |||||||||||||||||||||||
| 110 | my $pronunciation = Wiktionary::Parser::Section::Pronunciation::Representation->new( | ||||||||||||||||||||||
| 111 | representation => $args{representation}, | ||||||||||||||||||||||
| 112 | pronunciation => $args{pronunciation}, | ||||||||||||||||||||||
| 113 | context => $args{context}, | ||||||||||||||||||||||
| 114 | 10 | ); | |||||||||||||||||||||
| 115 | 10 | push @{$self->{pronunciation}{$lang}},$pronunciation; | |||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||
| 117 | |||||||||||||||||||||||
| 118 | |||||||||||||||||||||||
| 119 | # rhyme, homophone, hyphenation entries | ||||||||||||||||||||||
| 120 | 4 | ▶ | sub add_category { | ||||||||||||||||||||
|
Subroutine
add_category: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||
| 121 | 4 | my $self = shift; | |||||||||||||||||||||
| 122 | 4 | my %args = @_; | |||||||||||||||||||||
| 123 | 4 | ▶ | my $category = $args{category} or die 'category not defined'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 124 | |||||||||||||||||||||||
| 125 | 4 | ▶ | my $lang = $args{language} || '__language_undefined__'; | ||||||||||||||||||||
|
Condition50%1/2
$args{'language'} || '__language_undefined__'
MC/DC0%0/1
$args{'language'} || '__language_undefined__'
$args{'language'}
Truth table50%1/2
A
A= $args{'language'}
| |||||||||||||||||||||||
| 126 | 4 | my $meta = {}; | |||||||||||||||||||||
| 127 | my $item = Wiktionary::Parser::Section::Pronunciation::Representation->new( | ||||||||||||||||||||||
| 128 | representation => $args{representation}, | ||||||||||||||||||||||
| 129 | pronunciation => $args{pronunciation}, | ||||||||||||||||||||||
| 130 | context => $args{context}, | ||||||||||||||||||||||
| 131 | senses => $args{senses}, | ||||||||||||||||||||||
| 132 | 4 | ); | |||||||||||||||||||||
| 133 | 4 | push @{$self->{$category}{$lang}},$item; | |||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||
| 135 | |||||||||||||||||||||||
| 136 | |||||||||||||||||||||||
| 137 | 5 | ▶ | sub add_audio { | ||||||||||||||||||||
|
Subroutine
add_audio: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||
| 138 | 5 | my $self = shift; | |||||||||||||||||||||
| 139 | 5 | my %args = @_; | |||||||||||||||||||||
| 140 | 5 | ▶ | my $lang = $args{language} || '__language_undefined__'; | ||||||||||||||||||||
|
Condition50%1/2
$args{'language'} || '__language_undefined__'
MC/DC0%0/1
$args{'language'} || '__language_undefined__'
$args{'language'}
Truth table50%1/2
A
A= $args{'language'}
| |||||||||||||||||||||||
| 141 | |||||||||||||||||||||||
| 142 | my $audio = Wiktionary::Parser::Section::Pronunciation::Audio->new( | ||||||||||||||||||||||
| 143 | file => $args{file}, | ||||||||||||||||||||||
| 144 | text => $args{text}, | ||||||||||||||||||||||
| 145 | context => $args{context}, | ||||||||||||||||||||||
| 146 | 5 | ); | |||||||||||||||||||||
| 147 | |||||||||||||||||||||||
| 148 | 5 | push @{$self->{audio}{$lang}}, $audio; | |||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||
| 150 | |||||||||||||||||||||||
| 151 | 0 | ▶ | sub get_pronunciations { | ||||||||||||||||||||
|
Subroutine
get_pronunciations: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 152 | 0 | my $self = shift; | |||||||||||||||||||||
| 153 | 0 | return $self->{pronunciation}; | |||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||
| 155 | |||||||||||||||||||||||
| 156 | 0 | ▶ | sub get_audio { | ||||||||||||||||||||
|
Subroutine
get_audio: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 157 | 0 | my $self = shift; | |||||||||||||||||||||
| 158 | 0 | return $self->{audio}; | |||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||
| 160 | |||||||||||||||||||||||
| 161 | 0 | ▶ | sub get_rhymes { | ||||||||||||||||||||
|
Subroutine
get_rhymes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 162 | 0 | my $self = shift; | |||||||||||||||||||||
| 163 | return $self->{rhyme} | ||||||||||||||||||||||
| 164 | 0 | } | |||||||||||||||||||||
| 165 | |||||||||||||||||||||||
| 166 | 0 | ▶ | sub get_homophones{ | ||||||||||||||||||||
|
Subroutine
get_homophones: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 167 | 0 | my $self = shift; | |||||||||||||||||||||
| 168 | return $self->{homophone} | ||||||||||||||||||||||
| 169 | 0 | } | |||||||||||||||||||||
| 170 | |||||||||||||||||||||||
| 171 | 0 | ▶ | sub get_hyphenations{ | ||||||||||||||||||||
|
Subroutine
get_hyphenations: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 172 | 0 | my $self = shift; | |||||||||||||||||||||
| 173 | return $self->{hyphenation} | ||||||||||||||||||||||
| 174 | 0 | } | |||||||||||||||||||||
| 175 | |||||||||||||||||||||||
| 176 | 3 | 1; | |||||||||||||||||||||