File Coverage

blib/lib/Lingua/YaTeA/TermCandidate.pm
Criterion Covered Total %
statement 108 135 80.0
branch 6 8 75.0
condition n/a
subroutine 26 35 74.2
pod 29 33 87.8
total 169 211 80.0


line stmt bran cond sub pod time code
1             package Lingua::YaTeA::TermCandidate;
2 5     5   25 use strict;
  5         10  
  5         112  
3 5     5   20 use warnings;
  5         9  
  5         6329  
4             # use UNIVERSAL;
5             # use Scalar::Util qw(blessed);
6              
7             our $id = 0;
8             our $VERSION=$Lingua::YaTeA::VERSION;
9              
10             sub new
11             {
12 306     306 1 395 my ($class) = @_;
13 306         335 my $this;
14 306         668 $this->{ID} = $id++;
15 306         450 $this->{KEY} = "";
16 306         444 $this->{HEAD} = ();
17 306         430 $this->{WORDS} = [];
18 306         469 $this->{OCCURRENCES} = [];
19 306         408 $this->{RELIABILITY} = ();
20 306         411 $this->{TERM_STATUS} = 1;
21 306         547 $this->{ORIGINAL_PHRASE} = ();
22             # $this->{WEIGHT} = 0;
23 306         492 $this->{WEIGHTS} = {};
24 306         463 $this->{ROOT} = ();
25 306         399 $this->{MNP_STATUS} = 0; # added by SA 13/02/2009
26 306         410 bless ($this,$class);
27 306         562 return $this;
28             }
29              
30             sub setROOT {
31 301     301 0 415 my ($this, $ROOT) = @_;
32 301         329 push @{$this->{ROOT}}, $ROOT;
  301         507  
33 301         522 return($this->{ROOT});
34             }
35              
36             sub getROOT {
37 0     0 0 0 my ($this) = @_;
38 0         0 return($this->{ROOT});
39             }
40              
41             sub setTermStatus {
42 0     0 1 0 my ($this, $status) = @_;
43 0         0 $this->{TERM_STATUS} = $status;
44 0         0 return($this->{TERM_STATUS});
45             }
46              
47             sub getTermStatus {
48 0     0 1 0 my ($this) = @_;
49 0         0 return($this->{TERM_STATUS});
50             }
51              
52             sub isTerm {
53 0     0 1 0 my ($this) = @_;
54              
55 0         0 return($this->getTermStatus != 0);
56             }
57              
58             sub getLength
59             {
60 1210     1210 1 1470 my ($this) = @_;
61 1210         1202 return scalar @{$this->getWords};
  1210         1457  
62             }
63              
64             sub addWord
65             {
66 408     408 1 599 my ($this,$leaf,$words_a) = @_;
67 408         456 push @{$this->{WORDS}}, $words_a->[$leaf->getIndex];
  408         742  
68             }
69              
70             sub addOccurrence
71             {
72 320     320 1 429 my ($this,$occurrence) = @_;
73 320 100       548 if($occurrence->isMaximal)
74             {
75 1         2 $this->{MNP_STATUS} = 1; # added by SA 13/02/2009:: if at least one occurrence is a MNP, TC is a MNP
76             }
77 320         406 push @{$this->{OCCURRENCES}}, $occurrence;
  320         842  
78             }
79              
80             sub addOccurrences
81             {
82 66     66 1 98 my ($this,$occurrences_a) = @_;
83 66         90 my $occurrence;
84 66         94 foreach $occurrence (@$occurrences_a)
85             {
86 68         95 $this->addOccurrence($occurrence);
87             }
88             }
89              
90             sub getKey
91             {
92 1140     1140 1 1454 my ($this) = @_;
93 1140         2955 return $this->{KEY};
94             }
95              
96             sub getID
97             {
98 2303     2303 1 2825 my ($this) = @_;
99 2303         4384 return $this->{ID};
100             }
101              
102             sub getMNPStatus
103             {
104 240     240 1 319 my ($this) = @_;
105 240         645 return $this->{MNP_STATUS};
106             }
107              
108             sub editKey
109             {
110 692     692 1 969 my ($this,$string) = @_;
111 692         1407 $this->{KEY} .= $string;
112             }
113              
114             sub setHead
115             {
116 240     240 1 292 my ($this) = @_;
117 240         440 $this->{HEAD} = $this->searchHead(0);
118             }
119              
120             sub getHead
121             {
122 352     352 1 464 my ($this) = @_;
123 352         582 return $this->{HEAD};
124             }
125              
126             sub setWeight
127             {
128 240     240 1 265 my $this = shift;
129 240         255 my $weight;
130             my $weight_name;
131 240 50       297 if (scalar(@_) == 2) {
132 0         0 $weight_name = shift;
133             } else {
134             # default weight because it's the first
135 240         266 $weight_name = "DDW";
136             }
137 240         260 $weight = shift;
138 240         302 $this->getWeights->{$weight_name} = $weight;
139              
140             # $this->{WEIGHT} = $weight;
141             }
142              
143             sub getWeight
144             {
145 1324     1324 1 1518 my $this = shift;
146              
147 1324         1341 my $weight_name;
148 1324 50       1739 if (@_) {
149 1324         1477 $weight_name = shift;
150             } else {
151             # default wieght because it's the first
152 0         0 $weight_name = "DDW";
153             }
154 1324         1636 return($this->getWeights->{$weight_name});
155              
156             # return $this->{WEIGHT};
157             }
158              
159             sub setWeights
160             {
161 0     0 1 0 my ($this,$weight) = @_;
162 0         0 $this->{WEIGHTS} = $weight;
163             }
164              
165             sub getWeights
166             {
167 1566     1566 1 1937 my ($this) = @_;
168 1566         3500 return($this->{WEIGHTS});
169             }
170              
171             sub getWeightNames
172             {
173 240     240 1 337 my ($this) = @_;
174 240         291 return(keys %{$this->{WEIGHTS}});
  240         828  
175             }
176              
177             sub getWords
178             {
179 1893     1893 1 2219 my ($this) = @_;
180 1893         3295 return $this->{WORDS};
181             }
182              
183             sub getWord
184             {
185 0     0 0 0 my ($this,$index) = @_;
186 0         0 return $this->getWords->[$index];
187             }
188              
189             sub getOccurrences
190             {
191 2976     2976 1 3479 my ($this) = @_;
192 2976         5613 return $this->{OCCURRENCES};
193             }
194              
195             sub getOccurrencesNumber
196             {
197 0     0 0 0 my ($this) = @_;
198 0         0 return scalar @{$this->getOccurrences};
  0         0  
199             }
200              
201             sub buildLinguisticInfos
202             {
203 240     240 1 365 my ($this,$tagset) = @_;
204 240         524 my $if;
205             my $pos;
206 240         0 my $lf;
207 240         0 my $word;
208            
209 240         283 foreach $word (@{$this->getWords})
  240         365  
210             {
211 489         903 $if .= $word->getIF . " " ;
212 489 100       832 if ($tagset->existTag('PREPOSITIONS',$word->getIF))
213             {
214 45         72 $pos .= $word->getLF . " ";
215             }
216             else
217             {
218 444         724 $pos .= $word->getPOS . " ";
219             }
220 489         897 $lf .= $word->getLF . " " ;
221             }
222 240         1178 $if =~ s/\s+$//;
223 240         679 $pos =~ s/\s+$//;
224 240         668 $lf =~ s/\s+$//;
225 240         743 return ($if,$pos,$lf);
226              
227             }
228              
229             sub getIF
230             {
231 123     123 1 165 my ($this) = @_;
232 123         137 my $word;
233             my $if;
234 123         132 foreach $word (@{$this->getWords})
  123         177  
235             {
236 386         641 $if .= $word->getIF . " " ;
237             }
238 123         528 $if =~ s/\s+$//;
239 123         328 return $if;
240             }
241              
242             sub getLF
243             {
244 112     112 1 150 my ($this) = @_;
245 112         127 my $word;
246             my $lf;
247 112         129 foreach $word (@{$this->getWords})
  112         156  
248             {
249 361         548 $lf .= $word->getLF . " " ;
250             }
251 112         383 $lf =~ s/\s+$//;
252 112         275 return $lf;
253             }
254              
255             sub getPOS
256             {
257 0     0 1 0 my ($this) = @_;
258 0         0 my $word;
259             my $pos;
260 0         0 foreach $word (@{$this->getWords})
  0         0  
261             {
262 0         0 $pos .= $word->getPOS . " " ;
263             }
264 0         0 $pos =~ s/\s+$//;
265 0         0 return $pos;
266             }
267              
268             sub getFrequency
269             {
270 2312     2312 1 2704 my ($this) = @_;
271 2312         2501 return scalar @{$this->getOccurrences};
  2312         2887  
272             }
273              
274             sub setReliability
275             {
276 240     240 1 360 my ($this,$reliability) = @_;
277 240         371 $this->{RELIABILITY} = $reliability;
278             }
279              
280             sub getReliability
281             {
282 240     240 1 312 my ($this) = @_;
283 240         1073 return $this->{RELIABILITY};
284             }
285              
286             sub getOriginalPhrase
287             {
288 0     0 1   my ($this) = @_;
289 0           return $this->{ORIGINAL_PHRASE};
290             }
291              
292              
293              
294             1;
295              
296             __END__