-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmakeTrainingFile.pl
More file actions
56 lines (51 loc) · 1.26 KB
/
makeTrainingFile.pl
File metadata and controls
56 lines (51 loc) · 1.26 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl
sub printUsage {
print "usage: perl makeTrainingFile.pl inputname outputname skipnum\n";
}
sub getLine {
$text = shift;
$step = shift;
$output = shift;
@sounds = split " ", $line;
print "$# sounds:";
for($i = 0; $i + $step < $#sounds ; $i++) {
print "$i\t";
@current = split "/", $sounds[$i];
@currentTones = split ",", $current[1];;
if ( $#currentTones > 0 ) {
push @currentTones, $current[1];
}
@next = split "/", $sounds[$i+1];
@nextTones = split "," , $next[1];
if ( $#nextTones > 0 ) {
push @nextTones, $next[1];
}
@predict = split "/", $sounds[$i+$step];
foreach $currentTone ( @currentTones) {
foreach $nextTone ( @nextTones ) {
print $output "$current[0]/$currentTone $next[0]/$nextTone $predict[0]/$predict[1]";
print $output "\n";
}
}
}
print "\n";
}
if ( $#ARGV < 1 ) {
&printUsage();
die "exit program...";
}
$skipnum = 2;
if ( $#ARGV < 2 ) {
$skipnum = 2;
}else {
$skipnum = $ARGV[2];
}
$inputname = $ARGV[0];
$outputname = $ARGV[1];
open $input, "<" , $inputname or die "can't open $inputname";
open $output, ">", $outputname or die "can't open $outputname";
while($line = <$input> )
{
chomp $line;
&getLine($line,$skipnum,$output);
}