File Coverage

blib/lib/Wordnet/SenseSearch.pm
Criterion Covered Total %
statement 18 37 48.6
branch 1 6 16.6
condition 1 3 33.3
subroutine 5 6 83.3
pod 0 2 0.0
total 25 54 46.3


line stmt bran cond sub pod time code
1             package Wordnet::SenseSearch;
2              
3 1     1   53045 use 5.008008;
  1         4  
  1         40  
4 1     1   6 use strict;
  1         2  
  1         36  
5 1     1   5 use warnings;
  1         7  
  1         39  
6 1     1   1026 use Search::Dict;
  1         1284  
  1         614  
7              
8             our $VERSION = '0.02';
9             our $WNDICT = '/usr/local/WordNet-2.1/dict/';
10              
11             our @DATAFILES = qw(data.noun data.verb data.adj data.adv data.adj);
12              
13             sub new {
14 1     1 0 12 my $self = {};
15 1         2 my $class = shift;
16 1         3 bless $self, $class;
17 1         5 my %params = @_;
18 1   33     10 $self->{_dictdir} = $params{dir} || $WNDICT;
19 1 50       361 open $self->{_senseidx_fh}, $self->{_dictdir} . "/index.sense" or die $!;
20 0           return $self;
21             }
22              
23             # takes a sense key (i.e. "animal%1:03:00::") and returns some of the
24             # synset data
25             sub lookup {
26 0     0 0   my $self = shift;
27 0           my $key = shift;
28 0 0         return unless $key;
29 0           my $fh = $self->{_senseidx_fh};
30 0           look $fh, $key;
31 0           my $line = <$fh>;
32 0           my ($lemma,$sstype,$lexfile,$lexid,$headword,$headid,$offset,$sensenum,
33             $tagcnt) =
34             $line =~ m|^(\S+?)%(\d):(\d\d):(\d\d):(\S+?)*:
35             (\d\d)*\s+(\d+)\s(\d+)\s(\d+)\s*$|x;
36 0 0         open DATA, $self->{_dictdir} . "/" . $DATAFILES[$sstype-1] or die $!;
37 0           seek DATA, $offset, 0;
38 0           my $entry = ;
39 0           close DATA;
40 0           $entry =~ m|^(\d+)\s(\d\d)\s(\w)\s([\dA-Fa-f]+)\s|g;
41 0           my ($pos,$wcnt) = ($3,hex($4)); # can't do inline assignment with /g
42 0           my @words;
43 0           for (1 .. $wcnt) {
44 0           push @words, $entry =~ m|\G(\S+?)\s[\dA-Fa-f]\s|g;
45             }
46 0           my ($gloss) = $entry =~ m/\|\s*(.+?)\s*$/;
47 0           return (words => \@words, pos => $pos, lexfile => $lexfile,
48             sensenum => $sensenum, gloss => $gloss);
49             }
50              
51             1;
52             __END__