line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# PODNAME: Textoola::PatternStatComparator |
2
|
|
|
|
|
|
|
# ABSTRACT: Class to compare 2 counting-hashes with pattern-tokenlines and return the rate of change. |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
23379
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
6
|
1
|
|
|
1
|
|
8
|
use v5.14; |
|
1
|
|
|
|
|
4
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Textoola::PatternStatComparator; |
9
|
|
|
|
|
|
|
$Textoola::PatternStatComparator::VERSION = '0.003'; |
10
|
|
|
|
|
|
|
sub new { |
11
|
2
|
|
|
2
|
0
|
1673
|
my $class = shift; |
12
|
2
|
|
|
|
|
13
|
my %args = @_; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $self={ |
15
|
|
|
|
|
|
|
patternstats1 => $args{patternstats1}, |
16
|
|
|
|
|
|
|
patternstats2 => $args{patternstats2}, |
17
|
2
|
|
50
|
|
|
14
|
threshhold => $args{threshhold} || 0.05, # 5% |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
|
|
3
|
bless $self, $class; |
21
|
2
|
|
|
|
|
4
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub compare { |
25
|
2
|
|
|
2
|
0
|
5
|
my $self = shift; |
26
|
2
|
|
|
|
|
6
|
my $patstats1 = $self->{patternstats1}; |
27
|
2
|
|
|
|
|
2
|
my %patstats2 = %{$self->{patternstats2}}; |
|
2
|
|
|
|
|
8
|
|
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
3
|
my $threshhold = $self->{threshhold}; |
30
|
2
|
|
|
|
|
2
|
my $upperlimit = $threshhold; |
31
|
2
|
|
|
|
|
2
|
my $lowerlimit = -$threshhold; |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
1
|
my %result; |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
5
|
for my $pat (keys %$patstats1) { |
36
|
11
|
50
|
|
|
|
13
|
if (exists $patstats2{$pat}) { |
37
|
11
|
|
|
|
|
9
|
my $base = $patstats1->{$pat}; |
38
|
11
|
|
|
|
|
7
|
my $new = $patstats2{$pat}; |
39
|
11
|
|
|
|
|
12
|
my $change = ($new - $base) / $base; |
40
|
11
|
100
|
|
|
|
19
|
if ($change <= $lowerlimit) { |
|
|
100
|
|
|
|
|
|
41
|
3
|
|
|
|
|
10
|
$result{$pat} = $change; |
42
|
|
|
|
|
|
|
} elsif ($change >= $upperlimit) { |
43
|
3
|
|
|
|
|
1
|
$result{$pat} = $change; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
11
|
|
|
|
|
14
|
delete $patstats2{$pat}; |
47
|
|
|
|
|
|
|
} else { |
48
|
|
|
|
|
|
|
# only on left side |
49
|
0
|
|
|
|
|
0
|
$result{$pat} = -1; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
# for the rest of right side had an indefinite change |
53
|
2
|
|
|
|
|
3
|
for my $pat (keys %patstats2) { |
54
|
2
|
|
|
|
|
3
|
$result{$pat} = '*'; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
2
|
50
|
|
|
|
7
|
return wantarray ? %result : \%result; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub compare_reduce { |
61
|
1
|
|
|
1
|
0
|
4
|
my $self = shift; |
62
|
1
|
|
|
|
|
4
|
my $result = $self->compare(@_); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# reduce partial patterns with same change-rate |
65
|
1
|
|
|
|
|
60
|
my @patterns = sort keys %$result; |
66
|
1
|
|
|
|
|
4
|
while (scalar(@patterns)-1) { |
67
|
2
|
|
|
|
|
3
|
my $cur_pattern = shift @patterns; |
68
|
2
|
|
|
|
|
3
|
my $size = length($cur_pattern); |
69
|
2
|
|
|
|
|
3
|
my $next_pattern = substr($patterns[0],0,$size); |
70
|
|
|
|
|
|
|
|
71
|
2
|
50
|
|
|
|
6
|
if ($cur_pattern eq $next_pattern) { |
72
|
0
|
0
|
0
|
|
|
0
|
if (($result->{$cur_pattern} ne '*') and ($result->{$next_pattern} ne '*')) { |
|
|
0
|
0
|
|
|
|
|
73
|
0
|
0
|
|
|
|
0
|
if ($result->{$cur_pattern} == $result->{$next_pattern}) { |
74
|
0
|
|
|
|
|
0
|
delete $result->{$cur_pattern}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} elsif (($result->{$cur_pattern} eq '*') and ($result->{$next_pattern} eq '*')) { |
77
|
0
|
|
|
|
|
0
|
delete $result->{$cur_pattern}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
1
|
50
|
|
|
|
4
|
return wantarray ? %$result : $result; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |