line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WordLists::Lookup;
|
2
|
2
|
|
|
2
|
|
1630
|
use strict;
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
65
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings;
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
53
|
|
4
|
2
|
|
|
2
|
|
11
|
use utf8;
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
13
|
|
5
|
2
|
|
|
2
|
|
42
|
use WordLists::Sense;
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
52
|
|
6
|
2
|
|
|
2
|
|
8
|
use WordLists::Common qw(/generic/);
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1928
|
|
7
|
|
|
|
|
|
|
our $AUTOLOAD;
|
8
|
|
|
|
|
|
|
our $UNPACKAGE_SENSES = 1;
|
9
|
|
|
|
|
|
|
sub new
|
10
|
|
|
|
|
|
|
{
|
11
|
1
|
|
|
1
|
0
|
16
|
my ($class, $args) = @_;
|
12
|
1
|
|
|
|
|
9
|
my $self = {
|
13
|
|
|
|
|
|
|
'index' => [],
|
14
|
|
|
|
|
|
|
'norm_hw' => \&generic_norm_hw,
|
15
|
|
|
|
|
|
|
'norm_pos' => \&generic_norm_pos,
|
16
|
|
|
|
|
|
|
};
|
17
|
1
|
50
|
|
|
|
7
|
if ( ref $args eq ref {})
|
18
|
|
|
|
|
|
|
{
|
19
|
1
|
|
|
|
|
3
|
foreach (qw(norm_hw norm_pos dicts))
|
20
|
|
|
|
|
|
|
{
|
21
|
3
|
100
|
|
|
|
13
|
if (defined $args->{$_})
|
22
|
|
|
|
|
|
|
{
|
23
|
1
|
|
|
|
|
4
|
$self->{$_} = $args->{$_};
|
24
|
|
|
|
|
|
|
}
|
25
|
|
|
|
|
|
|
}
|
26
|
|
|
|
|
|
|
}
|
27
|
|
|
|
|
|
|
else
|
28
|
|
|
|
|
|
|
{
|
29
|
0
|
|
|
|
|
0
|
warn ('Failed to create '. $class . ' (hashref expected as argument to function new; found '.$args.')');
|
30
|
0
|
|
|
|
|
0
|
return undef;
|
31
|
|
|
|
|
|
|
}
|
32
|
1
|
|
|
|
|
5
|
bless ($self, $class);
|
33
|
1
|
|
|
|
|
2
|
$self->index_dict($_) foreach @{$self->{'dicts'}};
|
|
1
|
|
|
|
|
13
|
|
34
|
1
|
50
|
|
|
|
2
|
return $self if @{$self->{'dicts'}};
|
|
1
|
|
|
|
|
8
|
|
35
|
0
|
|
|
|
|
0
|
warn ('Failed to create '. $class);
|
36
|
0
|
|
|
|
|
0
|
return undef;
|
37
|
|
|
|
|
|
|
}
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub norm_hw
|
40
|
|
|
|
|
|
|
{
|
41
|
15
|
|
|
15
|
0
|
24
|
my ($self, $sHW) = @_;
|
42
|
15
|
|
|
|
|
17
|
return &{$self->{'norm_hw'}}($sHW);
|
|
15
|
|
|
|
|
49
|
|
43
|
|
|
|
|
|
|
}
|
44
|
|
|
|
|
|
|
sub norm_pos
|
45
|
|
|
|
|
|
|
{
|
46
|
13
|
|
|
13
|
0
|
18
|
my ($self, $sPos) = @_;
|
47
|
13
|
|
|
|
|
15
|
return &{$self->{'norm_pos'}}($sPos);
|
|
13
|
|
|
|
|
37
|
|
48
|
|
|
|
|
|
|
}
|
49
|
|
|
|
|
|
|
sub get_senses_for
|
50
|
|
|
|
|
|
|
{
|
51
|
4
|
|
|
4
|
0
|
6
|
my ($self, $sHW, $sPos) = @_;
|
52
|
4
|
|
|
|
|
10
|
$sHW = $self->norm_hw($sHW);
|
53
|
4
|
|
|
|
|
6
|
my @senses;
|
54
|
4
|
50
|
0
|
|
|
16
|
if (defined $sPos and ($sPos or $self->{'significant_empty_pos'}))
|
|
|
|
33
|
|
|
|
|
55
|
|
|
|
|
|
|
{
|
56
|
0
|
|
|
|
|
0
|
$sPos = $self->norm_pos($sPos);
|
57
|
0
|
|
|
|
|
0
|
DICT: foreach my $iDict (0..$#{$self->{'index'}})
|
|
0
|
|
|
|
|
0
|
|
58
|
|
|
|
|
|
|
{
|
59
|
0
|
0
|
|
|
|
0
|
if (defined $self->{'index'}[$iDict]{$sHW}{$sPos})
|
60
|
|
|
|
|
|
|
{
|
61
|
0
|
|
|
|
|
0
|
@senses = @{$self->{'index'}[$iDict]{$sHW}{$sPos}} ;
|
|
0
|
|
|
|
|
0
|
|
62
|
0
|
|
|
|
|
0
|
last DICT;
|
63
|
|
|
|
|
|
|
}
|
64
|
|
|
|
|
|
|
}
|
65
|
|
|
|
|
|
|
}
|
66
|
|
|
|
|
|
|
else
|
67
|
|
|
|
|
|
|
{
|
68
|
4
|
|
|
|
|
5
|
DICT: foreach my $iDict (0..$#{$self->{'index'}})
|
|
4
|
|
|
|
|
13
|
|
69
|
|
|
|
|
|
|
{
|
70
|
4
|
100
|
|
|
|
17
|
if (defined $self->{'index'}[$iDict]{$sHW})
|
71
|
|
|
|
|
|
|
{
|
72
|
3
|
|
|
|
|
11
|
foreach my $sPos (keys %{$self->{'index'}[$iDict]{$sHW}})
|
|
3
|
|
|
|
|
14
|
|
73
|
|
|
|
|
|
|
{
|
74
|
5
|
|
|
|
|
7
|
push @senses, @{$self->{'index'}[$iDict]{$sHW}{$sPos}};
|
|
5
|
|
|
|
|
22
|
|
75
|
|
|
|
|
|
|
}
|
76
|
3
|
50
|
|
|
|
14
|
last DICT if @senses;
|
77
|
|
|
|
|
|
|
}
|
78
|
|
|
|
|
|
|
}
|
79
|
|
|
|
|
|
|
}
|
80
|
4
|
|
|
|
|
15
|
return @senses;
|
81
|
|
|
|
|
|
|
}
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub index_dict
|
84
|
|
|
|
|
|
|
{
|
85
|
1
|
|
|
1
|
0
|
3
|
my ($self, $dict) = @_;
|
86
|
1
|
|
|
|
|
2
|
my $iNewDict = $#{$self->{'index'}}+1;
|
|
1
|
|
|
|
|
5
|
|
87
|
1
|
50
|
|
|
|
6
|
if (ref $dict eq ref $self)
|
88
|
|
|
|
|
|
|
{
|
89
|
0
|
|
|
|
|
0
|
foreach my $iDict(0..$#{$self->{'index'}})
|
|
0
|
|
|
|
|
0
|
|
90
|
|
|
|
|
|
|
{
|
91
|
0
|
|
|
|
|
0
|
foreach my $sOHW (keys %{$dict->{'index'}[$iDict]})
|
|
0
|
|
|
|
|
0
|
|
92
|
|
|
|
|
|
|
{
|
93
|
0
|
|
|
|
|
0
|
my $sHW = $self->norm_hw($sOHW);
|
94
|
0
|
|
|
|
|
0
|
foreach my $sOPos (keys %{$dict->{'index'}[$iDict]{$sOHW}})
|
|
0
|
|
|
|
|
0
|
|
95
|
|
|
|
|
|
|
{
|
96
|
0
|
|
|
|
|
0
|
my $sPos = $self->norm_pos($sOPos);
|
97
|
0
|
|
|
|
|
0
|
push (@{$self->{'index'}[$iNewDict]{$sHW}{$sPos}}, $dict->get_senses_for($sOHW, $sOPos));
|
|
0
|
|
|
|
|
0
|
|
98
|
|
|
|
|
|
|
}
|
99
|
|
|
|
|
|
|
}
|
100
|
|
|
|
|
|
|
}
|
101
|
|
|
|
|
|
|
}
|
102
|
|
|
|
|
|
|
else
|
103
|
|
|
|
|
|
|
{
|
104
|
1
|
|
|
|
|
3
|
foreach my $sOHW (keys %{$dict->{'index'}})
|
|
1
|
|
|
|
|
19
|
|
105
|
|
|
|
|
|
|
{
|
106
|
11
|
|
|
|
|
26
|
my $sHW = $self->norm_hw($sOHW);
|
107
|
11
|
|
|
|
|
16
|
foreach my $sOPos (keys %{$dict->{'index'}{$sOHW}})
|
|
11
|
|
|
|
|
43
|
|
108
|
|
|
|
|
|
|
{
|
109
|
13
|
|
|
|
|
27
|
my $sPos = $self->norm_pos($sOPos);
|
110
|
13
|
|
|
|
|
18
|
push (@{$self->{'index'}[$iNewDict]{$sHW}{$sPos}}, $dict->get_senses_for($sOHW, $sOPos));
|
|
13
|
|
|
|
|
85
|
|
111
|
|
|
|
|
|
|
}
|
112
|
|
|
|
|
|
|
}
|
113
|
|
|
|
|
|
|
}
|
114
|
|
|
|
|
|
|
}
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
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 or L (or indeed L) objects and searching them 'fuzzily' - that is to say, you can access case insentitively, or ignoring spaces, etc.
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
L objects are subclasses of L 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 |