Changeset 19dfa5c for app/src/dgp
- Timestamp:
- 04/24/08 12:36:13 (17 years ago)
- Branches:
- master, help
- Children:
- 12d8443
- Parents:
- a5fdde9
- git-author:
- pawelk <pawelk@…> (04/24/08 12:36:13)
- git-committer:
- pawelk <pawelk@…> (04/24/08 12:36:13)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
app/src/dgp/dgc
r0214596 r19dfa5c 6 6 #author: Tomasz Obrebski 7 7 8 # wymaga niejawnie programu canonize!!!! 8 9 #use lib "ENV{HOME}/.utt/lib/perl"; 9 #use strict; 10 11 use strict; 10 12 use Getopt::Long; 11 13 use Data::Dumper; 12 14 13 15 use attr; 14 #use File::HomeDir; 16 use File::HomeDir; 17 18 my $systemconfigfile='/usr/local/etc/utt/dgc.conf'; 19 my $userconfigfile=home()."/.utt/dgc.conf"; 20 21 Getopt::Long::Configure('no_ignore_case_always'); 15 22 16 23 my $help=0; … … 18 25 my $dicfile=0; 19 26 my $gramfile=0; 27 my $outputfile=0; 28 29 #read configuration files########################### 30 my $file; 31 foreach $file ($systemconfigfile, $userconfigfile){ 32 if(open(CONFIG, $file)){ 33 while (<CONFIG>) { 34 chomp; 35 s/#.*//; 36 s/^\s+//; 37 s/\s+$//; 38 next unless length; 39 my ($name, $value) = split(/\s*=\s*/, $_, 2); 40 if(($name eq "catfile")or($name eq "c")){ 41 $catfile=$value; 42 } 43 elsif(($name eq "dicfile")or($name eq "d")){ 44 $dicfile=$value; 45 } 46 elsif(($name eq "gramfile")or($name eq "g")){ 47 $gramfile=$value; 48 } 49 elsif(($name eq "outputfile")or($name eq "o")){ 50 $outputfile=$value; 51 } 52 elsif(($name eq "help")or($name eq "h")){ 53 $help=1; 54 } 55 56 } 57 close CONFIG; 58 } 59 } 60 ######################################################### 61 62 GetOptions("help|h" => \$help, 63 "catfile|c=s" => \$catfile, 64 "dicfile|d=s" => \$dicfile, 65 "gramfile|g=s" => \$gramfile, 66 "outputfile|o=s" => \$outputfile); 67 68 if($help) 69 { 70 print <<'END' 71 Usage: dgc [OPTIONS] 72 73 Options: 74 --catfile -c filename List of syntactic categories. 75 --dicfile -d filename Dictionary. 76 --gramfile -g filename List of grammar rules. 77 --outputfile -o filename Output filename. 78 --help -h Help. 79 END 80 ; 81 exit 0; 82 } 83 84 die("At least one of --cats and --dic must be given.\n") if !$catfile && !$dicfile; 20 85 21 86 my $ncat=0; … … 27 92 my $nlink=0; 28 93 29 GetOptions("help|h" => \$help,30 "catfile|c=s" => \$catfile,31 "dicfile|d=s" => \$dicfile,32 "gramfile|g=s" => \$gramfile);33 34 if($help)35 {36 print <<'END'37 Usage: dgpcompile [OPTIONS]38 39 Options:40 --cats -c filename List of syntactic categories.41 --dic -d filename Dictionary.42 --help -h Help.43 END44 ;45 exit 0;46 }47 48 die("At least one of --cats and --dic must be given.\n") if !$catfile && !$dicfile;49 50 94 my %cats; 51 95 my %roles; … … 53 97 my %gov; 54 98 99 if(!$outputfile) { 100 *OUTPUT = *STDOUT; 101 } 102 elsif($outputfile eq "-") { 103 *OUTPUT = *STDOUT; 104 } 105 else { 106 open(OUTPUT, ">$outputfile") or die("Can't open output file: $outputfile!"); 107 } 108 109 110 55 111 loadcats($catfile) if $catfile; 56 112 extractcats($dicfile) if $dicfile; 57 113 58 114 59 $cats_re = qr/(?:$attr::cat_re\s*(?:,\s*$attr::cat_re)*)/;115 my $cats_re = qr/(?:$attr::cat_re\s*(?:,\s*$attr::cat_re)*)/; 60 116 61 117 # class parse_class: 62 118 # /$attr::cat_re/g; 63 119 64 while(<>) 120 121 if(!$gramfile) { 122 *INPUT = *STDIN; 123 } 124 elsif($gramfile eq "-"){ 125 *INPUT = *STDIN; 126 } 127 else { 128 open(INPUT, $gramfile) or die("Unable to open: $gramfile!"); 129 } 130 131 while(<INPUT>) 65 132 { 66 133 if(/^\s*AGR\s+(\S+)\s+(\S+)\s*$/) … … 75 142 { 76 143 $roles{$_}=1; 77 print ;144 print OUTPUT; 78 145 } 79 146 elsif(/^\s*SGL\s+\S+\s*$/) 80 147 { 81 148 ++$nsgl; 82 print ;149 print OUTPUT; 83 150 } 84 151 elsif(/^\s*REQ\s+(\S+)\s+(\S+)\s*$/) 85 152 { 86 print "#$_";153 print OUTPUT "#$_"; 87 154 my $cat = attr::parse $1; 88 155 for my $atomcat (keys %cats) … … 90 157 if(attr::match @$cat, @{$cats{$atomcat}}) 91 158 { 92 print "REQ ".$atomcat." $2\n";159 print OUTPUT "REQ ".$atomcat." $2\n"; 93 160 ++$nreq; 94 161 } … … 98 165 { 99 166 ++$nleft; 100 print ;167 print OUTPUT; 101 168 } 102 169 elsif(/^\s*RIGHT\s+\S+\s*$/) 103 170 { 104 171 ++$nright; 105 print ;106 } 107 elsif( ($hs,$ds,$r) = /^\s*LINK\s+($cats_re)\s+($cats_re)\s+(\S+)\s*$/)108 { 109 print "#$_";110 for $h ($hs =~ /$attr::cat_re/g)111 { 112 for $d ($ds =~ /$attr::cat_re/g)172 print OUTPUT; 173 } 174 elsif(my ($hs,$ds,$r) = /^\s*LINK\s+($cats_re)\s+($cats_re)\s+(\S+)\s*$/) 175 { 176 print OUTPUT "#$_"; 177 for my $h ($hs =~ /$attr::cat_re/g) 178 { 179 for my $d ($ds =~ /$attr::cat_re/g) 113 180 { 114 181 addlinks($h,$d,$r); … … 119 186 else 120 187 { 121 print ;188 print OUTPUT; 122 189 } 123 190 } … … 126 193 sub addlinks 127 194 { 128 ($h,$d,$r) = @_;129 130 for my $a (@{$agr{$r}}) { print "#AGR $r $a\n"; }131 for my $c (@{$gov{$r}}) { print "#GOV $r ".attr::unparse(@$c)."\n"; }195 my ($h,$d,$r) = @_; 196 197 for my $a (@{$agr{$r}}) { print OUTPUT "#AGR $r $a\n"; } 198 for my $c (@{$gov{$r}}) { print OUTPUT "#GOV $r ".attr::unparse(@$c)."\n"; } 132 199 my $head = attr::parse $h; 133 200 my $dep = attr::parse $d; … … 152 219 } 153 220 154 print "LINK ";155 print $atomhead." ";156 print $atomdep." $r\n";221 print OUTPUT "LINK "; 222 print OUTPUT $atomhead." "; 223 print OUTPUT $atomdep." $r\n"; 157 224 ++$nlink; 158 225 … … 180 247 while(/,([^[:space:];]+)/g) 181 248 { 182 $cat=$1;249 my $cat=$1; 183 250 next if !$cat || exists $cats{$cat}; 184 251 $ncat++; 185 print "CAT $1\n";252 print OUTPUT "CAT $1\n"; 186 253 $cats{$cat}=attr::parse($cat); 187 254 } … … 199 266 tr/ \t\n//d; 200 267 next if !$_ || exists $cats{$_}; 201 print "CAT $_\n";268 print OUTPUT "CAT $_\n"; 202 269 ++$ncat; 203 270 $cats{$_}=attr::parse($_); … … 205 272 close CATFILE; 206 273 } 274
Note: See TracChangeset
for help on using the changeset viewer.