-
Notifications
You must be signed in to change notification settings - Fork 0
/
conflateTargets.pl
executable file
·67 lines (60 loc) · 1.58 KB
/
conflateTargets.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl -ws
#####################
#
# ©2013 Autodesk Development Sàrl
#
# Created on 21 Jun 2013 by Ventsislav Zhechev
#
# Changelog
# v0.1 Modified by Ventsislav Zhechev on 21 Jun 2013
# First version.
#
#####################
use strict;
use utf8;
use Encode qw/encode decode/;
my $oldSource = my $oldTarget = my $oldProduct = "";
my $cumulateP3 = my $cumulateP4 = 0;
my %targets;
while (<>) {
chomp;
my ($source, $target, $data) = split / \|\|\| /, decode "utf-8", $_;
my (undef, undef, $prob3, $prob4, undef, $product) = split / \| /, $data;
if ($source ne $oldSource || $product ne $oldProduct) {
if ($oldTarget ne "") {
if (defined $targets{$oldTarget}) {
$targets{$oldTarget}->[0] += $cumulateP3;
$targets{$oldTarget}->[1] += $cumulateP4;
} else {
$targets{$oldTarget} = [$cumulateP3, $cumulateP4];
}
}
if ($oldSource ne "" && $oldProduct ne "") {
foreach my $target (sort {$a cmp $b} keys %targets) {
print encode "utf-8", "$oldSource | $target | ".join(" | ", @{$targets{$target}})." | $oldProduct\n";
}
}
$cumulateP3 = $prob3;
$cumulateP4 = $prob4;
$oldSource = $source;
$oldTarget = $target;
$oldProduct = $product;
%targets = ();
} elsif ($target ne $oldTarget) {
if ($oldTarget ne "") {
if (defined $targets{$oldTarget}) {
$targets{$oldTarget}->[0] += $cumulateP3;
$targets{$oldTarget}->[1] += $cumulateP4;
} else {
$targets{$oldTarget} = [$cumulateP3, $cumulateP4];
}
}
$cumulateP3 = $prob3;
$cumulateP4 = $prob4;
$oldTarget = $target;
} else {
$cumulateP3 += $prob3;
$cumulateP4 += $prob4;
}
}
1;