1#!/usr/bin/perl -w 2use strict; 3 4my %cdict = (); my $cdictNum = 1; 5while (1) { 6 my $cdictFile = shift or last; 7 open F, $cdictFile or die; 8 while (<F>) { 9 chomp; 10 my ($c, $num) = split; 11 $cdict{$c} = $num; 12 if ($num+1 > $cdictNum) { $cdictNum = $num + 1; } 13 } 14 close F or die; 15} 16 17my @w = (); my @t = (); my @c = (); 18while (<>) { 19 chomp; 20 if (/^[\s]*$/) { dumpit(); print "\n"; @w = (); @t = (); @c = (); next; } 21 22 my ($w,$t,$c) = split; 23 #if ($c =~ /-NP/) { push @c, "1"; } else { push @c, "-1"; } 24 if (not exists $cdict{$c}) { 25 $cdict{$c} = $cdictNum; 26 $cdictNum++; 27 print STDERR "$c\t$cdict{$c}\n"; 28 } 29 30 push @c, $cdict{$c}; 31 push @t, $t; 32 push @w, $w; 33} 34 35sub dumpit { 36 for (my $n=0; $n<@c; $n++) { 37 my %f = (); 38 for (my $m=-2; $m<=+2; $m++) { 39 computef(\%f, '_'.$m, $n+$m); 40 } 41 print $c[$n] . ' |'; 42 foreach my $f (keys %f) { 43 $f =~ s/:/-COL-/g; 44 $f =~ s/\|/-PIP-/g; 45 print ' ' . $f; 46 } 47 print "\n"; 48 } 49} 50 51sub computef { 52 my ($f, $s0, $i) = @_; 53 54 if ($i < 0) { $f->{"w".$s0."=<s>" } = 1; return; } 55 if ($i >= @c) { $f->{"w".$s0."=</s>"} = 1; return; } 56 57 my $w = $w[$i]; my $p = $t[$i]; my $l = lc($w[$i]); 58 59 $f->{"w".$s0."=".$w} = 1; 60# $f->"p:=".$p} = 1; 61 $f->{"l".$s0."=".$l} = 1; 62 63 my $c = $w; 64 $c =~ s/[A-Z]+/A/g; 65 $c =~ s/[a-z]+/a/g; 66 $c =~ s/[0-9]+/0/g; 67 $c =~ s/[^\.Aa0]+/\#/g; 68 $f->{"c".$s0."=".$c} = 1; 69 $f->{"c".$s0."=".$c."_fw=".(($i==0) ? "y" : "n")} = 1; 70 71 my $N = length($l); 72 $f->{"pre1".$s0."=".substr($l,0,1)} = 1; 73 $f->{"pre2".$s0."=".substr($l,0,2)} = 1; 74 $f->{"pre3".$s0."=".substr($l,0,3)} = 1; 75 $f->{"suf1".$s0."=".substr($l,$N-1,1)} = 1; 76 $f->{"suf2".$s0."=".substr($l,$N-2,2)} = 1; 77 $f->{"suf3".$s0."=".substr($l,$N-3,3)} = 1; 78} 79