Lookup.pm

filter: Statementstmt 74.0% 60 / 81 Branchbran 56.2% 9 / 16 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 5 totaltotal 66.1% 80 / 121 SCAR 35.7
CC
21
Cov
68%
get_senses_for
20.4
index_dict
11.7
new
6.8
CRAP 35.5
« Common.pm ↑ Summary Parse/Simple.pm »
1 package WordLists::Lookup;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use WordLists::Sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use WordLists::Common qw(/generic/);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 our $AUTOLOAD;
8 2 our $UNPACKAGE_SENSES = 1;
9 sub new
10 {
11 1 ▶ my ($class, $args) = @_;
Subroutine new: called CC=6 SCAR=19.2
Pod undocumented
12 1 my $self = {
13 'index' => [],
14 'norm_hw' => \&generic_norm_hw,
15 'norm_pos' => \&generic_norm_pos,
16 };
17 1 ▶ if ( ref $args eq ref {})
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args eq ref {}) { } 1 0 1
18 {
19 1 foreach (qw(norm_hw norm_pos dicts))
20 {
21 3 ▶ if (defined $args->{$_})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args->{$_}) 1 2 3
22 {
23 1 $self->{$_} = $args->{$_};
24 }
25 }
26 }
27 else
28 {
29 0 warn ('Failed to create '. $class . ' (hashref expected as argument to function new; found '.$args.')');
30 0 return undef;
31 }
32 1 bless ($self, $class);
33 1 $self->index_dict($_) foreach @{$self->{'dicts'}};
34 1 ▶ return $self if @{$self->{'dicts'}};
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"dicts"};} 1 0 1
35 0 warn ('Failed to create '. $class);
36 0 return undef;
37 }
38
39 sub norm_hw
40 {
41 15 ▶ my ($self, $sHW) = @_;
Subroutine norm_hw: called CC=1 SCAR=0.0
Pod undocumented
42 15 return &{$self->{'norm_hw'}}($sHW);
43 }
44 sub norm_pos
45 {
46 13 ▶ my ($self, $sPos) = @_;
Subroutine norm_pos: called CC=1 SCAR=0.0
Pod undocumented
47 13 return &{$self->{'norm_pos'}}($sPos);
48 }
49 sub get_senses_for
50 {
51 4 ▶ my ($self, $sHW, $sPos) = @_;
Subroutine get_senses_for: called CC=10 SCAR=30.2
Pod undocumented
52 4 $sHW = $self->norm_hw($sHW);
53 4 my @senses;
54 4 ▶ if (defined $sPos and ($sPos or $self->{'significant_empty_pos'}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sPos and $sPos || $self->{'significant_empty_pos'}) { } 0 4 4
Condition16%1/6
defined $sPos and $sPos || $self->{"significant_empty_pos"}
!ll&&!rl&&r
400
$sPos or $self->{"significant_empty_pos"}
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $sPos and $sPos || $self->{"significant_empty_pos"}
defined $sPos $sPos $self->{"significant_empty_pos"}
Truth table25%1/4
A and B or C
A= defined $sPosB= $sPosC= $self->{"significant_empty_pos"}
ABCresult
0XX0
1000
11X1
1011
55 {
56 0 $sPos = $self->norm_pos($sPos);
57 0 DICT: foreach my $iDict (0..$#{$self->{'index'}})
58 {
59 0 ▶ if (defined $self->{'index'}[$iDict]{$sHW}{$sPos})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"index"}[$iDict]{$sHW}{$sPos}) 0 0 0
60 {
61 0 @senses = @{$self->{'index'}[$iDict]{$sHW}{$sPos}} ;
62 0 last DICT;
63 }
64 }
65 }
66 else
67 {
68 4 DICT: foreach my $iDict (0..$#{$self->{'index'}})
69 {
70 4 ▶ if (defined $self->{'index'}[$iDict]{$sHW})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"index"}[$iDict]{$sHW}) 3 1 4
71 {
72 3 foreach my $sPos (keys %{$self->{'index'}[$iDict]{$sHW}})
73 {
74 5 push @senses, @{$self->{'index'}[$iDict]{$sHW}{$sPos}};
75 }
76 3 ▶ last DICT if @senses;
Branch: 1 branch
BranchTrueFalseTotal
if @senses 3 0 3
77 }
78 }
79 }
80 4 return @senses;
81 }
82
83 sub index_dict
84 {
85 1 ▶ my ($self, $dict) = @_;
Subroutine index_dict: called CC=7 SCAR=24.6
Pod undocumented
86 1 my $iNewDict = $#{$self->{'index'}}+1;
87 1 ▶ if (ref $dict eq ref $self)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dict eq ref $self) { } 0 1 1
88 {
89 0 foreach my $iDict(0..$#{$self->{'index'}})
90 {
91 0 foreach my $sOHW (keys %{$dict->{'index'}[$iDict]})
92 {
93 0 my $sHW = $self->norm_hw($sOHW);
94 0 foreach my $sOPos (keys %{$dict->{'index'}[$iDict]{$sOHW}})
95 {
96 0 my $sPos = $self->norm_pos($sOPos);
97 0 push (@{$self->{'index'}[$iNewDict]{$sHW}{$sPos}}, $dict->get_senses_for($sOHW, $sOPos));
98 }
99 }
100 }
101 }
102 else
103 {
104 1 foreach my $sOHW (keys %{$dict->{'index'}})
105 {
106 11 my $sHW = $self->norm_hw($sOHW);
107 11 foreach my $sOPos (keys %{$dict->{'index'}{$sOHW}})
108 {
109 13 my $sPos = $self->norm_pos($sOPos);
110 13 push (@{$self->{'index'}[$iNewDict]{$sHW}{$sPos}}, $dict->get_senses_for($sOHW, $sOPos));
111 }
112 }
113 }
114 }
115
116
117
118 2 1;
119
120
121 =pod
122
123 =head1 NAME
124
125 WordLists::Lookup
126
127 =head1 SYNOPSIS
128
129 my $lookup = WordLists::Lookup->new({ dicts=>[$simple_dict, $technical_dict, $ten_volume_dict ]});
130 $lookup->get_senses_for('aortic');
131 # Nothing in $simple_dict, so fall back to $technical_dict or $ten_volume_dict.
132
133 =head1 DESCRIPTION
134
135 A lookup is a way of accessing one or more L<WordList::WordList> or L<WordList::Dict> (or indeed L<WordList::Lookup>) objects and searching them 'fuzzily' - that is to say, you can access case insentitively, or ignoring spaces, etc.
136
137 L<WordList::Lookup> objects are subclasses of L<WordList::WordList> and inherit all methods.
138
139 =head1 BUGS
140
141 Please use the Github issues tracker.
142
143 =head1 LICENSE
144
145 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.
146
147 =cut
« Common.pm ↑ Summary Parse/Simple.pm »