pattern_byplayer.sh: don't gen_spat_dict
[pachi.git] / pattern_mminput.pl
blob8b80f46431c0dfec4d7678caf3c556ed4f10b579
1 #!/usr/bin/perl
2 # pattern_mminput - convert patterns for Remi Coulom's MM tool
4 # First, run pattern_enumerate, then feed it to this one. The script will
5 # also use the pattern.fdict file generated by pattern_enumerate, so direct
6 # piping probably will not work.
8 # We use two-pass approach mainly basically to find out how many features
9 # of certain kind there are.
11 # See mm/README for format of generated output.
13 my @fi, @fc, @fn; # start indices, counts, maps
15 my $total;
16 my $df = "patterns.fdict";
17 open D, $df or die "$df: $!";
18 while (<D>) {
19 chomp;
20 my ($si, $fi, $fpi, $fn, $fp) = (/^(.*?) (.*?):(.*?) (.*?):(.*?)$/);
21 $fn[$fi] = $fn;
22 defined $fi[$fi] or $fi[$fi] = $si;
23 $fc[$fi]++;
24 $total = $si + 1;
26 close D;
28 print "! $total\n";
29 print (@fi."\n");
30 foreach my $i (0 .. $#fi) {
31 print $fc[$i]." ".$fn[$i]."\n";
33 print "!\n";
35 while (<>) {
36 chomp;
37 s/^\(//; s/\)$//;
38 my @patterns = split(/\) \(/, $_);
39 my @teams = ();
40 print "#\n";
41 foreach my $pat (@patterns) {
42 my @feats = split(/ /, $pat);
43 my @tfeats = ();
44 foreach my $feat (@feats) {
45 my ($fi, $fp) = split(/:/, $feat);
46 push @tfeats, $fi[$fi] + $fp;
48 push @teams, join(' ', @tfeats);
50 print $teams[0]."\n";
51 foreach my $i (0 .. $#teams) {
52 print $teams[$i]."\n";