-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_randomstrings.pl
64 lines (46 loc) · 1.23 KB
/
make_randomstrings.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
use warnings;
use utf8;
$keyfile = "/vol/tensusers/ihendrickx/Data/LSA/R_Sonar/SonarNews_20K_exp/sonar_minfr15_wordllist";
#lees het lexicon in, en bewaar het in de hash %woorden.
%woorden=();
$lexteller=0;
open(SFILE,"<:encoding(UTF-8)", $keyfile);
while(<SFILE>){
$line =$_;
chomp $line;
if($line =~ /(.*)\b/){
$lexteller++;
$woorden{$lexteller}=$1;
#print "($1)\n";
}}
close(SFILE);
print "Read $lexteller words\n";
$indir= "/vol/tensusers/ihendrickx/Data/LSA/R_Sonar/SonarNews_20K_exp/vocab_minfr15/wantQP/";
$outpath= "/vol/tensusers/ihendrickx/Data/LSA/R_Sonar/SonarNews_20K_exp/random_minfr15/want_rand";
opendir(my $dh, $indir) || die;
while($dir = readdir $dh)
{
if($dir =~ /\w\w/){
system("mkdir $outpath/$dir");
@files = glob("$indir/$dir/*QP*");
foreach $file (@files)
{
if(-e $file && ! -z $file){
$count = `wc -w < $file`;# die "wc failed: $?" if $?;
chomp($count);
print "$count $file\n";
if($file =~ /.*\/(.*QP.*)/ )
{
$filename=$1;
open(OUT,">:encoding(UTF-8)","$outpath/$dir/$filename");
for $i (1 .. $count)
{
$num = int(rand($lexteller));
print OUT "$woorden{$num} ";
}
close(OUT);
}
}}
}
}
closedir $dh;