Lemur/Result.pm

filter: Statementstmt 77.5% 31 / 40 Branchbran 70.0% 7 / 10 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 55.5% 5 / 9 Podpod 100% 5 / 5 totaltotal 68.4% 50 / 73 CC 8 SCAR 14.5
CC
8
Cov
71%
equals
7.6
_new
2.0
ctf
2.0
CRAP 4.3
« Lemur.pm ↑ Summary Lemur/ResultItem.pm »
1 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Search::Lemur::Result;
5  
6  
7 =head1 NAME
8  
9 Lemur::Result
10  
11 =head1 VERSION
12  
13 Version 1.0
14  
15 =cut
16  
17 6 our $VERSION = '1.00';
18  
19  
20 =head1 DESCRIPTION
21  
22 Stores the results from a lemur query for a single term.
23
24 =cut
25  
26 =head2 Main Methods
27  
28 =over 2
29 =cut
30  
31 # create a new result object. This should only be called by a
32 # Lemur object, in its query method. One of these will be created
33 # for every result returned by the query.
34 #
35 # The arguments are query term, the document ID, document length,
36 # and term frequency.
37 #
38 # If these arguments are not given, this will return undef
39 8 ▶sub _new {
Subroutine _new: called CC=2 SCAR=7.1
40 8 my $class = shift;
41 8 my $self = {};
42 8 ▶ if (scalar(@_) >= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ >= 3) { } 8 0 8
43 8 my ($term, $ctf, $df) = @_;
44 8 $self = { term => $term,
45 ctf => $ctf,
46 df => $df,
47 lines => [] };
48 0 } else { return undef; }
49 8 bless $self, $class;
50 8 return $self;
51 }
52  
53 =item ctf
54  
55 Get the corpus term frequency for this result.
56  
57 =cut
58  
59 0 ▶sub ctf {
Subroutine ctf: not called CC=1 SCAR=6.9
Pod documented
60 0 my $self = shift;
61 0 return $self->{ctf};
62 }
63  
64  
65 =item term
66  
67 Get the query term for this result.
68  
69 Returns the number of times this term occured in the corpus.
70  
71 =cut
72  
73 0 ▶sub term {
Subroutine term: not called CC=1 SCAR=6.9
Pod documented
74 0 my $self = shift;
75 0 return $self->{term};
76 }
77  
78 =item df
79  
80 Get the document frequency for this result.
81  
82 Returns the number of documents this term occurred in.
83  
84 =cut
85  
86 0 ▶sub df {
Subroutine df: not called CC=1 SCAR=6.9
Pod documented
87 0 my $self = shift;
88 0 return $self->{df};
89 }
90  
91  
92 =item docs
93  
94 Get the array of documents returned by this query.
95  
96 Returns an array of resultItem objects.
97  
98 =cut
99  
100 0 ▶sub docs {
Subroutine docs: not called CC=1 SCAR=6.9
Pod documented
101 0 my $self = shift;
102 0 return $self->{lines};
103 }
104  
105 # _add(resultItem)
106 #
107 # add a resultItem to the list
108 #
109 # This should only be called by Lemur objects' _parse method when
110 # populating the result
111 8 ▶sub _add {
Subroutine _add: called CC=1 SCAR=0.0
112 8 my $self = shift;
113 8 my $line = shift;
114 8 push @{$self->{lines}}, $line;
115 }
116  
117 =item equals
118  
119 Test equality between this result and the given one (used mostly for
120 testing).
121  
122 =cut
123  
124  
125 5 ▶sub equals {
Subroutine equals: called CC=7 SCAR=20.3
Pod documented
126 5 my $self = shift;
127 5 my $other = shift;
128 5 ▶ return 0 unless ($other->isa('Search::Lemur::Result'));
Branch: 1 branch
BranchTrueFalseTotal
unless $other->isa("Search::Lemur::Result") 0 5 5
129 5 my $numlines = scalar(@{$self->{lines}});
130 5 ▶ return 0 unless ($numlines == @{$other->{lines}});
Branch: 1 branch
BranchTrueFalseTotal
unless $numlines == @{$other->{"lines"};} 1 4 5
131 # check that the resultItems are all the same (order matters)
132 4 ▶ for (my $i = 0; $i < $numlines; $i++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $numlines) 4 4 8
133 4 return 0 unless (${$self->{lines}}[$i]->equals(
134 4 ▶ ${$self->{lines}}[$i]));
Branch: 1 branch
BranchTrueFalseTotal
unless do { $$self{"lines"} }->[$i]->equals(do { $$self{"lines"} }->[$i]) 0 4 4
135 }
136 return ($self->{term} eq $other->{term}) &&
137 ($self->{ctf} == $other->{ctf}) &&
138 4 ▶ ($self->{df} == $other->{df});
Condition33%2/6
$self->{'term'} eq $other->{'term'} && $self->{'ctf'} == $other->{'ctf'} && $self->{'df'} == $other->{'df'}
!ll&&!rl&&r
004
$self->{"term"} eq $other->{"term"} and $self->{"ctf"} == $other->{"ctf"}
!ll&&!rl&&r
004
MC/DC0%0/3
$self->{'term'} eq $other->{'term'} && $self->{'ctf'} == $other->{'ctf'} && $self->{'df'} == $other->{'df'}
$self->{"term"} eq $other->{"term"} $self->{"ctf"} == $other->{"ctf"} $self->{'df'} == $other->{'df'}
Truth table25%1/4
A and B && C
A= $self->{"term"} eq $other->{"term"}B= $self->{"ctf"} == $other->{"ctf"}C= $self->{'df'} == $other->{'df'}
ABCresult
0XX0
10X0
1100
1111
139 }
140
141  
142 =back
143  
144 =head1 AUTHOR
145  
146 Patrick Kaeding, C<< <pkaeding at cpan.org> >>
147  
148 =head1 BUGS
149  
150 Please report any bugs or feature requests to
151 C<bug-search-lemur at rt.cpan.org>, or through the web interface at
152 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Search-Lemur>.
153 I will be notified, and then you'll automatically be notified of progress on
154 your bug as I make changes.
155  
156 =head1 SUPPORT
157  
158 You can find documentation for this module with the perldoc command.
159  
160 perldoc Search::Lemur
161  
162 You can also look for information at:
163  
164 =over 4
165  
166 =item * AnnoCPAN: Annotated CPAN documentation
167  
168 L<http://annocpan.org/dist/Search-Lemur>
169  
170 =item * CPAN Ratings
171  
172 L<http://cpanratings.perl.org/d/Search-Lemur>
173  
174 =item * RT: CPAN's request tracker
175  
176 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Search-Lemur>
177  
178 =item * Search CPAN
179  
180 L<http://search.cpan.org/dist/Search-Lemur>
181  
182 =back
183  
184 =head1 ACKNOWLEDGEMENTS
185  
186 =head1 COPYRIGHT & LICENSE
187  
188 Copyright 2007 Patrick Kaeding, all rights reserved.
189  
190 This program is free software; you can redistribute it and/or modify it
191 under the same terms as Perl itself.
192  
193 =cut
194  
195 6 1;
« Lemur.pm ↑ Summary Lemur/ResultItem.pm »