line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WordLists::Sense;
|
2
|
5
|
|
|
5
|
|
496
|
use strict;
|
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
162
|
|
3
|
5
|
|
|
5
|
|
27
|
use warnings;
|
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
121
|
|
4
|
5
|
|
|
5
|
|
830
|
use utf8;
|
|
5
|
|
|
|
|
15
|
|
|
5
|
|
|
|
|
25
|
|
5
|
|
|
|
|
|
|
our $AUTOLOAD;
|
6
|
5
|
|
|
5
|
|
1109
|
use WordLists::Base;
|
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
944
|
|
7
|
|
|
|
|
|
|
our $VERSION = $WordLists::Base::VERSION;
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
WordLists::Sense - Class for senses in wordlists, dictionaries, etc.
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use WordLists::Sense;
|
16
|
|
|
|
|
|
|
my $sense = WordLists::Sense->new();
|
17
|
|
|
|
|
|
|
$sense->set('hw', 'head');
|
18
|
|
|
|
|
|
|
$sense->set('pos', 'noun');
|
19
|
|
|
|
|
|
|
$sense->set_pos('verb'); # alternative
|
20
|
|
|
|
|
|
|
$sense->has('pos'); # returns 1
|
21
|
|
|
|
|
|
|
$sense->get('pos'); # returns 'verb'
|
22
|
|
|
|
|
|
|
$sense->to_string; # returns "head\tverb" - however it is better to do this from within a wordlist
|
23
|
|
|
|
|
|
|
my $another_sense = WordLists::Sense->new({hw=>'head', pos=>'verb'});
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
This class is a very simple class which is little more than a blessed hash with accessors C, C, and C.
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
The following attributes are 'special' - treated no differently by this module but by others:
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=over
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=item *
|
32
|
|
|
|
|
|
|
C - ('headword') - all searches will be keyed to this
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=item *
|
35
|
|
|
|
|
|
|
C - ('part of speech') - this is a discriminator for finer control
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item *
|
38
|
|
|
|
|
|
|
C - ('dictionary') - this is set by a L object when the sense is added to that object to assert provenance
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=back
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 BUGS
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Please use the Github issues tracker.
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 LICENSE
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
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.
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub new
|
53
|
|
|
|
|
|
|
{
|
54
|
24
|
|
|
24
|
0
|
51
|
my ($class, $args) = @_;
|
55
|
24
|
|
|
|
|
121
|
my $self = $args;
|
56
|
24
|
|
100
|
|
|
85
|
$self ||={};
|
57
|
24
|
|
|
|
|
83
|
bless ($self, $class);
|
58
|
24
|
|
|
|
|
68
|
return $self;
|
59
|
|
|
|
|
|
|
}
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub get
|
62
|
|
|
|
|
|
|
{
|
63
|
18
|
|
|
18
|
0
|
28
|
my ($self, $attr) = @_;
|
64
|
18
|
|
|
|
|
66
|
return $self->{$attr};
|
65
|
|
|
|
|
|
|
}
|
66
|
|
|
|
|
|
|
sub parser
|
67
|
|
|
|
|
|
|
{
|
68
|
0
|
|
|
0
|
0
|
0
|
my ($self, $parser) = @_;
|
69
|
0
|
0
|
|
|
|
0
|
if (defined $parser)
|
70
|
|
|
|
|
|
|
{
|
71
|
0
|
|
|
|
|
0
|
$self->{'#parser'} = $parser;
|
72
|
|
|
|
|
|
|
}
|
73
|
0
|
0
|
|
|
|
0
|
if (defined $self->{'#parser'})
|
74
|
|
|
|
|
|
|
{
|
75
|
0
|
|
|
|
|
0
|
return $self->{'#parser'}
|
76
|
|
|
|
|
|
|
}
|
77
|
|
|
|
|
|
|
else
|
78
|
|
|
|
|
|
|
{
|
79
|
5
|
|
|
5
|
|
2251
|
use WordLists::Parse::Simple;
|
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
595
|
|
80
|
0
|
|
|
|
|
0
|
$self->{'#parser'} = WordLists::Parse::Simple->new();
|
81
|
|
|
|
|
|
|
}
|
82
|
|
|
|
|
|
|
}
|
83
|
|
|
|
|
|
|
sub serialiser
|
84
|
|
|
|
|
|
|
{
|
85
|
0
|
|
|
0
|
0
|
0
|
my ($self, $serialiser) = @_;
|
86
|
0
|
0
|
|
|
|
0
|
if (defined $serialiser)
|
87
|
|
|
|
|
|
|
{
|
88
|
0
|
|
|
|
|
0
|
$self->{'#serialiser'} = $serialiser;
|
89
|
|
|
|
|
|
|
}
|
90
|
0
|
0
|
|
|
|
0
|
if (defined $self->{'#serialiser'})
|
91
|
|
|
|
|
|
|
{
|
92
|
0
|
|
|
|
|
0
|
return $self->{'#serialiser'}
|
93
|
|
|
|
|
|
|
}
|
94
|
|
|
|
|
|
|
else
|
95
|
|
|
|
|
|
|
{
|
96
|
5
|
|
|
5
|
|
2530
|
use WordLists::Serialise::Simple;
|
|
5
|
|
|
|
|
27
|
|
|
5
|
|
|
|
|
11208
|
|
97
|
0
|
|
|
|
|
0
|
$self->{'#serialiser'} = WordLists::Serialise::Simple->new();
|
98
|
|
|
|
|
|
|
}
|
99
|
|
|
|
|
|
|
}
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub set
|
103
|
|
|
|
|
|
|
{
|
104
|
1
|
|
|
1
|
1
|
7
|
my ($self, $attr, $value) = @_;
|
105
|
1
|
|
|
|
|
7
|
return $self->{$attr} = $value;
|
106
|
|
|
|
|
|
|
}
|
107
|
|
|
|
|
|
|
sub has
|
108
|
|
|
|
|
|
|
{
|
109
|
0
|
|
|
0
|
0
|
0
|
my ($self, $attr) = @_;
|
110
|
0
|
|
|
|
|
0
|
return defined $self->{$attr};
|
111
|
|
|
|
|
|
|
}
|
112
|
|
|
|
|
|
|
sub read_hash
|
113
|
|
|
|
|
|
|
{
|
114
|
0
|
|
|
0
|
0
|
0
|
my ($self, $hash, $args) = @_;
|
115
|
0
|
|
|
|
|
0
|
foreach (keys %{$hash})
|
|
0
|
|
|
|
|
0
|
|
116
|
|
|
|
|
|
|
{
|
117
|
0
|
|
|
|
|
0
|
$self->set($_, $hash->{$_});
|
118
|
|
|
|
|
|
|
}
|
119
|
0
|
|
|
|
|
0
|
return $self;
|
120
|
|
|
|
|
|
|
}
|
121
|
|
|
|
|
|
|
sub to_hash
|
122
|
|
|
|
|
|
|
{
|
123
|
2
|
|
|
2
|
0
|
5
|
my ($self, $args) = @_;
|
124
|
2
|
|
|
|
|
4
|
my $hash = {};
|
125
|
2
|
50
|
|
|
|
10
|
unless (defined $args->{'fields'})
|
126
|
|
|
|
|
|
|
{
|
127
|
2
|
|
|
|
|
6
|
$args->{'fields'} = [];
|
128
|
2
|
|
|
|
|
4
|
push (@{$args->{'fields'}} , $_) foreach keys %{ $self } ;
|
|
2
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
12
|
|
129
|
|
|
|
|
|
|
}
|
130
|
2
|
|
|
|
|
6
|
$hash->{$_} = $self->get($_) foreach @{$args->{'fields'}};
|
|
2
|
|
|
|
|
18
|
|
131
|
2
|
|
|
|
|
13
|
return $hash;
|
132
|
|
|
|
|
|
|
}
|
133
|
|
|
|
|
|
|
sub to_string # should we ditch this?
|
134
|
|
|
|
|
|
|
{
|
135
|
1
|
|
|
1
|
0
|
2
|
my ($self, $args) = @_;
|
136
|
|
|
|
|
|
|
my $opts = {
|
137
|
|
|
|
|
|
|
field_prefix => "",
|
138
|
|
|
|
|
|
|
field_suffix => "",
|
139
|
|
|
|
|
|
|
sense_prefix => "",
|
140
|
|
|
|
|
|
|
sense_suffix => "",
|
141
|
|
|
|
|
|
|
separator => "\t",
|
142
|
|
|
|
|
|
|
fields => [qw(hw pos def eg)],
|
143
|
4
|
100
|
|
4
|
|
17
|
field_escape => sub { return defined $_[0] ? $_[0] : ''; },
|
144
|
1
|
50
|
|
|
|
17
|
defined $args ? %$args : (),
|
145
|
|
|
|
|
|
|
};
|
146
|
|
|
|
|
|
|
|
147
|
4
|
|
|
|
|
7
|
my $s =
|
148
|
|
|
|
|
|
|
$opts->{'sense_prefix'} .
|
149
|
|
|
|
|
|
|
join ($opts->{'separator'}, map {
|
150
|
1
|
|
|
|
|
2
|
$opts->{'field_prefix'} .
|
151
|
4
|
|
|
|
|
9
|
&{$opts->{'field_escape'}}($self->get($_), $_) .
|
152
|
|
|
|
|
|
|
$opts->{'field_suffix'}
|
153
|
1
|
|
|
|
|
4
|
} @{$opts->{'fields'}})
|
154
|
|
|
|
|
|
|
. $opts->{'sense_suffix'}
|
155
|
|
|
|
|
|
|
;
|
156
|
1
|
|
|
|
|
7
|
return $s;
|
157
|
|
|
|
|
|
|
}
|
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub AUTOLOAD
|
160
|
|
|
|
|
|
|
{
|
161
|
100
|
|
|
100
|
|
233
|
my $self = shift;
|
162
|
100
|
50
|
|
|
|
255
|
return if ($AUTOLOAD =~ /DESTROY/);
|
163
|
100
|
100
|
66
|
|
|
587
|
if ( ($AUTOLOAD =~ /.*::set_(\w+)/) and (@_) )
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
164
|
|
|
|
|
|
|
{
|
165
|
37
|
|
|
|
|
154
|
return $self->{$1} = shift;
|
166
|
|
|
|
|
|
|
}
|
167
|
|
|
|
|
|
|
elsif ($AUTOLOAD =~ /.*::get_(\w+)/)
|
168
|
|
|
|
|
|
|
{
|
169
|
63
|
|
|
|
|
271
|
return $self->{$1};
|
170
|
|
|
|
|
|
|
}
|
171
|
|
|
|
|
|
|
elsif ($AUTOLOAD =~ /.*::has_(\w+)/)
|
172
|
|
|
|
|
|
|
{
|
173
|
0
|
|
|
|
|
|
return defined $self->{$1};
|
174
|
|
|
|
|
|
|
}
|
175
|
|
|
|
|
|
|
}
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
1;
|