| 1 | package WordLists::WordList; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use WordLists::Sense; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use WordLists::Common qw (@sDefaultAttList @sDefiningAttlist @sParsingParameters); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use WordLists::Base; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | our $VERSION = $WordLists::Base::VERSION; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | our $DEFAULT_ENCODING = 'ascii'; | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | our $NO_SENSE_IDENTITY = 'ascii'; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | my ($class, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | my $self = { | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | default_attlist => \@sDefaultAttList, | ||||||||||||||||||||||||||||||||||||||||||||||
| 19 | defining_attlist => \@sDefiningAttlist, | ||||||||||||||||||||||||||||||||||||||||||||||
| 20 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | bless ($self, $class); | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | 3 | ▶ | if ( ref $args eq 'HASH') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | if (defined $args->{'parser'}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | $self->parser($args->{'parser'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | if (defined $args->{'serialiser'}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | $self->serialiser($args->{'serialiser'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | if (defined $args->{'name'}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | $self->{'name'} = $args->{'name'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | if (defined $args->{'attlist'}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | $self->{'attlist'} = $args->{'attlist'}; # todo: validate this | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | ▶ | if (defined $args->{'from_string'}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $self->read_string($args->{'from_string'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | elsif (defined $args->{'from_file'}) | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | $self->read_file($args->{'from_file'}, $args->{'encoding'}); | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | sub read_file # warning: this doesn't squash BOMs | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | my ($self, $fn, $enc) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_file: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | my $args = {}; | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | if (defined $self->{'attlist'}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $args->{'attlist'} = $self->{'attlist'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | foreach (@{$self->parser->parse_file($fn, $enc,$args)}) | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 13 | $self->read_hash($_); | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | sub read_hash | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 14 | ▶ | my ($self, $hash, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_hash: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 14 | my $sense = WordLists::Sense->new($hash); | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 14 | ▶ | if (ref $sense eq 'WordLists::Sense') | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 14 | $self->add_sense($sense); | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | sub read_array | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | my ($self, $array, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_array: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | foreach my $hash (@{$array}) | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 1 | ▶ | if (ref $hash eq ref {}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | $self->read_hash($hash) ; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 85 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | warn 'Expecting $wl->read_array([{}])' | |||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | sub read_string | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | my ($self, $s, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read_string: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | my $parsed = $self->parser->parse_string($s); | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | $parsed = [$parsed] if (ref ($parsed) eq ref {}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | return $self->read_array($parsed, $args); | |||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | sub to_string | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 1 | ▶ | my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | foreach(@sParsingParameters) | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 5 | ▶ | $args->{$_} = $self->{$_} unless defined $args->{$_}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | my $senses = [map {$_->to_hash($args)} $self->get_all_senses]; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1 | return $self->serialiser->to_string($senses, $args); | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | sub compare_senses | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | my ($self, $sense_a, $sense_b, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compare_senses: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | my $cmp = [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | {'name' => 'hw', 'c' => sub{lc $_[0] cmp lc $_[1] }} | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if (defined($args->{'sense_compare'}) and ref ($args->{'sense_compare'}) eq ref []) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $args->{"sense_compare"} and ref $args->{"sense_compare"} eq ref []
MC/DC0%0/2
defined $args->{"sense_compare"} and ref $args->{"sense_compare"} eq ref []
defined $args->{"sense_compare"}
ref $args->{"sense_compare"} eq ref []
Truth table0%0/3
A and B
A= defined $args->{"sense_compare"}B= ref $args->{"sense_compare"} eq ref []
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $cmp = $args->{'sense_compare'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | foreach (@{$cmp}) | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my $result = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | if (defined $_->{'name'}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $result = &{$_->{'c'}}( | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | $sense_a->get($_->{'name'}), | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | $sense_b->get($_->{'name'}) | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $result = &{$_->{'c'}}( | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | $sense_a, | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | $sense_b | ||||||||||||||||||||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | return $result unless $result == 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | sub sort | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | my ($self, $args) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sort: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $self->{'senses'} = [sort {$self->compare_senses($a, $b, $args)} @{$self->{'senses'}}]; | |||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | sub get_senses_for | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 24 | ▶ | my ($self, $sHW, $sPos) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_senses_for: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 24 | my @senses; | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | 24 | ▶ | if (defined $sPos and ($sPos or $self->{'significant_empty_pos'})) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%3/6
defined $sPos and $sPos || $self->{"significant_empty_pos"}
$sPos or $self->{"significant_empty_pos"}
MC/DC33%1/3
defined $sPos and $sPos || $self->{"significant_empty_pos"}
defined $sPos
$sPos
$self->{"significant_empty_pos"}
Truth table50%2/4
A and B or C
A= defined $sPosB= $sPosC= $self->{"significant_empty_pos"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 22 | ▶ | @senses = @{$self->{'index'}{$sHW}{$sPos}} if defined $self->{'index'}{$sHW}{$sPos}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | elsif (defined $sHW) | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | foreach my $sPos (keys %{$self->{'index'}{$sHW}}) | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | push @senses, @{$self->{'index'}{$sHW}{$sPos}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 24 | return @senses; | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | sub get_all_senses | ||||||||||||||||||||||||||||||||||||||||||||||
| 169 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 3 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_all_senses: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 3 | ▶ | return () unless defined $self->{'senses'}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 3 | return @{$self->{'senses'}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | sub get_current_attlist | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_current_attlist: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if ($self->{'attlist'}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | return @{$self->{'attlist'}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | return @{$self->{'default_attlist'}}; | |||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 183 | sub get_default_attlist | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_default_attlist: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | return @{$self->{'default_attlist'}} | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | sub add_sense | ||||||||||||||||||||||||||||||||||||||||||||||
| 189 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 22 | ▶ | my ($self, $sense) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_sense: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 22 | my $success = $self->_add_sense_to_list($sense); | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | 22 | $self->_index_sense($sense); | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | 22 | return $success; | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 195 | sub _add_sense_to_list | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 22 | ▶ | my ($self, $sense) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_sense_to_list: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 22 | return push (@{$self->{'senses'}}, $sense); | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | sub _index_sense | ||||||||||||||||||||||||||||||||||||||||||||||
| 201 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 22 | ▶ | my ($self, $sense) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_index_sense: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 22 | my $sHW = $sense->get_hw; | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 22 | my $sPos = $sense->get_pos; | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | 22 | ▶ | $sHW ||=''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$sHW ||= ""
MC/DC0%0/1
$sHW ||= ""
$sHW
Truth table50%1/2
A
A= $sHW
| |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 22 | ▶ | $sPos ||=''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$sPos ||= ""
MC/DC0%0/1
$sPos ||= ""
$sPos
Truth table50%1/2
A
A= $sPos
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 22 | return push (@{$self->{'index'}{$sHW}{$sPos}}, $sense); | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | sub _rebuild_index | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_rebuild_index: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my $index = $self->{'index'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | $index = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | foreach my $sense (@{$self->{'senses'}}) | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | push (@{$index->{$sense->get_hw}{$sense->get_pos}}, $sense); | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | sub parser | ||||||||||||||||||||||||||||||||||||||||||||||
| 224 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 3 | ▶ | my ($self, $parser) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parser: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 3 | ▶ | if (defined $parser) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | $self->{'#parser'} = $parser; | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 3 | ▶ | if (defined $self->{'#parser'}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 2 | return $self->{'#parser'} | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 234 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 235 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 4 | ▶ | use WordLists::Parse::Simple; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 1 | $self->{'#parser'} = WordLists::Parse::Simple->new(); | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 240 | sub serialiser | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | ▶ | my ($self, $serialiser) = @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serialiser: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | ▶ | if (defined $serialiser) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | $self->{'#serialiser'} = $serialiser; | |||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 1 | ▶ | if (defined $self->{'#serialiser'}) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return $self->{'#serialiser'} | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | else | ||||||||||||||||||||||||||||||||||||||||||||||
| 252 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | ▶ | use WordLists::Serialise::Simple; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1 | return $self->{'#serialiser'} = WordLists::Serialise::Simple->new(); | |||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||
| 262 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||
| 264 | WordLists::WordList | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | my $wl = WordLists::WordList->new({from_file=>'unit1.txt'}); | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | my @senses = $wl->get_senses_for('book', 'verb'); | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | $wl->add_sense($new_sense); | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | print OUT $wl->to_string; | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | WordLists::WordList is a base class for a group of L<WordLists::Sense> objects. | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||
| 277 | =head3 new | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | The constructor creates an empty wordlist, and will populate the wordlist if you pass it parameters such as C<from_string> and C<from_file> (in which case, you can also specify C<encoding>). These parameters should be passed in a hash ref (as per the example in the synopsis). You can populate the wordlist later, of course. | ||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | =head3 parser | ||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||
| 283 | This is an accessor for the parser, and returns the parser and/or sets the parser if given one. The parser defaults to L<WordLists::Parse::Simple>, and the parser is created the first time it is requested (not when the L<WordLists::WordList> object is created, unless C<from_file> or C<from_string> is used). | ||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | =head3 serialiser | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||
| 287 | This is an accessor for the serialiser, and returns the serialiser and/or sets the serialiser if given one. The serialiser defaults to L<WordLists::Serialise::Simple>, and the serialiser is created the first time it is requested (not when the L<WordLists::WordList> object is created). | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | =head3 get_senses_for | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||
| 291 | This returns senses which match the parameters specified (hw, pos). | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | =head3 get_all_senses | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | This returns all senses; by default, it will return them in the order in which they were entered, but senses can be reordered using the C<sort> method. | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | =head1 TODO | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | Please use the Github issues tracker. | ||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||
| 303 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | Copyright 2011-2012 © Cambridge University Press. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||