-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcountInstancesPerLevel.pl
More file actions
executable file
·40 lines (31 loc) · 1.06 KB
/
countInstancesPerLevel.pl
File metadata and controls
executable file
·40 lines (31 loc) · 1.06 KB
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
#!/usr/bin/perl
use lib $ENV{TDTlite};
require "format.pl";
my $version = "v.2";
printVersionHeader("CountValuesPerLevel $version");
if ($help) { printHelp("CountValuesPerLevel"); }
elsif ($corpus eq "" || $factor_name eq "") { printAbort(); }
else {
%cases = parseFactorHash();
for ($i=0; $i <= $#factornames; $i++) {
# ID of variable in the output file (i.e. column)
my $fid = getFactorID($factornames[$i], %cases);
my $newfactor_name = "LevelCount_".$factornames[$i];
%cases = createFactor($newfactor_name, %cases);
my $new_fid = getFactorID($newfactor_name, %cases);
my %newvalue;
foreach $id (sort keys %cases) {
next if ($id eq getHeaderID());
$newvalue{$cases{$id}[$fid]}++;
}
foreach $id (sort keys %cases) {
next if ($id eq getHeaderID());
$cases{$id}[$new_fid] = $newvalue{$cases{$id}[$fid]};
}
@k = keys %newvalue;
$levels = $#k + 1;
print "\nCounted $levels distinct levels for variable ".$factornames[$i].".\n";
}
writeFactorHash(%cases);
}
printFooter();