blib/lib/Lingua/Ogmios/LearningDataSet/Data.pm

filter: Statementstmt 81.2% 95 / 117 Branchbran 70.9% 44 / 62 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 87.5% 14 / 16 Podpod 0.0% 0 / 14 totaltotal 71.1% 155 / 218 CC 34 SCAR 19.2
CC
34
Cov
76%
getSVM
16.5
getARFF
8.1
weight
6.0
CRAP 6.9
« blib/lib/Lingua/Ogmios/LearningDataSet.pm ↑ Summary blib/lib/Lingua/Ogmios/NLPWrappers/Template.pm »
1 package Lingua::Ogmios::LearningDataSet::Data;
2  
3  
4 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 8 our $VERSION='0.1';
8  
9 30 ▶sub new {
Subroutine new: called CC=4 SCAR=14.0
Pod undocumented
10  
11 30 my $class = shift;
12 30 my $fields = shift;
13  
14  
15 my $data = {
16 'values' => $fields->{values},
17 'type' => $fields->{type},
18 'weight' => $fields->{weight},
19 'countVal' => 0,
20 'class' => $fields->{class},
21 'comment' => $fields->{comment},
22 'qid' => $fields->{qid},
23 30 };
24  
25 30 bless($data, $class);
26  
27 30 ▶ if (!defined $data->type) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $data->type) 1 29 30
28 1 $data->type('normal');
29 }
30  
31 30 ▶ if (defined $data->values) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $data->values) { } 0 30 30
32 0 $data->countVal(scalar(@{$data->values}));
33 } else {
34 30 $data->{values} = [];
35 }
36  
37 30 ▶ if (defined $fields->{"countVal"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fields->{"countVal"}) 29 1 30
38 29 $data->countVal($fields->{"countVal"});
39 }
40  
41 30 return($data);
42 }
43  
44 0 ▶sub weight {
Subroutine weight: not called CC=2 SCAR=17.9
Pod undocumented
45 0 my $self = shift;
46  
47 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
48 0 $self->{'weight'} = shift;
49 }
50 0 return($self->{'weight'});
51 }
52  
53 33 ▶sub comment {
Subroutine comment: called CC=2 SCAR=7.6
Pod undocumented
54 33 my $self = shift;
55  
56 33 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 33 33
57 0 $self->{'comment'} = shift;
58 }
59 33 return($self->{'comment'});
60 }
61  
62 30 ▶sub qid {
Subroutine qid: called CC=2 SCAR=7.6
Pod undocumented
63 30 my $self = shift;
64  
65 30 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 30 30
66 0 $self->{'qid'} = shift;
67 }
68 30 return($self->{'qid'});
69 }
70  
71 124 ▶sub class {
Subroutine class: called CC=2 SCAR=6.9
Pod undocumented
72 124 my $self = shift;
73  
74 124 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 29 95 124
75 29 $self->{'class'} = shift;
76 }
77 124 return($self->{'class'});
78 }
79  
80 3 ▶sub isNormal {
Subroutine isNormal: called CC=2 SCAR=6.9
Pod undocumented
81 3 my ($self) = @_;
82  
83 3 ▶ if ($self->type eq "normal") {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type eq 'normal') { } 2 1 3
84 2 return(1);
85 } else {
86 1 return(0);
87 }
88 }
89  
90 455 ▶sub isSparse {
Subroutine isSparse: called CC=2 SCAR=6.9
Pod undocumented
91 455 my ($self) = @_;
92  
93 455 ▶ if ($self->type eq "sparse") {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->type eq 'sparse') { } 453 2 455
94 453 return(1);
95 } else {
96 2 return(0);
97 }
98 }
99  
100  
101 489 ▶sub type {
Subroutine type: called CC=2 SCAR=6.9
Pod undocumented
102 489 my $self = shift;
103  
104 489 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 488 489
105 1 $self->{'type'} = shift;
106 }
107 489 return($self->{'type'});
108 }
109  
110 1883 ▶sub countVal {
Subroutine countVal: called CC=2 SCAR=6.9
Pod undocumented
111 1883 my $self = shift;
112  
113 1883 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 31 1852 1883
114 31 $self->{'countVal'} = shift;
115 }
116 1883 return($self->{'countVal'});
117 }
118  
119 2724 ▶sub values {
Subroutine values: called CC=3 SCAR=11.0
Pod undocumented
120 2724 my $self = shift;
121  
122 2724 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 2722 2724
123 2 my $values_ref = shift;
124 2 push @{$self->{'values'}}, @$values_ref;
125 2 ▶ if (defined $self->values) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->values) 2 0 2
126 2 $self->countVal(scalar(@{$self->values}));
127 }
128  
129 }
130 2724 return($self->{'values'});
131 }
132  
133  
134  
135 0 ▶sub incr_value {
Subroutine incr_value: not called CC=2 SCAR=17.9
Pod undocumented
136 0 my $self = shift;
137 0 my $index = shift;
138  
139 0 ▶ if ($index >= $self->countVal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index >= $self->countVal) 0 0 0
140 0 warn "\nindex ($index) out of range (countVal=" . $self->countVal . " - a)\n";
141 }
142  
143 0 $self->values->[$index]++;
144 0 return($self->values->[$index]);
145 }
146  
147  
148 427 ▶sub value {
Subroutine value: called CC=3 SCAR=11.6
Pod undocumented
149 427 my $self = shift;
150 427 my $index = shift;
151  
152 427 ▶ if ($index >= $self->countVal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($index >= $self->countVal) 0 427 427
153 0 warn "\nindex ($index) out of range (countVal=" . $self->countVal . " - b)\n";
154 }
155  
156 427 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 427 0 427
157 427 $self->values->[$index] = shift;
158 }
159 427 return($self->values->[$index]);
160 }
161  
162  
163 3 ▶sub getARFF {
Subroutine getARFF: called CC=8 SCAR=20.9
Pod undocumented
164 3 my ($self) = @_;
165  
166 3 my $i;
167 3 my $arffString = "";
168  
169 3 ▶ if (defined $self->comment) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->comment) 0 3 3
170 0 $arffString .= "% " . $self->comment . "\n";
171 }
172  
173 3 ▶ if ($self->isNormal) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isNormal) 2 1 3
174 2 $arffString .= join(',',@{$self->values}) . ",";
175 2 ▶ if (defined $self->class) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->class) { } 1 1 2
176 1 $arffString .= $self->class;
177 } else {
178 1 $arffString .= "?"
179 }
180 }
181  
182 3 ▶ if ($self->isSparse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isSparse) 1 2 3
183 1 $arffString .= '{';
184 1 ▶ for($i=0;$i < $self->countVal;$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->countVal) 4 1 5
185 4 ▶ if (defined $self->values->[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->values->[$i]) 2 2 4
186 #warn $self->values->[$i] . "($i)\n";
187 2 $arffString .= "$i " . $self->values->[$i] . ", ";
188 }
189 }
190 1 $arffString .= $self->countVal . " ";
191 1 ▶ if (defined $self->class) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->class) { } 1 0 1
192 1 $arffString .= $self->class;
193 } else {
194 0 $arffString .= "?"
195 }
196 1 $arffString .= '}';
197 }
198  
199  
200 3 return($arffString);
201 }
202  
203 30 ▶sub getSVM {
Subroutine getSVM: called CC=11 SCAR=28.0
Pod undocumented
204 30 my $self = shift;
205 30 my $classes = shift;
206 30 my $printComments = shift;
207 30 my $svmString;
208 my $i;
209  
210 30 ▶ if (((!defined $printComments) || ($printComments == 1)) && (defined $self->comment)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!defined($printComments) || $printComments == 1 and defined $self->comment) 0 30 30
Condition33%2/6
!defined($printComments) || $printComments == 1 and defined $self->comment
!ll&&!rl&&r
0300
not defined $printComments or $printComments == 1
l!l&&r!l&&!r
3000
MC/DC0%0/3
!defined($printComments) || $printComments == 1 and defined $self->comment
not defined $printComments $printComments == 1 defined $self->comment
Truth table20%1/5
not(A) or B and C
A= not defined $printCommentsB= $printComments == 1C= defined $self->comment
ABCresult
00X0
1X00
0100
1X11
0111
211 0 $svmString = $self->comment . "\n";
212 }
213 30 ▶ if (defined $self->class) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->class) { } 29 1 30
214 # warn "====> " . $self->class . ";\n";
215 29 ▶ if (scalar(keys %$classes) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %$classes == 1) { } 0 29 29
216 0 ▶ if (exists $classes->{$self->class}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$classes{$self->class}) { } 0 0 0
217 0 $svmString .= "+1 ";
218 } else {
219 0 $svmString .= "-1 ";
220 }
221 } else {
222 # warn "==> $classes\n";
223 # for my $c (keys(%{$classes})) {
224 # warn "$c : " . $classes->{$c} . "\n";
225 # }
226 # warn $self->class . "\n";
227 29 ▶ if (exists $classes->{$self->class}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$classes{$self->class}) 29 0 29
228 29 $svmString .= $classes->{$self->class} . " ";
229 }
230 }
231 } else {
232 1 $svmString .= "0 ";
233 }
234 # warn "$svmString\n";
235 30 ▶ if (defined $self->qid) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->qid) 0 30 30
236 0 $svmString .= "qid:" . $self->qid . " ";
237 }
238  
239 30 ▶ for($i=0;$i < $self->countVal;$i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $self->countVal) 1389 30 1419
240 1389 ▶ if (defined $self->values->[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->values->[$i]) 435 954 1389
241 435 $svmString .= ($i+1) . ":" . $self->values->[$i] . " ";
242 }
243 }
244 30 return($svmString);
245 }
246  
247  
248 =head1 NAME
249  
250 Lingua::Ogmios::LearningDataSet::Data - Perl extension for managing the learning data
251  
252 =head1 SYNOPSIS
253  
254 use Lingua::Ogmios::LearningDataSet::Data;
255  
256 my %config = Lingua::Ogmios::LearningDataSet::Data::load_config($rcfile);
257  
258 $yatea = Lingua::Ogmios::LearningDataSet::Data->new($config{"OPTIONS"}, \%config);
259  
260 $yatea->termExtraction($corpus);
261  
262  
263 =head1 DESCRIPTION
264  
265  
266 =head1 METHODS
267  
268 =head2 function()
269  
270 function($rcfile);
271  
272 =head1 SEE ALSO
273  
274  
275 =head1 AUTHORS
276  
277 Thierry Hamon <thierry.hamon@limsi.fr>
278  
279 =head1 LICENSE
280  
281 Copyright (C) 2013 by Thierry Hamon
282  
283 This library is free software; you can redistribute it and/or modify
284 it under the same terms as Perl itself, either Perl version 5.8.6 or,
285 at your option, any later version of Perl 5 you may have available.
286  
287  
288 =cut
289  
290  
291 8 1;
« blib/lib/Lingua/Ogmios/LearningDataSet.pm ↑ Summary blib/lib/Lingua/Ogmios/NLPWrappers/Template.pm »