| 1 | package Lingua::RU::OpenCorpora::Tokenizer::List; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 3 | our $VERSION = 0.06; | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 3 | ▶ | use IO::File; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 3 | ▶ | use File::Spec; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 3 | ▶ | use Carp qw(croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 3 | ▶ | use Encode qw(decode); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | 3 | ▶ | use IO::Uncompress::Gunzip; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | 3 | ▶ | use File::ShareDir qw(dist_dir); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 0 | ▶ | sub data_version { 0.05 } | ||||||||||||||||||
|
Subroutine
data_version: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 8 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||
| 19 | 8 | my($class, $name, $args) = @_; | |||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 8 | ▶ | croak "List name unspecified" unless defined $name; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 8 | ▶ | $args ||= {}; | ||||||||||||||||||
|
Condition100%2/2
$args ||= {}
MC/DC100%1/1
$args ||= {}
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||
| 24 | 8 | ▶ | $args->{data_dir} ||= dist_dir('Lingua-RU-OpenCorpora-Tokenizer'); | ||||||||||||||||||
|
Condition66%2/3
$args->{"data_dir"} ||= dist_dir("Lingua-RU-OpenCorpora-Tokenizer")
MC/DC0%0/2
$args->{"data_dir"} ||= dist_dir("Lingua-RU-OpenCorpora-Tokenizer")
$args->{"data_dir"}
dist_dir("Lingua-RU-OpenCorpora-Tokenizer")
Truth table66%2/3
A ||= B
A= $args->{"data_dir"}B= dist_dir("Lingua-RU-OpenCorpora-Tokenizer")
| |||||||||||||||||||||
| 25 | 8 | ▶ | $args->{root_url} ||= 'http://opencorpora.org/files/export/tokenizer_data'; | ||||||||||||||||||
|
Condition50%1/2
$args->{"root_url"} ||= "http://opencorpora.org/files/export/tokenizer_data"
MC/DC0%0/1
$args->{"root_url"} ||= "http://opencorpora.org/files/export/tokenizer_data"
$args->{"root_url"}
Truth table50%1/2
A
A= $args->{"root_url"}
| |||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 8 | my $self = bless { | |||||||||||||||||||
| 28 | %$args, | ||||||||||||||||||||
| 29 | name => $name, | ||||||||||||||||||||
| 30 | }, $class; | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 8 | $self->_load; | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 8 | $self; | |||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 31 | ▶ | sub in_list { exists $_[0]->{data}{lc $_[1]} } | ||||||||||||||||||
|
Subroutine
in_list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 8 | ▶ | sub _load { | ||||||||||||||||||
|
Subroutine
_load: called CC=3 SCAR=11.0
| |||||||||||||||||||||
| 40 | 8 | my $self = shift; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 8 | my $fn = $self->_path; | |||||||||||||||||||
| 43 | 8 | ▶ | my $fh = IO::Uncompress::Gunzip->new($fn) or die "$fn: $IO::Uncompress::Gunzip::GunzipError"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 8 | chomp($self->{version} = $fh->getline); | |||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 8 | my @data = map decode('utf-8', lc), $fh->getlines; | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | # workaround for The Unicode Bug | ||||||||||||||||||||
| 50 | # see https://metacpan.org/module/perlunicode#The-Unicode-Bug | ||||||||||||||||||||
| 51 | 8 | utf8::upgrade($_) for @data; | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 8 | $self->_parse_list(\@data); | |||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 8 | $fh->close; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 8 | return; | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | ▶ | sub _update { | ||||||||||||||||||
|
Subroutine
_update: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 61 | 0 | my($self, $new_data) = @_; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 0 | my $fn = $self->_path; | |||||||||||||||||||
| 64 | 0 | ▶ | my $fh = IO::File->new($fn, '>') or croak "$fn: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 65 | 0 | $fh->binmode; | |||||||||||||||||||
| 66 | 0 | $fh->print($new_data); | |||||||||||||||||||
| 67 | 0 | $fh->close; | |||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 0 | $self->_load; | |||||||||||||||||||
| 70 | } | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 6 | ▶ | sub _parse_list { | ||||||||||||||||||
|
Subroutine
_parse_list: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 74 | 6 | my($self, $list) = @_; | |||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 6 | chomp @$list; | |||||||||||||||||||
| 77 | 6 | $self->{data} = +{ map {$_,undef} @$list }; | |||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 6 | return; | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | 8 | ▶ | sub _path { | ||||||||||||||||||
|
Subroutine
_path: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 83 | 8 | my $self = shift; | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | 8 | File::Spec->catfile($self->{data_dir}, "$self->{name}.gz"); | |||||||||||||||||||
| 86 | } | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | ▶ | sub _url { | ||||||||||||||||||
|
Subroutine
_url: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 89 | 0 | my($self, $mode) = @_; | |||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | ▶ | $mode ||= 'file'; | ||||||||||||||||||
|
Condition0%0/2
$mode ||= "file"
MC/DC0%0/1
$mode ||= "file"
$mode
Truth table0%0/2
A
A= $mode
| |||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | my $url = join '/', $self->{root_url}, $self->data_version, $self->{name}; | |||||||||||||||||||
| 94 | 0 | ▶ | if($mode eq 'file') { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 95 | 0 | $url .= '.gz'; | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | elsif($mode eq 'version') { | ||||||||||||||||||||
| 98 | 0 | $url .= '.latest'; | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | $url; | |||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 3 | 1; | |||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||