File Coverage

blib/lib/WordNet/Similarity/Visual/QueryDataInterface.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package WordNet::Similarity::Visual::QueryDataInterface;
2              
3             =head1 NAME
4              
5             WordNet::Similarity::Visual::QueryDataInterface
6              
7             =head1 SYNOPSIS
8              
9             =head2 Basic Usage Example
10              
11             use WordNet::Similarity::Visual::QueryDataInterface;
12              
13             my $wn = WordNet::Similarity::Visual::QueryDataInterface->new;
14              
15             $wn->initialize;
16              
17             my ($result) = $wn->find_allsenses($word);
18              
19             =head1 DESCRIPTION
20              
21             This package provides an interface to WordNet::QueryData.
22              
23             =head2 Methods
24              
25             The following methods are defined in this package:
26              
27             =head3 Public methods
28              
29             =over
30              
31             =cut
32              
33 1     1   18 use 5.008004;
  1         3  
  1         42  
34 1     1   11 use strict;
  1         2  
  1         48  
35 1     1   4 use warnings;
  1         2  
  1         44  
36 1     1   516 use Gtk2 '-init';
  0            
  0            
37             use WordNet::QueryData;
38             our $VERSION = '0.07';
39             use constant TRUE => 1;
40             use constant FALSE => 0;
41             my $wn;
42              
43             =item $obj->new
44              
45             The constructor for WordNet::Similarity::Visual::QueryDataInterface objects.
46              
47             Return value: the new blessed object
48              
49             =cut
50              
51             sub new
52             {
53             my ($class) = @_;
54             my $self = {};
55             bless $self, $class;
56             }
57              
58             =item $obj->initialize
59              
60             To initialize WordNet::QueryData.
61              
62             Return Value: None
63              
64             =cut
65              
66             sub initialize
67             {
68             my ($self) = @_;
69             $self->{ wn }=WordNet::QueryData->new;
70             }
71              
72              
73              
74              
75             =item $obj->search_glosses
76              
77             Parameter: The word(String) for which we are searching the glosses.
78              
79             Return value: A hash with all the glosses for all the senses of the word.
80              
81             =cut
82              
83             sub search_senses
84             {
85             my ($self, $word) = @_;
86             my $count=0;
87             my @wordglos=();
88             if (length $word != 0 )
89             {
90             $word=lc $word;
91             my @temp = split '#',$word;
92             my $wordlevel = $#temp+1;
93             my @allsenses = ();
94             my $sense;
95             my %allres;
96             if ($wordlevel == 3)
97             {
98             @wordglos = $self->{ wn }->querySense($word, "glos");
99             $allres{$word} = $wordglos[0];
100             $count++;
101             }
102             elsif ($wordlevel == 2)
103             {
104             my @senses = $self->{ wn }->queryWord($word);
105             my @wordglos;
106             my $glos;
107             my $wordsense;
108             foreach $wordsense (@senses)
109             {
110             while (Gtk2->events_pending)
111             {
112             Gtk2->main_iteration;
113             }
114             @wordglos = $self->{ wn }->querySense($wordsense,"glos");
115             $allres{$wordsense}=$wordglos[0];
116             $count++;
117             }
118             }
119             else
120             {
121             my @wordpos= ();
122             @wordpos=$self->{ wn }->queryWord($word);
123             my $pos;
124             my $wordsense;
125             my @senses = ();
126             my $glos;
127             my @wordglos;
128             foreach $pos (@wordpos)
129             {
130             while (Gtk2->events_pending)
131             {
132             Gtk2->main_iteration;
133             }
134             @senses = $self->{ wn }->queryWord($pos);
135             foreach $wordsense (@senses)
136             {
137             while (Gtk2->events_pending)
138             {
139             Gtk2->main_iteration;
140             }
141             @wordglos = $self->{ wn }->querySense($wordsense,"glos");
142             $allres{$wordsense}=$wordglos[0];
143             $count++;
144             }
145             }
146             }
147             if ($count > 0)
148             {
149             return \%allres;
150             }
151             else
152             {
153             return -1;
154             }
155             }
156             }
157              
158             =item $obj->find_allsenses
159              
160             Parameter: The word(String) for which we are searching the senses.
161              
162             Return value: A array of all the senses of this word found in WordNet.
163              
164             =cut
165              
166             sub find_allsenses
167             {
168             my ($self, $word)=@_;
169             my @temp = split '#',$word;
170             my $wordlevel = $#temp+1;
171             my $pos;
172             my @wordsenses = ();
173             my @wordsense;
174             if($wordlevel==1)
175             {
176             @temp=$self->{ wn }->queryWord($word);
177             foreach $pos (@temp)
178             {
179             @wordsense=$self->{ wn }->queryWord($pos);
180             push (@wordsenses, @wordsense);
181             @wordsense = ();
182             }
183             }
184             elsif($wordlevel==2)
185             {
186             @wordsenses = $self->{ wn }->queryWord($word);
187             }
188             else
189             {
190             $wordsenses[0]=$word
191             }
192             return @wordsenses;
193             }
194              
195              
196              
197             =item $obj->find_allsyns
198              
199             Parameter: The word(String) for which we are searching the synonyms.
200              
201             Return value: A array of all the senses of this word found in WordNet.
202              
203             =cut
204              
205             sub find_allsyns
206             {
207             my ($self, $word)=@_;
208             my @syns1 = $self->{ wn }->querySense($word,"syns");
209             return @syns1;
210             }
211              
212             1;
213             __END__