| 1 | package Wiktionary::Parser::Section::PartofSpeech; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 3 | ▶ | use Wiktionary::Parser::Section; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | |||||||||||||||||||
| 5 | 3 | ▶ | use base qw(Wiktionary::Parser::Section); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | 12 | ▶ | sub new { | ||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||
| 8 | 12 | my $class = shift; | |||||||||||||||||
| 9 | 12 | my %args = @_; | |||||||||||||||||
| 10 | 12 | my $self = bless Wiktionary::Parser::Section->new(%args), $class; | |||||||||||||||||
| 11 | |||||||||||||||||||
| 12 | # in some poorly formatted sections, | ||||||||||||||||||
| 13 | # we can still get the part of speech and language from section headers | ||||||||||||||||||
| 14 | # if they are not defined in markup | ||||||||||||||||||
| 15 | 12 | $self->set_part_of_speech($self->get_header()); | |||||||||||||||||
| 16 | 12 | $self->set_language_code($self->get_language()); | |||||||||||||||||
| 17 | 12 | return $self; | |||||||||||||||||
| 18 | } | ||||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | # add a line of content to this section and parse it into its component parts | ||||||||||||||||||
| 21 | 58 | ▶ | sub add_content { | ||||||||||||||||
|
Subroutine
add_content: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||
| 22 | 58 | my $self = shift; | |||||||||||||||||
| 23 | 58 | my $line = shift; | |||||||||||||||||
| 24 | |||||||||||||||||||
| 25 | 58 | ▶ | if ($line =~ m/^\{\{([^\}]+)\}\}/) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 26 | 11 | my $header_meta = $1; | |||||||||||||||||
| 27 | 11 | my @meta_parts = split(/\|/,$header_meta); | |||||||||||||||||
| 28 | |||||||||||||||||||
| 29 | # e.g. {{head|en|noun}} | ||||||||||||||||||
| 30 | 11 | ▶ | if ($meta_parts[0] eq 'head') { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 31 | 2 | $self->set_language_code($meta_parts[1]); | |||||||||||||||||
| 32 | 2 | $self->set_part_of_speech($meta_parts[2]) | |||||||||||||||||
| 33 | |||||||||||||||||||
| 34 | |||||||||||||||||||
| 35 | } elsif ($meta_parts[0] =~ m/^(\w+)\-(\w+)-(\w+)\|?/) { | ||||||||||||||||||
| 36 | # {{roa-jer-noun|... | ||||||||||||||||||
| 37 | 2 | $self->set_language_code($1); | |||||||||||||||||
| 38 | 2 | $self->set_part_of_speech($3); | |||||||||||||||||
| 39 | 2 | $self->set_inflection([@meta_parts[1..-1]]); | |||||||||||||||||
| 40 | |||||||||||||||||||
| 41 | } elsif ($meta_parts[0] =~ m/^(\w+)\-(\w+)/) { | ||||||||||||||||||
| 42 | # e.g. {{en-noun|...}} | ||||||||||||||||||
| 43 | 6 | $self->set_language_code($1); | |||||||||||||||||
| 44 | 6 | $self->set_part_of_speech($2); | |||||||||||||||||
| 45 | 6 | $self->set_inflection([@meta_parts[1..-1]]); | |||||||||||||||||
| 46 | } | ||||||||||||||||||
| 47 | } | ||||||||||||||||||
| 48 | |||||||||||||||||||
| 49 | 58 | push @{$self->{content}}, $line; | |||||||||||||||||
| 50 | } | ||||||||||||||||||
| 51 | |||||||||||||||||||
| 52 | 22 | ▶ | sub set_part_of_speech { | ||||||||||||||||
|
Subroutine
set_part_of_speech: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||
| 53 | 22 | my $self = shift; | |||||||||||||||||
| 54 | 22 | $self->{part_of_speech} = shift; | |||||||||||||||||
| 55 | } | ||||||||||||||||||
| 56 | |||||||||||||||||||
| 57 | 0 | ▶ | sub get_part_of_speech { | ||||||||||||||||
|
Subroutine
get_part_of_speech: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 58 | 0 | my $self = shift; | |||||||||||||||||
| 59 | 0 | return $self->{part_of_speech}; | |||||||||||||||||
| 60 | } | ||||||||||||||||||
| 61 | |||||||||||||||||||
| 62 | |||||||||||||||||||
| 63 | 22 | ▶ | sub set_language_code { | ||||||||||||||||
|
Subroutine
set_language_code: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||
| 64 | 22 | my $self = shift; | |||||||||||||||||
| 65 | 22 | $self->{language_code} = shift; | |||||||||||||||||
| 66 | } | ||||||||||||||||||
| 67 | |||||||||||||||||||
| 68 | 0 | ▶ | sub get_language_code { | ||||||||||||||||
|
Subroutine
get_language_code: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 69 | 0 | my $self = shift; | |||||||||||||||||
| 70 | 0 | return $self->{language_code}; | |||||||||||||||||
| 71 | } | ||||||||||||||||||
| 72 | |||||||||||||||||||
| 73 | 8 | ▶ | sub set_inflection { | ||||||||||||||||
|
Subroutine
set_inflection: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||
| 74 | 8 | my $self = shift; | |||||||||||||||||
| 75 | 8 | $self->{inflection} = shift; | |||||||||||||||||
| 76 | } | ||||||||||||||||||
| 77 | |||||||||||||||||||
| 78 | 0 | ▶ | sub get_inflection { | ||||||||||||||||
|
Subroutine
get_inflection: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 79 | 0 | my $self = shift; | |||||||||||||||||
| 80 | 0 | return $self->{inflection}; | |||||||||||||||||
| 81 | } | ||||||||||||||||||
| 82 | |||||||||||||||||||
| 83 | |||||||||||||||||||
| 84 | |||||||||||||||||||
| 85 | 3 | 1; | |||||||||||||||||