| 1 | package Wiktionary::Parser::Section::Translations; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Wiktionary::Parser::Section; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use Wiktionary::Parser::Section::Translations::WordSense; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Wiktionary::Parser::Section::Translations::WordSense::Lexeme; | ||||||||||||||||||||||||||||
|
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 | 42 | ▶ | sub new { | ||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 10 | 42 | my $class = shift; | |||||||||||||||||||||||||||||
| 11 | 42 | my %args = @_; | |||||||||||||||||||||||||||||
| 12 | 42 | my $self = bless Wiktionary::Parser::Section->new(%args), $class; | |||||||||||||||||||||||||||||
| 13 | 42 | return $self; | |||||||||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | 1551 | ▶ | sub get_templates { | ||||||||||||||||||||||||||||
|
Subroutine
get_templates: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 18 | return [ | ||||||||||||||||||||||||||||||
| 19 | { | ||||||||||||||||||||||||||||||
| 20 | # e.g. {{trans-bottom}} | ||||||||||||||||||||||||||||||
| 21 | pattern => qr/{{trans-bottom}}/, | ||||||||||||||||||||||||||||||
| 22 | 5 | ▶ | parser => sub { return { meta => 'end_word_sense' } } | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 23 | }, | ||||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||||
| 25 | # comma - separates different blocks of words+metadata | ||||||||||||||||||||||||||||||
| 26 | pattern => qr/[,;\.]/, | ||||||||||||||||||||||||||||||
| 27 | 97 | ▶ | parser => sub { return {meta => 'end_segment' } }, | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 28 | }, | ||||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||||
| 30 | # e.g. * Swedish: ... | ||||||||||||||||||||||||||||||
| 31 | pattern => qr/\*\:?\s([^\:]+)\:\s*/, | ||||||||||||||||||||||||||||||
| 32 | parser => \&template_language, | ||||||||||||||||||||||||||||||
| 33 | }, | ||||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||||
| 35 | # e.g. {{trans-top|colour}} | ||||||||||||||||||||||||||||||
| 36 | pattern => qr/{{trans-top\|([^}]+)/, | ||||||||||||||||||||||||||||||
| 37 | 24 | ▶ | parser => sub { return { word_sense => $_[-1] } } | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 38 | }, | ||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||||
| 41 | # e.g. {{trans-see|apples and pears (''Cockney rhyming slang'')|apples and pears}} | ||||||||||||||||||||||||||||||
| 42 | pattern => qr/{{trans-see\|([^}]+)}}/, | ||||||||||||||||||||||||||||||
| 43 | parser =>\&template_trans_see, | ||||||||||||||||||||||||||||||
| 44 | }, | ||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||||
| 47 | # e.g. {{tø|arz|برتقان|tr=burtuʕaan|sc=Arab|xs=Egyptian Arabic}} | ||||||||||||||||||||||||||||||
| 48 | pattern => qr/{{t[^\|]*\|([^}]+)}}/, | ||||||||||||||||||||||||||||||
| 49 | parser => \&template_t, | ||||||||||||||||||||||||||||||
| 50 | }, | ||||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||||
| 52 | # e.g. {{ku-Arab|[[پرتهقاڵ]] | ||||||||||||||||||||||||||||||
| 53 | pattern => qr/{{(\w{2}\-Arab\|[^}]+)}/, | ||||||||||||||||||||||||||||||
| 54 | parser => \&template_t, | ||||||||||||||||||||||||||||||
| 55 | }, | ||||||||||||||||||||||||||||||
| 56 | { | ||||||||||||||||||||||||||||||
| 57 | # e.g. {{qualifier|Dominican Republic|Puerto Rico} | ||||||||||||||||||||||||||||||
| 58 | pattern => qr/{{qualifier\|([^\}]+)}}/, | ||||||||||||||||||||||||||||||
| 59 | parser => \&template_qualifier, | ||||||||||||||||||||||||||||||
| 60 | }, | ||||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||||
| 62 | # e.g. [[כלבא]] (kalbā’) {{m}} | ||||||||||||||||||||||||||||||
| 63 | pattern => qr/\[\[([^\]]+)\]\]\s+\(([^\)]+)\)\s+{{(\w)}}/, | ||||||||||||||||||||||||||||||
| 64 | parser => \&template_4, | ||||||||||||||||||||||||||||||
| 65 | }, | ||||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||||
| 67 | # e.g. [[oranževec]] {{m}} | ||||||||||||||||||||||||||||||
| 68 | pattern => qr/\[\[([^\]]+)\]\]\s*{{(\w)}}/, | ||||||||||||||||||||||||||||||
| 69 | parser => \&template_2 | ||||||||||||||||||||||||||||||
| 70 | }, | ||||||||||||||||||||||||||||||
| 71 | { | ||||||||||||||||||||||||||||||
| 72 | # e.g. (narangi) {{f}} | ||||||||||||||||||||||||||||||
| 73 | pattern => qr/\(([^\]]+)\)\s*{{(\w)}}/, | ||||||||||||||||||||||||||||||
| 74 | parser => \&template_2 | ||||||||||||||||||||||||||||||
| 75 | }, | ||||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||||
| 77 | # e.g. [[colore de aranzu]], [[ruggiu]], [[ruiu]], [[arrubiu]] | ||||||||||||||||||||||||||||||
| 78 | pattern => qr/\[\[([^\]]+)\]\]/, | ||||||||||||||||||||||||||||||
| 79 | parser => \&template_3 | ||||||||||||||||||||||||||||||
| 80 | }, | ||||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||||
| 82 | # e.g. ''(collective)'' | ||||||||||||||||||||||||||||||
| 83 | pattern => qr/\'\'([^\']+)\'\'/, | ||||||||||||||||||||||||||||||
| 84 | parser => \&template_q, | ||||||||||||||||||||||||||||||
| 85 | }, | ||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||
| 87 | # run this last - just chop a character off if nothing else matches; | ||||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||||
| 89 | pattern => qr/./, | ||||||||||||||||||||||||||||||
| 90 | 345 | ▶ | parser => sub { return {meta => 'unparsable'} } | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||
| 93 | 1551 | ]; | |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | 3 | ▶ | sub template_q { | ||||||||||||||||||||||||||||
|
Subroutine
template_q: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 97 | 3 | my $self = shift; | |||||||||||||||||||||||||||||
| 98 | 3 | my $template = shift; | |||||||||||||||||||||||||||||
| 99 | 3 | $template =~ s/[\[\]\(\)]//g; | |||||||||||||||||||||||||||||
| 100 | 3 | return { qualifier => [$template] }; | |||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||
| 103 | 10 | ▶ | sub template_qualifier { | ||||||||||||||||||||||||||||
|
Subroutine
template_qualifier: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 104 | 10 | my $self = shift; | |||||||||||||||||||||||||||||
| 105 | 10 | my $template = shift; | |||||||||||||||||||||||||||||
| 106 | 10 | my @parts = split(/\|/,$template); | |||||||||||||||||||||||||||||
| 107 | 10 | $self->clean_tokens(@parts); | |||||||||||||||||||||||||||||
| 108 | 10 | return {qualifier => \@parts} | |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||
| 111 | 310 | ▶ | sub template_language { | ||||||||||||||||||||||||||||
|
Subroutine
template_language: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 112 | 310 | my $self = shift; | |||||||||||||||||||||||||||||
| 113 | 310 | my $language = shift; | |||||||||||||||||||||||||||||
| 114 | 310 | $self->clean_tokens($language); | |||||||||||||||||||||||||||||
| 115 | 310 | return { language => $language } | |||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||
| 118 | # parse the trans-see template into its parts | ||||||||||||||||||||||||||||||
| 119 | # http://en.wiktionary.org/wiki/Template:trans-see | ||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub template_trans_see { | ||||||||||||||||||||||||||||
|
Subroutine
template_trans_see: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 121 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 122 | 0 | my ($title) = shift; | |||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||
| 124 | 0 | my @params = split(/\|/,$title,2); | |||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||
| 126 | # {{trans-see|that}} | ||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if ($params[0] && scalar @params == 1) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$params[0] and scalar @params == 1
MC/DC0%0/2
$params[0] and scalar @params == 1
$params[0]
scalar @params == 1
Truth table0%0/3
A and B
A= $params[0]B= scalar @params == 1
| |||||||||||||||||||||||||||||||
| 128 | 0 | $self->clean_tokens(@params); | |||||||||||||||||||||||||||||
| 129 | return { | ||||||||||||||||||||||||||||||
| 130 | 0 | word_sense => "wiktionary:$params[0]", | |||||||||||||||||||||||||||||
| 131 | meta => 'wiktionary_link', | ||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||
| 135 | # {{trans-see|rally|[[rally#Etymology 2|rally]]}} | ||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if (my $link_meta = $params[1] =~ m/\[\[([^\]]+)\]\]/) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 137 | 0 | my @link_params = split(/\|/, $1); | |||||||||||||||||||||||||||||
| 138 | 0 | my $link; | |||||||||||||||||||||||||||||
| 139 | # grab the last value if there's more than one entry | ||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | if (scalar @link_params > 1) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 141 | 0 | $link = $link_params[-1]; | |||||||||||||||||||||||||||||
| 142 | } else { | ||||||||||||||||||||||||||||||
| 143 | 0 | $link = shift @link_params; | |||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||
| 146 | 0 | $link =~ s/\#.+$//; | |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||
| 148 | return { | ||||||||||||||||||||||||||||||
| 149 | 0 | word_sense => "wiktionary:$link", | |||||||||||||||||||||||||||||
| 150 | meta => 'wiktionary_link', | ||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||
| 154 | # {{trans-see|Nahuatl language|Nahuatl}} | ||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | if ($params[1]) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 156 | 0 | my $link = $params[1]; | |||||||||||||||||||||||||||||
| 157 | 0 | $link =~ s/\#.+$//; | |||||||||||||||||||||||||||||
| 158 | return { | ||||||||||||||||||||||||||||||
| 159 | 0 | word_sense => "wiktionary:$link", | |||||||||||||||||||||||||||||
| 160 | meta => 'wiktionary_link', | ||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||
| 164 | 0 | return; | |||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||
| 167 | 327 | ▶ | sub template_t { | ||||||||||||||||||||||||||||
|
Subroutine
template_t: called CC=9 SCAR=22.1
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 168 | 327 | my $self = shift; | |||||||||||||||||||||||||||||
| 169 | 327 | my $template = shift; | |||||||||||||||||||||||||||||
| 170 | 327 | my @parts = split(/\|/,$template); | |||||||||||||||||||||||||||||
| 171 | 327 | my %meta; | |||||||||||||||||||||||||||||
| 172 | 327 | $meta{language_code} = shift @parts; | |||||||||||||||||||||||||||||
| 173 | 327 | my $translation = shift @parts; | |||||||||||||||||||||||||||||
| 174 | 327 | ▶ | $translation ||= ''; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$translation ||= ""
MC/DC0%0/1
$translation ||= ""
$translation
Truth table50%1/2
A
A= $translation
| |||||||||||||||||||||||||||||||
| 175 | 327 | my @tokens = $translation =~ m/\[\[([^\]]+)\]\]/g; | |||||||||||||||||||||||||||||
| 176 | 327 | $translation =~ s/\[\[([^\]]+)\]\]//g; | |||||||||||||||||||||||||||||
| 177 | 327 | push @tokens, $translation; | |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||
| 179 | 327 | $meta{translations} = [ grep { length($_) }@tokens ]; | |||||||||||||||||||||||||||||
| 180 | 327 | for my $token (@parts) { | |||||||||||||||||||||||||||||
| 181 | 376 | ▶ | if ($token =~ m/^[fmcn]$/) { | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 182 | # f: fem. | ||||||||||||||||||||||||||||||
| 183 | # m: masc. | ||||||||||||||||||||||||||||||
| 184 | # c: common | ||||||||||||||||||||||||||||||
| 185 | # n: neut. | ||||||||||||||||||||||||||||||
| 186 | 106 | $meta{gender} = $token; | |||||||||||||||||||||||||||||
| 187 | } elsif ($token =~ m/^[sp]$/) { | ||||||||||||||||||||||||||||||
| 188 | # s: singular | ||||||||||||||||||||||||||||||
| 189 | # p: plural | ||||||||||||||||||||||||||||||
| 190 | 0 | $meta{number} = $token; | |||||||||||||||||||||||||||||
| 191 | } elsif ($token =~ m/^tr=(.+)/) { | ||||||||||||||||||||||||||||||
| 192 | 104 | $meta{transliteration} = $1; | |||||||||||||||||||||||||||||
| 193 | } elsif ($token =~ m/^sc=(.+)/) { | ||||||||||||||||||||||||||||||
| 194 | 75 | $meta{script_code_template} = $1; | |||||||||||||||||||||||||||||
| 195 | } elsif ($token =~ m/^alt=(.+)/) { | ||||||||||||||||||||||||||||||
| 196 | 15 | $meta{alternate} = $1; | |||||||||||||||||||||||||||||
| 197 | } elsif ($token =~ m/^xs=(.+)/) { | ||||||||||||||||||||||||||||||
| 198 | 76 | $meta{xs} = $1; | |||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||
| 204 | 327 | return \%meta; | |||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||
| 207 | 25 | ▶ | sub template_2 { | ||||||||||||||||||||||||||||
|
Subroutine
template_2: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 208 | 25 | my $self = shift; | |||||||||||||||||||||||||||||
| 209 | 25 | my @parts = @_; | |||||||||||||||||||||||||||||
| 210 | 25 | my %meta; | |||||||||||||||||||||||||||||
| 211 | 25 | my $translation = shift @parts; | |||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||
| 213 | 25 | my @tokens = $translation =~ m/\[\[([^\]]+)\]\]/g; | |||||||||||||||||||||||||||||
| 214 | 25 | $translation =~ s/\[\[([^\]]+)\]\]//g; | |||||||||||||||||||||||||||||
| 215 | 25 | push @tokens, $translation; | |||||||||||||||||||||||||||||
| 216 | 25 | $meta{translations} = \@tokens; | |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||
| 218 | 25 | $meta{gender} = shift @parts; | |||||||||||||||||||||||||||||
| 219 | 25 | return \%meta; | |||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||
| 222 | 56 | ▶ | sub template_3 { | ||||||||||||||||||||||||||||
|
Subroutine
template_3: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 223 | 56 | my $self = shift; | |||||||||||||||||||||||||||||
| 224 | 56 | my @parts = @_; | |||||||||||||||||||||||||||||
| 225 | 56 | $self->clean_tokens(@parts); | |||||||||||||||||||||||||||||
| 226 | 56 | my %meta; | |||||||||||||||||||||||||||||
| 227 | 56 | $meta{translations} = \@parts; | |||||||||||||||||||||||||||||
| 228 | 56 | return \%meta; | |||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||
| 232 | 4 | ▶ | sub template_4 { | ||||||||||||||||||||||||||||
|
Subroutine
template_4: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 233 | 4 | my $self = shift; | |||||||||||||||||||||||||||||
| 234 | 4 | my @parts = @_; | |||||||||||||||||||||||||||||
| 235 | 4 | $self->clean_tokens(@parts); | |||||||||||||||||||||||||||||
| 236 | 4 | my %meta; | |||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||
| 238 | 4 | $meta{translations} = [shift @parts]; | |||||||||||||||||||||||||||||
| 239 | 4 | $meta{transliteration} = shift @parts; | |||||||||||||||||||||||||||||
| 240 | 4 | my $gp = shift @parts; | |||||||||||||||||||||||||||||
| 241 | 4 | ▶ | if ($gp =~ m/[mfcn]/) { | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 242 | 2 | $meta{gender} = $gp; | |||||||||||||||||||||||||||||
| 243 | } elsif ($gp =~ m/[ps]/) { | ||||||||||||||||||||||||||||||
| 244 | 2 | $meta{number} = $gp; | |||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||
| 247 | 4 | return \%meta; | |||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||
| 250 | 380 | ▶ | sub clean_tokens { | ||||||||||||||||||||||||||||
|
Subroutine
clean_tokens: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 251 | 380 | my $self = shift; | |||||||||||||||||||||||||||||
| 252 | 380 | for (@_) { | |||||||||||||||||||||||||||||
| 253 | 390 | $_ =~ s/[\[\]\(\)]//g; | |||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||
| 258 | # add a line of content to this section and parse it into its meaningful parts | ||||||||||||||||||||||||||||||
| 259 | 345 | ▶ | sub add_content { | ||||||||||||||||||||||||||||
|
Subroutine
add_content: called CC=22 SCAR=31.1
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 260 | 345 | my $self = shift; | |||||||||||||||||||||||||||||
| 261 | 345 | my $line = shift; | |||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||
| 263 | # TODO: template parsing issues | ||||||||||||||||||||||||||||||
| 264 | # {{qualifier|...}} | ||||||||||||||||||||||||||||||
| 265 | # | ||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||
| 267 | 345 | my $line_copy = $line; # #$line is getting disembowled below | |||||||||||||||||||||||||||||
| 268 | 345 | push @{$self->{content}}, $line_copy; | |||||||||||||||||||||||||||||
| 269 | 345 | my $lexeme = Wiktionary::Parser::Section::Translations::WordSense::Lexeme->new(); | |||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||
| 271 | 345 | ▶ | while (my $meta = $self->get_template_match($line)) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 272 | 1206 | ▶ | next unless defined $meta; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||
| 274 | 1206 | ▶ | if ($meta->{word_sense}) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 275 | # start new lexeme | ||||||||||||||||||||||||||||||
| 276 | 24 | ▶ | if ($self->get_current_word_sense()) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 277 | 0 | $self->get_current_word_sense()->add_lexeme($lexeme); | |||||||||||||||||||||||||||||
| 278 | 0 | $lexeme = Wiktionary::Parser::Section::Translations::WordSense::Lexeme->new(); | |||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||
| 280 | my $word_sense = Wiktionary::Parser::Section::Translations::WordSense->new( | ||||||||||||||||||||||||||||||
| 281 | word_sense => $meta->{word_sense}, | ||||||||||||||||||||||||||||||
| 282 | 24 | ); | |||||||||||||||||||||||||||||
| 283 | 24 | $self->add_word_sense($word_sense); | |||||||||||||||||||||||||||||
| 284 | 24 | $self->set_current_word_sense($word_sense); | |||||||||||||||||||||||||||||
| 285 | 24 | next; | |||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||
| 288 | 1182 | ▶ | if ($meta->{meta} && $meta->{meta} eq 'end_word_sense') { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$meta->{"meta"} and $meta->{"meta"} eq "end_word_sense"
MC/DC100%2/2
$meta->{"meta"} and $meta->{"meta"} eq "end_word_sense"
$meta->{"meta"}
$meta->{"meta"} eq "end_word_sense"
Truth table100%3/3
A and B
A= $meta->{"meta"}B= $meta->{"meta"} eq "end_word_sense"
| |||||||||||||||||||||||||||||||
| 289 | 5 | $self->set_current_word_sense(undef); | |||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||
| 292 | 1182 | ▶ | if ($meta->{meta} && $meta->{meta} eq 'end_segment') { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$meta->{"meta"} and $meta->{"meta"} eq "end_segment"
MC/DC100%2/2
$meta->{"meta"} and $meta->{"meta"} eq "end_segment"
$meta->{"meta"}
$meta->{"meta"} eq "end_segment"
Truth table100%3/3
A and B
A= $meta->{"meta"}B= $meta->{"meta"} eq "end_segment"
| |||||||||||||||||||||||||||||||
| 293 | 97 | ▶ | if ($self->get_current_word_sense()) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 294 | 96 | $self->get_current_word_sense()->add_lexeme($lexeme); | |||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||
| 296 | 97 | my $_lexeme = Wiktionary::Parser::Section::Translations::WordSense::Lexeme->new(); | |||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||
| 300 | 1182 | ▶ | $lexeme->add_translations(@{$meta->{translations} || []}) if ($meta->{translations}); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$meta->{'translations'} || []
MC/DC0%0/1
$meta->{'translations'} || []
$meta->{'translations'}
Truth table50%1/2
A
A= $meta->{'translations'}
| |||||||||||||||||||||||||||||||
| 301 | 1182 | ▶ | $lexeme->set_gender($meta->{gender}) if ($meta->{gender}); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 302 | 1182 | ▶ | $lexeme->set_number($meta->{number}) if ($meta->{number}); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 303 | 1182 | ▶ | $lexeme->set_transliteration($meta->{transliteration}) if ($meta->{transliteration}); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 304 | 1182 | ▶ | $lexeme->set_alternate($meta->{alternate}) if ($meta->{alternate}); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||
| 306 | 1182 | ▶ | $lexeme->add_qualifiers(@{$meta->{qualifier} || [] }) if $meta->{qualifier}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$meta->{'qualifier'} || []
MC/DC0%0/1
$meta->{'qualifier'} || []
$meta->{'qualifier'}
Truth table50%1/2
A
A= $meta->{'qualifier'}
| |||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||
| 308 | 1182 | ▶ | $lexeme->set_language_name($meta->{language}) if $meta->{language}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 309 | 1182 | ▶ | $lexeme->set_language_code($meta->{language_code}) if $meta->{language_code}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||
| 313 | 345 | ▶ | if ($self->get_current_word_sense() && $lexeme) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->get_current_word_sense and $lexeme
MC/DC50%1/2
$self->get_current_word_sense and $lexeme
$self->get_current_word_sense
$lexeme
Truth table66%2/3
A and B
A= $self->get_current_word_senseB= $lexeme
| |||||||||||||||||||||||||||||||
| 314 | 336 | $self->get_current_word_sense()->add_lexeme($lexeme); | |||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||
| 317 | # find the template pattern that matches the beginning of the given line | ||||||||||||||||||||||||||||||
| 318 | 1551 | ▶ | sub get_template_match { | ||||||||||||||||||||||||||||
|
Subroutine
get_template_match: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 319 | 1551 | my $self = shift; | |||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||
| 321 | 1551 | my $templates = $self->get_templates(); | |||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||
| 323 | 1551 | for my $template (@$templates) { | |||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||
| 325 | 13935 | my $pattern = $template->{pattern}; | |||||||||||||||||||||||||||||
| 326 | 13935 | my $parser = $template->{parser}; | |||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||
| 328 | 13935 | ▶ | if (my @matches = $_[0] =~ m/^$pattern/) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 329 | # if there's a match parse extracted string into a hash of metadata | ||||||||||||||||||||||||||||||
| 330 | 1206 | my $meta = $parser->($self,@matches); | |||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||
| 332 | # remove the matched piece from the line | ||||||||||||||||||||||||||||||
| 333 | 1206 | $_[0] =~ s/$pattern//; | |||||||||||||||||||||||||||||
| 334 | 1206 | $_[0] =~ s/^\s*//; | |||||||||||||||||||||||||||||
| 335 | 1206 | return $meta; | |||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||
| 338 | 345 | return; | |||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||
| 341 | 24 | ▶ | sub add_word_sense { | ||||||||||||||||||||||||||||
|
Subroutine
add_word_sense: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 342 | 24 | my $self = shift; | |||||||||||||||||||||||||||||
| 343 | 24 | my $word_sense = shift; | |||||||||||||||||||||||||||||
| 344 | 24 | my $sense = $word_sense->get_word(); | |||||||||||||||||||||||||||||
| 345 | 24 | $self->{word_senses}{$sense} = $word_sense; | |||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | sub get_word_sense { | ||||||||||||||||||||||||||||
|
Subroutine
get_word_sense: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 349 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 350 | 0 | my $sense = shift; | |||||||||||||||||||||||||||||
| 351 | 0 | return $self->{word_senses}{$sense}; | |||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||
| 355 | 40 | ▶ | sub get_word_senses { | ||||||||||||||||||||||||||||
|
Subroutine
get_word_senses: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 356 | 40 | my $self = shift; | |||||||||||||||||||||||||||||
| 357 | 40 | ▶ | return [values %{$self->{word_senses} || {}}]; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'word_senses'} || {}
MC/DC100%1/1
$self->{'word_senses'} || {}
$self->{'word_senses'}
Truth table100%2/2
A
A= $self->{'word_senses'}
| |||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||
| 360 | 29 | ▶ | sub set_current_word_sense { | ||||||||||||||||||||||||||||
|
Subroutine
set_current_word_sense: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 361 | 29 | my $self = shift; | |||||||||||||||||||||||||||||
| 362 | 29 | $self->{current_word_sense} = shift; | |||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||
| 365 | 898 | ▶ | sub get_current_word_sense { | ||||||||||||||||||||||||||||
|
Subroutine
get_current_word_sense: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 366 | 898 | my $self = shift; | |||||||||||||||||||||||||||||
| 367 | 898 | return $self->{current_word_sense}; | |||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||
| 369 | 3 | 1; | |||||||||||||||||||||||||||||