- Timestamp:
- 01/17/13 20:50:41 (12 years ago)
- Branches:
- master
- Children:
- d2f119e
- Parents:
- 555c7f8
- git-author:
- Tomasz Obrebski <to@…> (01/17/13 20:50:41)
- git-committer:
- Tomasz Obrebski <to@…> (01/17/13 20:50:41)
- Location:
- src
- Files:
-
- 4 deleted
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/dgc/Makefile
re7de6cc r3b02b04 7 7 ifdef BIN_DIR 8 8 install -m 0755 dgc $(BIN_DIR) 9 install -m 0755 l2src $(BIN_DIR) 9 10 endif 10 11 … … 13 14 ifdef BIN_DIR 14 15 rm $(BIN_DIR)/dgc 16 rm $(BIN_DIR)/l2src 15 17 endif 16 18 -
src/dgc/dgc
re7de6cc r3b02b04 9 9 use lib "$ENV{'HOME'}/.local/lib/utt"; 10 10 11 use strict;11 #use strict; 12 12 use Getopt::Long; 13 13 use Data::Dumper; 14 14 use attr; 15 15 use File::HomeDir; 16 use Parse::RecDescent; 17 18 $::RD_HINT=1; 19 # use List::MoreUtils; 16 20 17 21 my $systemconfigfile='/etc/utt/dgc.conf'; 18 my $userconfigfile= home()."/.utt/dgc.conf";22 my $userconfigfile=0; #home()."/.utt/dgc.conf"; 19 23 20 24 Getopt::Long::Configure('no_ignore_case_always'); … … 31 35 if(open(CONFIG, $file)){ 32 36 while (<CONFIG>) { 33 chomp; 34 s/#.*//; 35 s/^\s+//; 36 s/\s+$//; 37 chomp; s/#.*//; s/^\s+//; s/\s+$//; 37 38 next unless length; 38 39 my ($name, $value) = split(/\s*=\s*/, $_, 2); 39 if(($name eq "categories")or($name eq "c")){ 40 $catfile=$value; 41 } 42 elsif(($name eq "dictionary")or($name eq "d")){ 43 $dicfile=$value; 44 } 45 elsif(($name eq "grammar")or($name eq "g")){ 46 $gramfile=$value; 47 } 48 elsif(($name eq "outputfile")or($name eq "o")){ 49 $outputfile=$value; 50 } 51 elsif(($name eq "help")or($name eq "h")){ 52 $help=1; 53 } 40 if(($name eq "categories")or($name eq "c")) { $catfile=$value; } 41 elsif(($name eq "dictionary")or($name eq "d")) { $dicfile=$value; } 42 elsif(($name eq "grammar")or($name eq "g")) { $gramfile=$value; } 43 elsif(($name eq "outputfile")or($name eq "o")) { $outputfile=$value; } 44 elsif(($name eq "help")or($name eq "h")) { $help=1; } 54 45 55 46 } … … 90 81 die("At least one of --cats and --dic must be given.\n") if !$catfile && !$dicfile; 91 82 92 my $ncat=0; 93 my $nrole=0; 94 my $nsgl=0; 95 my $nleft=0; 96 my $nright=0; 97 my $ninitr=0; 98 my $nfinr=0; 99 my $ninitf=0; 100 my $nfinf=0; 101 my $ninitc=0; 102 my $nfinc=0; 103 my $nreq=0; 104 my $nlink=0; 105 my $nflag=0; 106 my $nset=0; 107 my $npass=0; 108 my $nlong=0; 109 my $nconstr=0; 110 my $nclass=0; 111 112 my %cats; 113 my %roles; 114 my %agr; 115 my %gov; 116 117 if(!$outputfile) { 118 *OUTPUT = *STDOUT; 119 } 120 elsif($outputfile eq "-") { 121 *OUTPUT = *STDOUT; 122 } 123 else { 124 open(OUTPUT, ">$outputfile") or die("Can't open output file: $outputfile!"); 125 } 126 83 84 our %in; #gramatyka wej¶ciowa 85 our %idx; #indeks gramatyki wej¶ciowej (niektóre stwierdzenia) 86 our %out; #gramatyka wyj¶ciowa 87 our %class; #tablica klas 88 89 our $attr_re = $attr::attr_re; 90 our $cat_re = $attr::cat_re; 91 our $cats_re = qr/(?:$attr::cat_re\s*(?:,\s*$attr::cat_re)*)/; 92 our $class_re = qr/(?:\@\w+)/; 93 our $av_re = $attr::av_re; 94 our $avlist_re = $attr::avlist_re; 95 our $role_re = qr/(?:[[:lower:][:digit:]_]+)/; 96 our $prop_re = qr/(?:[[:upper:]]+)/; 97 our $proplist_re = qr/(?:(?:\&$prop_re)+)/; 98 99 my $inputlineno=0; 100 101 our $statementgrammar = q( 102 103 statement : statement1 ";" { $item[1] } 104 105 statement1: /cat/i acat { ['cat', { cat=>$item{acat}, catexp=>attr::parse($item{acat}) }, $item{acat}] } 106 | /flag/i flag { ['flag', { flag=>$item{flag} }, $item{flag}] } 107 | /role/i role { ['role', { role=>$item{role} }, $item{role}] } 108 | /left/i role { ['left', { role=>$item{role} }, 0] } 109 | /right/i role { ['right', { role=>$item{role} }, 0] } 110 | /sgl/i role { ['sgl', { role=>$item{role} }, 0] } 111 | /req/i xcat role { ['req', { cats=>$item{xcat}, role=>$item{role} }, 0] } 112 | /agr/i role attr { ['agr', { role=>$item{role}, attr=>$item{attr} }, $item{role}] } 113 | /gov/i role xcat { ['gov', { role=>$item{role}, cats=>$item{xcat} }, $item{role}] } 114 | /init/i flagconstr { ['initf', { flag=>$item{flagconstr} }, 0] } 115 | /fin/i flagconstr { ['finf', { flag=>$item{flagconstr} }, 0] } 116 | /init/i role { ['initr', { role=>$item{role} }, 0] } 117 | /fin/i role { ['finr', { role=>$item{role} }, 0] } 118 | /set/i xcat flag { ['set', { cats=>$item{xcat}, flag=>$item{flag} }, 0] } 119 | /pass/i role flag { ['pass', { role=>$item{role}, flag=>$item{flag} }, 0] } 120 | /constre/i role role { ['constre', { role1=>$item[2], role2=>$item[3] }, 0] } 121 | /constri/i role role { ['constri', { role1=>$item[2], role2=>$item[3] }, 0] } 122 123 | /link/i xcat optflags(?) xcat optflags(?) role prop(s?) 124 { ['link', { hcats=>$item[2], hflagconstr=>$item[3], 125 dcats=>$item[4], dflagconstr=>$item[5], 126 role=>$item[6], props=>$item[7] }, 0] } 127 128 | /long/i role role(s? /,/) '^' role(s? /,/) 129 { ['long', { rel=>$item[2], up=>$item[3], down=>$item[5] }, 0] } 130 131 | /class/i classname '=' xcat { ['class', { name=>$item{classname}, cats=>$item{xcat} }, $item{classname}] } 132 133 acat: /$attr::cat_re/ 134 135 attr: /$attr::attr_re/ 136 137 xcat: classexpr 138 139 role: /\w+/ 140 141 flag: /\w+/ 142 143 optflags: "//" flagconstr { $item[2] } 144 145 flagconstr: /\w+[+-]/ 146 147 prop: '&' /\w+/ { $item[2] } 148 149 classname: /\$\w+[+-]/ 150 151 classexpr : classexpr1 '|' classexpr { main::union($item[1],$item[3]) } 152 | classexpr1 '~' classexpr { main::intersection( $item[1], main::complement($item[3]) ) } 153 | classexpr1 154 155 classexpr1 : classexpr2 '&' classexpr1 { main::intersection($item[1],$item[3]) } 156 | classexpr2 157 158 classexpr2 : '~' classexpr2 { main::complement($item[2]) } 159 | classexpr3 160 161 classexpr3 : classexpr4 '/' /$attr::avlist_re/ { main::intersection($item[1], [main::extension('*/' . $item[3])] ) } 162 | classexpr4 163 164 classexpr4 : class 165 | cat 166 | '(' classexpr ')' { $item[2] } 167 168 class : classname { $main::class{$item[1]} or @{[]} } 169 170 cat : /$main::cat_re/ { [main::extension($item[1])] } 171 172 ); 173 174 our $statementparser = Parse::RecDescent->new($statementgrammar); 175 176 sub register 177 { 178 my ($src, $statement, $data, $index) = @_ ; 179 $data->{line} = $inputlineno; 180 $data->{src} = $src; 181 push @{$in{$statement}}, $data; 182 push @{$idx{$statement}{$index}}, $data if($index); 183 184 if ($statement eq 'class') { $class{ $data->{name} } = $data->{cats} } 185 } 186 187 188 if(!$outputfile) { *OUTPUT = *STDOUT; } 189 elsif($outputfile eq "-") { *OUTPUT = *STDOUT; } 190 else { open(OUTPUT, ">$outputfile") or die("Can't open output file: $outputfile!"); } 191 192 if(!$gramfile) { *INPUT = *STDIN; } 193 elsif($gramfile eq "-") { *INPUT = *STDIN; } 194 else { open(INPUT, "cat $gramfile | m4 |") or die("Unable to open: $gramfile!"); } 195 196 # *INPUT = *STDIN; ############### TYMCZASOWO 127 197 128 198 loadcats($catfile) if $catfile; … … 130 200 131 201 132 my $cats_re = qr/(?:$attr::cat_re\s*(?:,\s*$attr::cat_re)*)/; 133 my $class_re = qr/(?:\@\w+)/; 134 135 my $avlist_re = $attr::avlist_re; 136 137 my $role_re = qr/(?:[[:lower:][:digit:]_]+)/; 138 my $prop_re = qr/(?:\&[[:upper:]]+)/; 139 my $proplist_re = qr/(?:$prop_re+)/; 140 141 # class parse_class: 142 # /$attr::cat_re/g; 143 144 145 if(!$gramfile) { 146 *INPUT = *STDIN; 147 } 148 elsif($gramfile eq "-"){ 149 *INPUT = *STDIN; 150 } 151 else { 152 open(INPUT, $gramfile) or die("Unable to open: $gramfile!"); 153 } 202 # CZYTANIE GRAMATYKI DGC 154 203 155 204 while(<INPUT>) 156 205 { 206 $inputlineno++; 157 207 s/#.*//; 158 208 s/^\s+//; 159 209 s/\s+$//; 160 if(/^AGR\s+(\S+)\s+(\S+)$/) 210 s/\s+/ /g; 211 next unless $_; 212 my $result = $statementparser->statement("$_;"); 213 214 # print "#input line $inputlineno\n"; 215 # print Dumper($result); 216 217 if($result) { register($_, @{$result}) } else { print STDERR "ERROR at line $inputlineno\n" } 218 } 219 220 221 # GENEROWANIE GRAMATYKI DGP 222 223 my $inline = 0; 224 my $outline = 0; 225 226 227 # print Dumper($idx{gov}->{subj}); 228 229 230 for my $x (@{$in{cat}}) { print_outin("CAT $x->{cat}", $x); } 231 232 for my $x (@{$in{flag}}) { print_outin("FLAG $x->{flag}", $x); } 233 234 for my $x (@{$in{role}}) { print_outin("ROLE $x->{role}", $x); } 235 236 for my $x (@{$in{long}}) { print_outin("LONG $x->{rel} " . join(",",@{$x->{up}}) . "^" . join(",",@{$x->{down}}), $x) } 237 238 for my $x (@{$in{left}}) { print_outin("LEFT $x->{role}", $x) if chk_role($x->{role}, $x) } 239 240 for my $x (@{$in{right}}) { print_outin("RIGHT $x->{role}", $x) if chk_role($x->{role}, $x) } 241 242 for my $x (@{$in{sgl}}) { print_outin("SGL $x->{role}", $x) if chk_role($x->{role}, $x) } 243 244 for my $x (@{$in{req}}) 245 { 246 if( chk_role($x->{role}, $x) ) 161 247 { 162 push @{$agr{$1}}, $2; 163 } 164 elsif(/^GOV\s+(\S+)\s+(\S+)$/) 165 { 166 push @{$gov{$1}}, attr::parse($2); 167 } 168 elsif(/^ROLE\s+\S+$/) 169 { 170 $roles{$_}=1; 171 print OUTPUT "$_\n"; 172 } 173 elsif(/^SGL\s+\S+$/) 174 { 175 ++$nsgl; 176 print OUTPUT "$_\n"; 177 } 178 elsif(/^REQ\s+(\S+)\s+(\S+)$/) 179 { 180 print OUTPUT "#$_\n"; 181 my $cat = attr::parse $1; 182 for my $atomcat (keys %cats) 248 for my $atomcat (map{$_->{cat}} @{$x->{cats}}) 183 249 { 184 if(attr::match @$cat, @{$cats{$atomcat}}) 185 { 186 print OUTPUT "REQ ".$atomcat." $2\n"; 187 ++$nreq; 188 } 250 print_outin("REQ $atomcat $x->{role}", $x); 189 251 } 190 252 } 191 elsif(/^LEFT\s+\S+$/) 253 } 254 255 for my $x (@{$in{initr}}) { print_outin("INITR $x->{role}", $x) if chk_role($x->{role}, $x) } 256 257 for my $x (@{$in{finr}}) { print_outin("FINR $x->{role}", $x) if chk_role($x->{role}, $x) } 258 259 for my $x (@{$in{initf}}) { print_outin("INITF $x->{flag}", $x) } # SPRAWDZIÆ CZY FLAGA JEST ZADEKLAROWANA 260 261 for my $x (@{$in{finf}}) { print_outin("FINF $x->{flag}", $x); } # SPRAWDZIÆ CZY FLAGA JEST ZADEKLAROWANA 262 263 for my $x (@{$in{set}}) 264 { 265 for my $atomcat (map{$_->{cat}} @{$x->{cats}}) 192 266 { 193 ++$nleft; 194 print OUTPUT "$_\n"; 267 print_outin("SET $atomcat $x->{flag}", $x); 268 } 269 } 270 271 for my $x (@{$in{pass}}) { print_outin("PASS $x->{role} $x->{flag}", $x); } 272 273 for my $x (@{$in{constre}}) { print_outin("CONSTRE $x->{role1} $x->{role2}", $x) if chk_role($x->{role1}, $x) & chk_role($x->{role2}, $x) } 274 275 for my $x (@{$in{constri}}) { print_outin("CONSTRI $x->{role1} $x->{role2}", $x) if chk_role($x->{role1}, $x) & chk_role($x->{role2}, $x) } 276 277 for my $x (@{$in{link}}) 278 { 279 my @agrs = @{ $idx{agr}->{$x->{role} } or [] }; 280 my @govs = @{ $idx{gov}->{$x->{role} } or [] }; 281 282 my @deps = (@govs > 0) ? @{ intersection( $x->{dcats}, map { $_->{cats} } @govs ) } : @{ $x->{dcats} } ; 283 284 for my $head ( @{ $x->{hcats} } ) 285 { 286 DEP: 287 for my $dep (@deps) 288 { 289 for my $agr (@agrs) 290 { 291 next DEP unless attr::agree(@{$head->{catexp}},@{$dep->{catexp}},$agr->{attr}); 292 } 293 my $hflagconstr = @{$x->{hflagconstr}} ? "//@{$x->{hflagconstr}}" : ""; 294 my $dflagconstr = @{$x->{dflagconstr}} ? "//@{$x->{dflagconstr}}" : ""; 295 my $props = join(map { "\&$_" } $x->{props}); 296 print_outin("LINK $head->{cat}$hflagconstr $dep->{cat}$dflagconstr $x->{role}$props",$x, @agrs, @govs); 297 } 195 298 } 196 elsif(/^RIGHT\s+\S+$/) 299 } 300 301 302 sub chk_role 303 { 304 ($role, $statement_details) = @_; 305 if($idx{role}{$role}) { 1; } else { print_error("undefined role", $statement_details); 0; } 306 } 307 308 sub print_outin 309 { 310 my ($out,@in) = (shift, @_); 311 print OUTPUT "$out\t\t#"; 312 printf OUTPUT " %04d@\"%s\"", $_->{line}, $_->{src} foreach @in; 313 print OUTPUT "\n"; 314 } 315 316 sub print_error 317 { 318 my ($message,@in) = (shift,@_); 319 print STDERR "ERROR: $message in statement "; 320 printf STDERR " %04d@\"%s\"", $_->{line}, $_->{src} foreach @in; 321 print STDERR "\n"; 322 } 323 324 325 sub extractcats 326 { 327 my $file = shift; 328 open DICFILE, "$file"; 329 while(<DICFILE>) 197 330 { 198 ++$nright; 199 print OUTPUT "$_\n"; 331 while(/,([^[:space:];]+)/g) 332 { 333 my $cat=$1; 334 next if !$cat; # || exists $cats{$cat}; 335 # print OUTPUT "CAT $1\n"; 336 register('cat', {src=>"CAT $cat", cat=>"$cat", catexp=>attr::parse($cat)}, $cat); 337 } 200 338 } 201 elsif(/^INIT\s+[[:lower:]]\S*$/) 339 close DICFILE; 340 } 341 342 343 sub loadcats 344 { 345 my $file = shift; 346 open CATFILE, "$file"; 347 while(<CATFILE>) 202 348 { 203 ++$ninitr; 204 s/INIT/INITR/; 205 print OUTPUT "$_\n"; 349 tr/ \t\n//d; 350 next if !$_; # || exists $cats{$_}; 351 # print OUTPUT "CAT $_\n"; 352 register("CAT $_", 'cat', {cat=>"$_", catexp=>attr::parse($_)}, $_); 206 353 } 207 elsif(/^FIN\s+[[:lower:]]\S*$/) 208 { 209 ++$nfinr; 210 s/FIN/FINR/; 211 print OUTPUT "$_\n"; 212 } 213 elsif(/^INIT\s+[[:upper:]]+[+-]$/) 214 { 215 ++$ninitf; 216 s/INIT/INITF/; 217 s/[+-]//g; 218 print OUTPUT "$_\n"; 219 } 220 elsif(/^FIN\s+[[:upper:]]+$/) 221 { 222 ++$nfinf; 223 s/FIN/FINF/; 224 s/[+-]//g; 225 print OUTPUT "$_\n"; 226 } 354 close CATFILE; 355 } 356 357 sub extension 358 { 359 my $cat = shift; 360 my $catexp = attr::parse($cat); 361 grep { attr::match(@{$_->{catexp}},@{$catexp}) } @{$in{cat}}; 362 } 363 364 sub uniq { my %seen; grep { ! $seen{$_}++ } @_ } 365 sub union { [ uniq( map { @{$_} } @_ ) ] } 366 sub intersection { my $n=@_; my %seen; [ grep { ++$seen{$_} == $n } map { @{$_} } @_ ] } 367 sub complement { my %exclude; for $c (@{shift()}) { $exclude{$c}++ }; [ grep { ! $exclude{$_} } @{$in{cat}} ] } 368 369 # printf STDERR "%6d CAT statements\n", 0+keys(%cats); 370 # printf STDERR "%6d ROLE statements\n", 0+keys(%role); 371 # printf STDERR "%6d SGL statements\n", @sgl+0; 372 # printf STDERR "%6d REQ statements\n", @req+0; 373 # printf STDERR "%6d LEFT statements\n", $nleft; 374 # printf STDERR "%6d RIGHT statements\n", $nright; 375 # printf STDERR "%6d INITR statements\n", $ninitr; 376 # printf STDERR "%6d FINR statements\n", $nfinr; 377 # printf STDERR "%6d INITF statements\n", $ninitf; 378 # printf STDERR "%6d FINF statements\n", $nfinf; 379 # printf STDERR "%6d INITC statements\n", $ninitc; 380 # printf STDERR "%6d FINC statements\n", $nfinc; 381 # printf STDERR "%6d LINK statements\n", $nlink; 382 # printf STDERR "%6d CLASS statements\n", $nclass; 383 # printf STDERR "%6d FLAG statements\n", $nflag; 384 # printf STDERR "%6d SET statements\n", $nset; 385 # printf STDERR "%6d PASS statements\n", $npass; 386 387 388 ################################################################################## 389 390 # while(<INPUT>) 391 # { 392 # $inputlineno++; 393 # s/#.*//; 394 # s/^\s+//; 395 # s/\s+$//; 396 # s/\s+/ /g; 397 # if (/^CAT ($cat_re)$/) { register('cat', {src=>$&, cat=>attr::parse($1)}, $1); } 398 # elsif(/^FLAG (\S+)$/) { register('flag', {src=>$&, flag=>$1}, $1); } 399 # elsif(/^ROLE (\S+)$/) { register('role', {src=>$&, role=>$1}, $1); } 400 # elsif(/^LEFT (\S+)$/) { register('left', {src=>$&, role=>$1}, 0); } 401 # elsif(/^RIGHT (\S+)$/) { register('right', {src=>$&, role=>$1}, 0); } 402 # elsif(/^SGL (\S+)$/) { register('sgl', {src=>$&, role=>$1}, 0); } 403 # elsif(/^REQ (\S+) (\S+)$/) { register('req', {src=>$&, cat=>$1, role=>$2}, 0); } 404 # elsif(/^AGR (\S+) (\S+)$/) { register('agr', {src=>$&, role=>$1, attr=>$2}, $1); } 405 # elsif(/^GOV (\S+) (\S+)$/) { register('gov', {src=>$&, role=>$1, cat=>$2, catexp=>attr::parse($2)}, $1); } 406 # elsif(/^INIT ($role_re)$/) { register('initr', {src=>$&, role=>$1}, 0); } 407 # elsif(/^FIN ($role_re)$/) { register('finr', {src=>$&, role=>$1}, 0); } 408 # elsif(/^INIT ($av_re)$/) { register('initf', {src=>$&, flag=>$1}, 0); } 409 # elsif(/^FIN ($av_re)$/) { register('finf', {src=>$&, flag=>$1}, 0); } 410 # elsif(/^SET ($cat_re)\s+(\S+)$/) { register('set', {src=>$&, cat=>$1, flag=>$2}, 0); } 411 # elsif(/^PASS (\S+)\s+(\S+)$/) { register('pass', {src=>$&, role=>$1, flag=>$2}, 0); } 412 # elsif(/^CONSTRE (\S+)\s+(\S+)$/) { register('constre', {src=>$&, role1=>$1, role2=>$2}, 0); } 413 # elsif(/^CONSTRI (\S+)\s+(\S+)$/) { register('constri', {src=>$&, role1=>$1, role2=>$2}, 0); } 414 415 # elsif(my ($hs,$hfs,$ds,$dfs,$r,$rprops) = /^LINK\s+($cats_re)((?:;$avlist_re)?)\s+($cats_re)((?:;$avlist_re)?)\s+($role_re)((?:$proplist_re)?)$/) 416 # { register('link', {src=>$&, hs=>$hs, hfs=>$hfs, ds=>$ds, dfs=>$dfs, r=>$r, props=>$rprops},0) } 417 # elsif(/^LONG\s+(\S+)((\s+<\S+)*)((\s+\S+>)*)$/) 418 # { 419 # my $rel = $1; 420 # my $ups = $2; 421 # my $downs = $4; 422 423 # $ups =~ s/<//g; 424 # $ups =~ s/^\s+//; 425 # my @up = split(/\s+/,$ups) or (); 426 427 # $downs =~ s/>//g; 428 # $downs =~ s/^\s+//; 429 # my @down = split(/\s+/,$downs) or (); 430 431 # register('long', {src=>$&, rel=>$rel, up=>\@up, down=>\@down},0); 432 433 # print OUTPUT "LONG $rel " . join(",",@up) . "^" . join(",",@down) . "\n"; 434 # } 435 # elsif(my ($cl,$cs) = /^CLASS\s+(\S+)\s*\=(.*)$/) 436 # { 437 # $class{$1} = $classparser->classexpr($2); 438 # } 439 # elsif(/^$/) 440 # { 441 # # pomijamy puste linie oraz komentarze 442 # } 443 # else 444 # { 445 # print STDERR "Illegal format: $_\n"; 446 # } 447 # } 448 449 450 451 # sub is_cat { shift =~ /$attr::cat_re/; } 452 # sub is_role { $role{shift}; } 453 # sub is_flag { $flag{shift}; } 454 455 456 # sub print_in 457 # { 458 # my $data = shift(); 459 # printf "in@%04d ", $data->{line}; 460 # print $data->{src}; 461 # } 462 463 # sub print_out 464 # { 465 # printf "out@%08d ", $outline++; 466 # print @_; 467 # } 468 469 # sub addlinks 470 # { 471 # my ($l, $h,$hfs,$d,$dfs,$r,$rprops) = @_; 472 473 # my @heads = extension($h); 474 # my @deps = extension($d); 475 476 # my @deps_gov; 477 # DEP_GOV: 478 # for my $dep (@deps) 479 # { 480 # for my $gov (@govs) 481 # { 482 # next DEP_GOV unless attr::match(@{$dep->{catexp}},@{$gov->{catexp}}); 483 # } 484 # push @deps_gov, $dep; 485 # } 486 487 # for my $head (@heads) 488 # { 489 # DEP: 490 # for my $dep (@deps_gov) 491 # { 492 # for my $agr (@agrs) 493 # { 494 # next DEP unless attr::agree(@{$head->{catexp}},@{$dep->{catexp}},$agr->{attr}); 495 # } 496 # print_outin("LINK $head->{cat}$hfs $dep->{cat}$dfs $r$rprops",$l, @agrs,@govs); 497 # } 498 # } 499 # } 500 501 502 503 227 504 # elsif(/^INIT\s+([[:upper:]]\S*)$/) 228 505 # { … … 251 528 # } 252 529 # } 253 elsif(my ($hs,$hfs,$ds,$dfs,$r,$rprops) = /^LINK\s+($cats_re)((?:;$avlist_re)?)\s+($cats_re)((?:;$avlist_re)?)\s+($role_re)((?:$proplist_re)?)$/)254 {255 print OUTPUT "#$_\n";256 for my $h ($hs =~ /$attr::cat_re/g)257 {258 for my $d ($ds =~ /$attr::cat_re/g)259 {260 addlinks($h,$hfs,$d,$dfs,$r,$rprops);261 }262 }263 }264 # elsif(my ($hs,$ds,$fs,$r) = /^LINK\s+($cats_re)\s+($cats_re)\s+(\S+)\s+(\S+)$/)265 # {266 # print OUTPUT "#$_\n";267 # for my $h ($hs =~ /$attr::cat_re/g)268 # {269 # for my $d ($ds =~ /$attr::cat_re/g)270 # {271 # addlinks1($h,$d,$fs,$r);272 # }273 # }274 # }275 elsif(/^FLAG\s+\S+$/)276 {277 ++$nflag;278 print OUTPUT "$_\n"279 }280 elsif(/^SET\s+(\S+)\s+(\S+)$/)281 {282 print OUTPUT "#$_\n";283 my $cat = attr::parse $1;284 my $flag = $2;285 for my $atomcat (keys %cats)286 {287 if(attr::match @$cat, @{$cats{$atomcat}})288 {289 print OUTPUT "SET ".$atomcat." $flag\n";290 ++$nset;291 }292 }293 }294 elsif(/^PASS\s+\S+\s+\S+$/)295 {296 ++$npass;297 print OUTPUT "$_\n"298 }299 elsif(/^CONSTR[IE]\s+\S+\s+\S+$/)300 {301 ++$nconstr;302 print OUTPUT "$_\n"303 }304 elsif(/^LONG\s+(\S+)((\s+<\S+)*)((\s+\S+>)*)$/)305 {306 ++$nlong;307 my $rel = $1;308 my $ups = $2;309 my $downs = $4;310 311 $ups =~ s/<//g;312 $ups =~ s/^\s+//;313 my @up = split(/\s+/,$ups);314 315 $downs =~ s/>//g;316 $downs =~ s/^\s+//;317 my @down = split(/\s+/,$downs);318 print OUTPUT "LONG $rel " . join(",",@up) . "^" . join(",",@down) . "\n";319 }320 elsif(my ($cl,$cs) = /^CLASS\s+(\S+)\s*\:\s*(.*)/)321 {322 print OUTPUT "#$_\n";323 for my $c ($cs =~ /\S+/g)324 {325 my $cat = attr::parse $c;326 327 for my $atomcat (sort(keys %cats))328 {329 if(attr::match @$cat, @{$cats{$atomcat}})330 {331 print OUTPUT "CLASS $cl $atomcat\n";332 ++$nclass;333 }334 }335 }336 }337 elsif(/^$/) {338 # pomijamy puste linie oraz komentarze339 }340 else341 {342 print STDERR "Illegal format: $_\n";343 }344 }345 346 347 sub addlinks348 {349 my ($h,$hfs,$d,$dfs,$r,$rprops) = @_;350 351 for my $a (@{$agr{$r}}) { print OUTPUT "#AGR $r $a\n"; }352 for my $c (@{$gov{$r}}) { print OUTPUT "#GOV $r ".attr::unparse(@$c)."\n"; }353 my $head = attr::parse $h;354 my $dep = attr::parse $d;355 356 for my $atomhead (keys %cats)357 {358 if(attr::match @$head, @{$cats{$atomhead}})359 {360 DEP:361 for my $atomdep (keys %cats)362 {363 next DEP if ! attr::match @$dep, @{$cats{$atomdep}};364 365 for my $a (@{$agr{$r}})366 {367 next DEP if ! attr::agree(@{$cats{$atomhead}},@{$cats{$atomdep}},$a);368 }369 370 for my $c (@{$gov{$r}})371 {372 next DEP if ! attr::match(@$c,@{$cats{$atomdep}});373 }374 375 print OUTPUT "LINK $atomhead$hfs $atomdep$dfs $r$rprops\n";376 ++$nlink;377 378 }379 }380 }381 }382 383 384 sub addlinks1385 {386 my ($h,$d,$fs,$r) = @_;387 388 for my $a (@{$agr{$r}}) { print OUTPUT "#AGR $r $a\n"; }389 for my $c (@{$gov{$r}}) { print OUTPUT "#GOV $r ".attr::unparse(@$c)."\n"; }390 my $head = attr::parse $h;391 my $dep = attr::parse $d;392 393 for my $atomhead (keys %cats)394 {395 if(attr::match @$head, @{$cats{$atomhead}})396 {397 DEP:398 for my $atomdep (keys %cats)399 {400 next DEP if ! attr::match @$dep, @{$cats{$atomdep}};401 402 for my $a (@{$agr{$r}})403 {404 next DEP if ! attr::agree(@{$cats{$atomhead}},@{$cats{$atomdep}},$a);405 }406 407 for my $c (@{$gov{$r}})408 {409 next DEP if ! attr::match(@$c,@{$cats{$atomdep}});410 }411 412 print OUTPUT "LINK $atomhead $atomdep $fs $r\n";413 ++$nlink;414 415 }416 }417 }418 }419 420 421 printf STDERR "%6d CAT statements\n", 0+keys(%cats);422 printf STDERR "%6d ROLE statements\n", 0+keys(%roles);423 printf STDERR "%6d SGL statements\n", $nsgl;424 printf STDERR "%6d REQ statements\n", $nreq;425 printf STDERR "%6d LEFT statements\n", $nleft;426 printf STDERR "%6d RIGHT statements\n", $nright;427 printf STDERR "%6d INITR statements\n", $ninitr;428 printf STDERR "%6d FINR statements\n", $nfinr;429 printf STDERR "%6d INITF statements\n", $ninitf;430 printf STDERR "%6d FINF statements\n", $nfinf;431 printf STDERR "%6d INITC statements\n", $ninitc;432 printf STDERR "%6d FINC statements\n", $nfinc;433 printf STDERR "%6d LINK statements\n", $nlink;434 printf STDERR "%6d CLASS statements\n", $nclass;435 printf STDERR "%6d FLAG statements\n", $nflag;436 printf STDERR "%6d SET statements\n", $nset;437 printf STDERR "%6d PASS statements\n", $npass;438 439 440 sub extractcats441 {442 my $file = shift;443 open DICFILE, "$file";444 while(<DICFILE>)445 {446 while(/,([^[:space:];]+)/g)447 {448 my $cat=$1;449 next if !$cat || exists $cats{$cat};450 $ncat++;451 print OUTPUT "CAT $1\n";452 $cats{$cat}=attr::parse($cat);453 }454 }455 close DICFILE;456 }457 458 459 sub loadcats460 {461 my $file = shift;462 open CATFILE, "$file";463 while(<CATFILE>)464 {465 tr/ \t\n//d;466 next if !$_ || exists $cats{$_};467 print OUTPUT "CAT $_\n";468 ++$ncat;469 $cats{$_}=attr::parse($_);470 }471 close CATFILE;472 }473 -
src/dgp/boubble.hh
re7de6cc r3b02b04 26 26 Boubble(list<Role> u, list<Role> d, LongRel l, int s=-1); 27 27 Boubble(const char* pathstr, const char* l, int s=-1); 28 // Boubble(const Boubble& b) {_src=b._src; _upath=b._upath; _dpath=b._dpath; _rel=b._rel; }; 28 29 29 30 Dir dir(); … … 138 139 } 139 140 140 if(d==DOWN && _upath.empty() && !_dpath.empty() )141 if(d==DOWN && _upath.empty() && !_dpath.empty() && _dpath.front() == r) 141 142 { 142 143 Boubble* newboubble = new Boubble(_upath,_dpath,_rel,_src); -
src/dgp/dgp1.cc
ra15e59b r3b02b04 10 10 list<int> nodelist; 11 11 list<int>::iterator processed; 12 13 14 void print_sets(int n); 15 12 16 13 17 //==================================================================================================== … … 44 48 ret.forbidden |= grammar.constr_exclude(link.role); 45 49 46 ret.boubbles =bs;50 ret.boubbles.merge(bs); //DOBRZE 47 51 ret.flags |= ( depflags & grammar.pass_flags(link.role) ); 48 52 … … 58 62 { 59 63 NodeProp ret=depprop; 60 ret.boubbles =bs;64 ret.boubbles.merge(bs); //DOBRZE 61 65 return ret; 62 66 } … … 67 71 { 68 72 MNode& mnode = mgraph[mnodeind]; 73 int ret=-1; 69 74 for(vector<int>::iterator ps=mnode.snodes.begin(); ps!=mnode.snodes.end(); ++ps) 70 if(sgraph[*ps].prop==p && sgraph[*ps].LH==newheadLH && sgraph[*ps].LV==newheadLV) return *ps; 71 return -1; 75 { 76 if(debug) fprintf(stderr,"#find existing node: checking %d ... \n", *ps); 77 if(sgraph[*ps].prop==p) 78 if(sgraph[*ps].LH==newheadLH && sgraph[*ps].LV==newheadLV) 79 { 80 ret = *ps; 81 // fprintf(stderr,"FIND EXISTING NODE SUCCEEDED BEACAUSE OF LH/LV equality ()\n"); 82 } 83 else 84 { 85 // fprintf(stderr,"FIND EXISTING NODE FAILED BEACAUSE OF LH/LV inequality\n"); 86 } 87 } 88 89 if(debug) fprintf(stderr,"\n"); 90 return ret; 72 91 } 73 92 … … 83 102 ret.push_back(new_boubble); 84 103 } 104 85 105 return ret; 86 106 } … … 120 140 //==================================================================================================== 121 141 122 int create_new_head_node_left(list<int>::iterator h, NodeProp& newheadprop, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLD, bitset<MAXNODES>& newheadLV) 123 { 124 int newheadind = sgraph.clone(*h,newheadprop); 125 list<int>::iterator nextit=h; ++nextit; 126 nodelist.insert(nextit,newheadind); 142 void copy_links(int i, int j) 143 { 144 sgraph[j].heads = sgraph[i].heads; 145 sgraph[j].deps = sgraph[i].deps; 146 } 147 148 149 void create_reverse_links(int n) 150 { 151 for(vector<Arc>::iterator a=sgraph[n].heads.begin(); a != sgraph[n].heads.end(); a++) 152 sgraph[a->dst].deps.push_back(Arc(n,a->role,a->headanc,a->depanc)); 153 154 for(vector<Arc>::iterator a=sgraph[n].deps.begin(); a != sgraph[n].deps.end(); a++) 155 sgraph[a->dst].heads.push_back(Arc(n,a->role,a->headanc,a->depanc)); 156 } 157 158 //==================================================================================================== 159 160 int create_new_head_node_left(int h, NodeProp& newheadprop, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLD, bitset<MAXNODES>& newheadLV) 161 { 162 int newheadind = sgraph.clone(h,newheadprop); 163 // list<int>::iterator nextit=h; ++nextit; 164 // nodelist.insert(nextit,newheadind); 165 nodelist.push_back(newheadind); 127 166 sgraph[newheadind].LH=newheadLH; 128 167 sgraph[newheadind].LD = newheadLD; 129 168 sgraph[newheadind].in_LH=true; 130 169 sgraph[newheadind].LV.reset(); 131 132 if(debug) sgraph.print_node_debug(stderr,"C ",newheadind,*h); 133 170 171 copy_links(h,newheadind); 172 create_reverse_links(newheadind); 173 174 if(debug) sgraph.print_node_debug(stderr,"C ",newheadind,h); 175 if(debug) print_sets(newheadind); 134 176 return newheadind; 135 177 } 136 178 137 int create_new_dep_node_left(list<int>::iterator d, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV) 138 { 139 int newind = sgraph.clone(*d,prop); 140 list<int>::iterator nextit=d; ++nextit; 141 nodelist.insert(nextit,newind); 179 int create_new_dep_node_left(int d, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV) 180 { 181 int newind = sgraph.clone(d,prop); 182 // list<int>::iterator nextit=d; ++nextit; 183 // nodelist.insert(nextit,newind); 184 nodelist.push_back(newind); 142 185 sgraph[newind].LH.reset(); 143 186 sgraph[newind].LD=LD; 144 187 sgraph[newind].in_LH=false; //??????? 145 188 sgraph[newind].LV.reset(); 146 147 if(debug) sgraph.print_node_debug(stderr,"C ",newind,*d); 189 190 copy_links(d,newind); 191 create_reverse_links(newind); 192 193 if(debug) sgraph.print_node_debug(stderr,"C ",newind,d); 194 if(debug) print_sets(newind); 148 195 149 196 return newind; 150 197 } 151 198 152 int create_new_head_node_right(list<int>::iterator h, NodeProp& newheadprop, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLD, bitset<MAXNODES>& newheadLV) 153 { 154 int newheadind = sgraph.clone(*h,newheadprop); 155 list<int>::iterator nextit=h; ++nextit; 156 nodelist.insert(nextit,newheadind); 199 int create_new_head_node_right(int h, NodeProp& newheadprop, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLD, bitset<MAXNODES>& newheadLV) 200 { 201 int newheadind = sgraph.clone(h,newheadprop); 202 // list<int>::iterator nextit=h; ++nextit; 203 // nodelist.insert(nextit,newheadind); 204 nodelist.push_back(newheadind); 157 205 sgraph[newheadind].LH=newheadLH; 158 206 sgraph[newheadind].LD=newheadLD; … … 160 208 sgraph[newheadind].LV=newheadLV; 161 209 162 if(debug) sgraph.print_node_debug(stderr,"C ",newheadind,*h); 210 copy_links(h,newheadind); 211 create_reverse_links(newheadind); 212 213 if(debug) sgraph.print_node_debug(stderr,"C ",newheadind,h); 214 if(debug) print_sets(newheadind); 163 215 164 216 return newheadind; 165 217 } 166 218 167 int create_new_dep_node_right(list<int>::iterator d, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV) 168 { 169 int newind = sgraph.clone(*d,prop); 170 list<int>::iterator nextit=d; ++nextit; 171 nodelist.insert(nextit,newind); 219 int create_new_dep_node_right(int d, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV) 220 { 221 int newind = sgraph.clone(d,prop); 222 nodelist.push_back(newind); 172 223 sgraph[newind].LH=LH; 173 224 sgraph[newind].LD=LD; … … 175 226 sgraph[newind].LV.reset(); 176 227 177 if(debug) sgraph.print_node_debug(stderr,"C ",newind,*d); 228 copy_links(d,newind); 229 create_reverse_links(newind); 230 231 if(debug) sgraph.print_node_debug(stderr,"C ",newind,d); 232 if(debug) print_sets(newind); 178 233 179 234 return newind; … … 182 237 //==================================================================================================== 183 238 184 void connect_left( list<int>::iterator h, list<int>::iteratord, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles)185 { 186 187 NodeProp &oldheadprop = sgraph[ *h].prop;188 NodeProp &olddepprop = sgraph[ *d].prop;239 void connect_left(int h, int d, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles) 240 { 241 242 NodeProp &oldheadprop = sgraph[h].prop; 243 NodeProp &olddepprop = sgraph[d].prop; 189 244 190 245 NodeProp newheadprop = compute_head_prop(oldheadprop,l,new_head_boubbles,olddepprop.flags); … … 192 247 int newheadind; 193 248 if(oldheadprop==newheadprop) 194 newheadind = *h;249 newheadind = h; 195 250 else 196 251 { 197 bitset<MAXNODES> newheadLH = sgraph[*h].LH; 198 bitset<MAXNODES> newheadLV = sgraph[*d].LV; 199 bitset<MAXNODES> newheadLD = sgraph[*h].LD; 200 201 newheadind = find_existing_node(sgraph[*h].mnode, newheadprop, newheadLH, newheadLV); 202 if( newheadind >= 0 ) 252 bitset<MAXNODES> newheadLH = sgraph[h].LH; 253 bitset<MAXNODES> newheadLV = sgraph[d].LV; 254 bitset<MAXNODES> newheadLD = sgraph[h].LD; 255 256 // vector<int> newedge; 257 258 newheadind = find_existing_node(sgraph[h].mnode, newheadprop, newheadLH, newheadLV); 259 if( newheadind >= 0) // W£¡CZONE 203 260 sgraph[newheadind].LD |= newheadLD; 204 261 else 205 newheadind = create_new_head_node_left(h,newheadprop,newheadLH,newheadLD,newheadLV); 262 { 263 newheadind = create_new_head_node_left(h,newheadprop,newheadLH,newheadLD,newheadLV); 264 sgraph[newheadind].edge.clear(); 265 sgraph[newheadind].edge_contains_self = false; 266 } 267 206 268 } 207 269 208 209 210 270 NodeProp newdepprop = compute_dep_prop(olddepprop,l,new_dep_boubbles); 211 271 … … 213 273 214 274 if(olddepprop==newdepprop) 215 newdepind = *d;275 newdepind = d; 216 276 else 217 277 { 218 bitset<MAXNODES> newdepLH = sgraph[ *d].LH;219 bitset<MAXNODES> newdepLV = sgraph[ *d].LV;220 bitset<MAXNODES> newdepLD = sgraph[ *d].LD;221 222 newdepind = find_existing_node(sgraph[ *d].mnode, newdepprop, newdepLH, newdepLV);223 if( newdepind >= 0 )278 bitset<MAXNODES> newdepLH = sgraph[d].LH; 279 bitset<MAXNODES> newdepLV = sgraph[d].LV; 280 bitset<MAXNODES> newdepLD = sgraph[d].LD; 281 282 newdepind = find_existing_node(sgraph[d].mnode, newdepprop, newdepLH, newdepLV); 283 if( newdepind >= 0) // W£¡CZONE 224 284 sgraph[newdepind].LD |= newdepLD; // TYLKO DLA LD 225 285 else 226 newdepind = create_new_dep_node_left(d,newdepprop,newdepLH,newdepLD,newdepLV); 286 { 287 newdepind = create_new_dep_node_left(d,newdepprop,newdepLH,newdepLD,newdepLV); 288 sgraph[newdepind].edge.clear(); 289 //sgraph[newdepind].edge.push_back(newdepind); // TO 290 sgraph[newdepind].edge_contains_self = true; // LUB TO 291 } 227 292 } 228 229 sgraph[newheadind].deps.push_back(Arc(newdepind,l.role,*h,*d)); 230 231 if(sgraph[*d].saturated()) sgraph[newheadind].LV |= sgraph[*d].LV; 232 233 sgraph[newheadind].LD.set(*d); 234 if(sgraph[*d].saturated()) sgraph[newheadind].LD |= sgraph[*d].LD; 235 236 if(debug) sgraph.print_arc(stderr,newheadind,*d,l.role,0); 237 if(debug) sgraph.print_node_debug(stderr,"U ",newheadind,*h); 238 if(debug) sgraph.print_node_debug(stderr,"U ",*d,*d); 293 294 295 sgraph[newheadind].deps.push_back(Arc(newdepind,l.role,h,d)); 296 sgraph[newdepind].heads.push_back(Arc(newheadind,l.role,h,d)); 297 sgraph[newheadind].edge.push_back(newdepind); 298 299 if(sgraph[d].saturated()) sgraph[newheadind].LV |= sgraph[d].LV; 300 301 sgraph[newheadind].LD.set(d); 302 if(sgraph[d].saturated()) sgraph[newheadind].LD |= sgraph[d].LD; 303 304 if(debug) sgraph.print_arc(stderr,newheadind,d,l.role,0); 305 if(debug) sgraph.print_node_debug(stderr,"U ",newheadind,h); 306 if(debug) print_sets(newheadind); 307 if(debug) sgraph.print_node_debug(stderr,"U ",newdepind,d); 308 if(debug) print_sets(newdepind); 239 309 } 240 310 241 311 //---------------------------------------------------------------------------------------------------- 242 312 243 void connect_right( list<int>::iterator h, list<int>::iteratord, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles)244 { 245 NodeProp &oldheadprop = sgraph[ *h].prop;246 247 NodeProp newheadprop = compute_head_prop(oldheadprop,l,new_head_boubbles, sgraph[ *d].prop.flags);313 void connect_right(int h, int d, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles) 314 { 315 NodeProp &oldheadprop = sgraph[h].prop; 316 317 NodeProp newheadprop = compute_head_prop(oldheadprop,l,new_head_boubbles, sgraph[d].prop.flags); 248 318 249 319 int newheadind; 250 320 251 321 if(oldheadprop==newheadprop) 252 newheadind = *h;322 newheadind = h; 253 323 else 254 324 { 255 bitset<MAXNODES> newheadLH = sgraph[*h].LH; 256 bitset<MAXNODES> newheadLV = sgraph[*h].LV; 257 bitset<MAXNODES> newheadLD = sgraph[*h].LD; 258 259 newheadind = find_existing_node(sgraph[*h].mnode, newheadprop, newheadLH, newheadLV); 260 if( newheadind >= 0 ) 325 bitset<MAXNODES> newheadLH = sgraph[h].LH; 326 bitset<MAXNODES> newheadLV = sgraph[h].LV; 327 bitset<MAXNODES> newheadLD = sgraph[h].LD; 328 329 newheadind = find_existing_node(sgraph[h].mnode, newheadprop, newheadLH, newheadLV); 330 331 if(debug) fprintf(stderr,"#HEAD EXISTS %d\n",newheadind); 332 333 if( newheadind >= 0) // W£¡CZONE 261 334 sgraph[newheadind].LD |= newheadLD; // TYLKO DLA LD 262 335 else 263 newheadind = create_new_head_node_right(h,newheadprop,newheadLH,newheadLD,newheadLV); 336 { 337 newheadind = create_new_head_node_right(h,newheadprop,newheadLH,newheadLD,newheadLV); 338 //if(!sgraph[h].edge.empty()) sgraph[newheadind].edge.push_back(newheadind); // TO 339 sgraph[newheadind].edge_contains_self = sgraph[h].edge_contains_self; // LUB TO 340 sgraph[newheadind].visible_as_neighbour = false; 341 } 264 342 } 265 343 266 NodeProp &olddepprop = sgraph[ *d].prop;344 NodeProp &olddepprop = sgraph[d].prop; 267 345 NodeProp newdepprop = compute_dep_prop(olddepprop,l,new_dep_boubbles); 268 346 … … 270 348 271 349 if(olddepprop==newdepprop) 272 newdepind = *d;350 newdepind = d; 273 351 else 274 352 { 275 bitset<MAXNODES> newdepLH = sgraph[*d].LH; 276 bitset<MAXNODES> newdepLV = sgraph[*d].LV; 277 bitset<MAXNODES> newdepLD = sgraph[*d].LD; 278 279 newdepind = find_existing_node(sgraph[*d].mnode, newdepprop, newdepLH, newdepLV); 280 if( newdepind >= 0 ) 353 bitset<MAXNODES> newdepLH = sgraph[d].LH; 354 bitset<MAXNODES> newdepLV = sgraph[d].LV; 355 bitset<MAXNODES> newdepLD = sgraph[d].LD; 356 357 newdepind = find_existing_node(sgraph[d].mnode, newdepprop, newdepLH, newdepLV); 358 359 if(debug) fprintf(stderr,"#DEP EXISTS %d\n",newdepind); 360 361 if( newdepind >= 0) // W£¡CZONE 281 362 sgraph[newdepind].LD |= newdepLD; // TYLKO DLA LD 282 363 else 283 newdepind = create_new_dep_node_right(d,newdepprop,newdepLH,newdepLD,newdepLV); 364 { 365 newdepind = create_new_dep_node_right(d,newdepprop,newdepLH,newdepLD,newdepLV); 366 sgraph[newdepind].edge.clear(); 367 sgraph[newdepind].edge_contains_self = false; 368 } 284 369 } 285 370 286 371 287 288 289 sgraph[newdepind].heads.push_back(Arc(newheadind,l.role,*h,*d));372 sgraph[newdepind].heads.push_back(Arc(newheadind,l.role,h,d)); 373 sgraph[newheadind].deps.push_back(Arc(newdepind,l.role,h,d)); 374 //sgraph[newdepind].edge.push_back(newheadind); 290 375 291 376 sgraph[newdepind].LH.set(newheadind); … … 296 381 297 382 if(debug) sgraph.print_arc(stderr,newheadind,newdepind,l.role,1); 298 if(debug) sgraph.print_node_debug(stderr,"U ",newheadind, *h);299 if(debug) sgraph.print_node_debug(stderr,"U ",newdepind, *d);383 if(debug) sgraph.print_node_debug(stderr,"U ",newheadind,h); 384 if(debug) sgraph.print_node_debug(stderr,"U ",newdepind,d); 300 385 301 386 } … … 323 408 } 324 409 325 // bool check_boubbles_at_target(list<Boubble*> boubbles, int node) 326 // { 327 // for(list<Boubble*>::iterator b = boubbles.begin(); b != boubbles.end(); ++b ) 328 // if( (*b)->is_at_target() && !grammar.check_longrel(sgraph.cat((*b)->src()), sgraph.cat(node), (*b)->rel()) ) 329 // return false; 330 // return true; 331 // } 332 333 //==================================================================================================== 334 335 void try_connect_dependents(list<int>::iterator j) 336 { 337 for(list<int>::iterator i(j); i!=nodelist.begin(); --i) 338 if(sgraph.visible(*i,*j) && sgraph.saturated(*i)) 339 { 340 if(debug) {fprintf(stderr,"## %d <-- %d ... ",*i,*j); } 341 342 list<const Link*> ji_links = grammar.connectable2( sgraph.cat(*j), sgraph.cat(*i), sgraph[*j].prop.flags, sgraph[*i].prop.flags); // ref do Roles!!! 410 //==================================================================================================== 411 412 void try_connect_dependents(int j) 413 { 414 // for(list<int>::iterator i(j); i!=nodelist.begin(); --i) 415 // if(sgraph.visible(*i,*j) && sgraph.saturated(*i)) 416 LViterator lvi(sgraph,j); 417 int i; 418 while((i=lvi.next()) >= 0) 419 if(sgraph.saturated(i)) 420 { 421 if(debug) {fprintf(stderr,"## %d <-- %d ... ",i,j); } 422 423 list<const Link*> ji_links = grammar.connectable2( sgraph.cat(j), sgraph.cat(i), sgraph[j].prop.flags, sgraph[i].prop.flags); // ref do Roles!!! 343 424 list<const Link*>::iterator ri = ji_links.begin(); 344 425 if(ri == ji_links.end()) { if(debug) fprintf(stderr,"no roles\n"); } … … 346 427 { 347 428 for(; ri != ji_links.end(); ++ri ) 348 if(!grammar.check_constr2(sgraph[ *j].prop,sgraph[*i].prop,0,**ri ))429 if(!grammar.check_constr2(sgraph[j].prop,sgraph[i].prop,0,**ri )) 349 430 { if(debug) fprintf(stderr,"constraints failed\n"); } 350 431 else 351 432 { 352 list<Boubble*> new_head_boubbles = collect_head_boubbles( *j,*i,(*ri)->role);353 list<Boubble*> new_dep_boubbles = collect_dep_boubbles( *j,*i,(*ri)->role);433 list<Boubble*> new_head_boubbles = collect_head_boubbles(j,i,(*ri)->role); 434 list<Boubble*> new_dep_boubbles = collect_dep_boubbles(j,i,(*ri)->role); 354 435 355 if( !(check_boubbles_at_target(new_head_boubbles, *j) && check_boubbles_at_target(new_dep_boubbles,*i)) )436 if( !(check_boubbles_at_target(new_head_boubbles,j) && check_boubbles_at_target(new_dep_boubbles,i)) ) 356 437 { if(debug) fprintf(stderr,"boubbles failed\n"); } 357 438 else … … 368 449 //---------------------------------------------------------------------------------------------------- 369 450 370 void try_connect_heads(list<int>::iterator j) 371 { 372 for(list<int>::iterator i(j); i!=nodelist.begin(); --i) 373 if(sgraph.visible(*i,*j)) 374 { 375 if(debug) fprintf(stderr, "## %d --> %d ... ",*i,*j); 376 377 list<const Link*> ij_links = grammar.connectable2( sgraph.cat(*i), sgraph.cat(*j), sgraph[*i].prop.flags, sgraph[*j].prop.flags ); 451 void try_connect_heads(int j) 452 { 453 // for(list<int>::iterator i(j); i!=nodelist.begin(); --i) 454 // if(sgraph.visible(*i,*j) && sgraph.saturated(*j)) 455 456 LViterator lvi(sgraph,j); 457 int i; 458 while((i=lvi.next()) >= 0) 459 if(sgraph.saturated(j)) 460 { 461 if(debug) fprintf(stderr, "## %d --> %d ... ",i,j); 462 463 list<const Link*> ij_links = grammar.connectable2( sgraph.cat(i), sgraph.cat(j), sgraph[i].prop.flags, sgraph[j].prop.flags ); 378 464 list<const Link*>::iterator ri = ij_links.begin(); 379 465 if(ri == ij_links.end()) { if(debug) fprintf(stderr,"no roles\n"); } … … 381 467 { 382 468 for(; ri != ij_links.end(); ++ri ) 383 if( !grammar.check_constr2( sgraph[ *i].prop, sgraph[*j].prop, 1, **ri ) )469 if( !grammar.check_constr2( sgraph[i].prop, sgraph[j].prop, 1, **ri ) ) 384 470 { if(debug) fprintf(stderr,"constraints failed\n"); } 385 471 else 386 472 { 387 list<Boubble*> new_head_boubbles = collect_head_boubbles( *i,*j,(*ri)->role);388 list<Boubble*> new_dep_boubbles = collect_dep_boubbles( *i,*j,(*ri)->role);473 list<Boubble*> new_head_boubbles = collect_head_boubbles(i,j,(*ri)->role); 474 list<Boubble*> new_dep_boubbles = collect_dep_boubbles(i,j,(*ri)->role); 389 475 390 if( !(check_boubbles_at_target(new_head_boubbles, *i) && check_boubbles_at_target(new_dep_boubbles,*j)) )476 if( !(check_boubbles_at_target(new_head_boubbles,i) && check_boubbles_at_target(new_dep_boubbles,j)) ) 391 477 { if(debug) fprintf(stderr,"boubbles failed\n"); } 392 478 else … … 399 485 } 400 486 } 401 487 488 //==================================================================================================== 489 490 void update_sets() 491 { 492 for(int n=0; n<sgraph.size(); ++n) 493 { 494 LViterator lvi(sgraph,n,false); 495 LHiterator lhi(sgraph,n); 496 LDiterator ldi(sgraph,n); 497 int i; 498 499 // printf("UPDATING LV[%d]:",n); 500 while((i=lvi.next())>=0) 501 { 502 // printf(" %d",i); 503 sgraph[n].LV.set(i); 504 } 505 // printf("\n"); 506 507 while((i=lhi.next())>=0) sgraph[n].LH.set(i); 508 while((i=ldi.next())>=0) sgraph[n].LD.set(i); 509 } 510 } 511 512 //==================================================================================================== 513 514 void print_sets(int n) 515 { 516 LViterator lvi(sgraph,n); 517 LHiterator lhi(sgraph,n); 518 LDiterator ldi(sgraph,n); 519 520 int i; 521 printf("LV[%d]: ",n); 522 while((i=lvi.next())>=0) 523 { 524 printf("%d ",i); 525 sgraph[n].LV.set(i); 526 } 527 528 printf("LH[%d]: ",n); 529 while((i=lhi.next())>=0) 530 { 531 printf("%d ",i); 532 sgraph[n].LH.set(i); 533 } 534 printf("LD[%d]: ",n); 535 while((i=ldi.next())>=0) 536 { 537 printf("%d ",i); 538 sgraph[n].LD.set(i); 539 } 540 printf("\n"); 541 } 542 402 543 //==================================================================================================== 403 544 … … 430 571 nodelist.push_back(basenode); 431 572 432 if(debug) {sgraph.print_node_debug(stderr,"B ",basenode,-1);} // STDOUT!!! 573 if(debug) sgraph.print_node_debug(stderr,"B ",basenode,-1); // STDOUT!!! 574 if(debug) print_sets(basenode); 433 575 434 576 list<int>::iterator cursor=processed; 435 577 while(++cursor != nodelist.end()) 436 578 { 437 try_connect_dependents(cursor); 438 try_connect_heads(cursor); 579 if(debug) sgraph.print_node_debug(stderr,"> ",*cursor,-1); 580 try_connect_dependents(*cursor); 581 try_connect_heads(*cursor); 439 582 processed=cursor; 440 583 } 441 584 442 585 } 443 reverse_links(); 444 } 586 // reverse_links(); 587 update_sets(); 588 } -
src/dgp/grammar.cc
ra15e59b r3b02b04 298 298 { 299 299 char cat1[MAXLINE],flags1[MAXLINE],cat2[MAXLINE],flags2[MAXLINE],type[MAXLINE],props[MAXLINE]; 300 301 if(sscanf(arg1,"%[^;];%s",cat1,flags1)==1) *flags1='\0'; 302 if(sscanf(arg2,"%[^;];%s",cat2,flags2)==1) *flags2='\0'; 303 if(sscanf(arg3,"%[^&]%s",type,props)==1) *props='\0'; 300 char* double_slash_position; 301 // pierwszy argument 302 // if(sscanf(arg1,"%[^;];%s",cat1,flags1)==1) *flags1='\0'; 303 if((double_slash_position=strstr(arg1,"//")) != NULL) // czy s± flagi 304 { 305 int cat_length=double_slash_position-arg1; 306 strncpy(cat1, arg1, cat_length); cat1[cat_length]='\0'; 307 strcpy(flags1, arg1+cat_length+2); 308 } 309 else 310 { 311 strcpy(cat1, arg1); 312 flags1[0]='\0'; 313 } 314 // drugi argument 315 // if(sscanf(arg2,"%[^;];%s",cat2,flags2)==1) *flags2='\0'; 316 if((double_slash_position=strstr(arg2,"//")) != NULL) // czy s± flagi 317 { 318 int cat_length=double_slash_position-arg2; 319 strncpy(cat2, arg2, cat_length); cat2[cat_length]='\0'; 320 strcpy(flags2, arg2+cat_length+2); 321 } 322 else 323 { 324 strcpy(cat2,arg2); 325 flags2[0]='\0'; 326 } 327 // trzeci argument 328 if(sscanf(arg3,"%[^&]%s",type,props)==1) props[0]='\0'; 304 329 305 // printf("line=%s\n\tcat1=%s flags1=%s cat2=%s flags2=%s type=%sprops=%s\n",line,cat1,flags1,cat2,flags2,type,props);330 // printf("line=%s\n\tcat1=<%s> flags1=%s cat2=<%s> flags2=%s type=<%s> props=%s\n",line,cat1,flags1,cat2,flags2,type,props); 306 331 307 332 if( chk_cat(cat1) && chk_cat(cat2) && chk_type(type) ) … … 346 371 347 372 // compute_gt(); 348 373 349 374 return true; 350 375 -
src/dgp/main.cc
ra15e59b r3b02b04 38 38 bool printtimeinfo=false; 39 39 40 40 41 void output(); 41 42 … … 43 44 { 44 45 gengetopt_args_info args; 46 struct timeval readgrammar_starttime,readgrammar_endtime; 45 47 46 48 if(cmdline_parser(argc,argv,&args) != 0) … … 71 73 } 72 74 75 gettimeofday(&readgrammar_starttime,NULL); 76 73 77 grammar.read(grammarf); 74 78 fclose(grammarf); 75 79 80 gettimeofday(&readgrammar_endtime,NULL); 76 81 82 if(printtimeinfo) 83 fprintf(stderr,"### START TIME: %10.2fms\n", (float)MICROSECONDSELAPSED(readgrammar_starttime,readgrammar_endtime)/1000 ); 77 84 85 //////////////////////////////////////////////////////////////////////////////////////////////////// 86 // TESTOWANIE POPRAWNOŠCI ODCZYTU GRAMATYKI 78 87 // grammar.write(cout); 79 88 // exit(0); 89 //////////////////////////////////////////////////////////////////////////////////////////////////// 80 90 81 91 struct timeval starttime,afterinput,afterparse,endtime; … … 101 111 { 102 112 gettimeofday(&afterinput,NULL); 113 103 114 dgp1(); // parametry!!! MGraph, SGraph, Grammar 115 104 116 gettimeofday(&afterparse,NULL); 105 117 output(); -
src/dgp/sgraph.cc
ra15e59b r3b02b04 28 28 newnode.in_LH=true; 29 29 30 newnode.edge.push_back(lastnodeind()); 31 30 32 return lastnodeind(); 31 33 } … … 55 57 SNode &newnode=makenewnode(); 56 58 SNode &ancnode = nodes[ancind]; 57 58 59 59 60 60 newnode.prop=newprop; … … 178 178 179 179 buf+=sprint_node(buf,n,anc,HEADS|DEPS|SETS|CONSTRAINTS); 180 181 buf+=sprintf(buf,"/"); 182 for(vector<int>::iterator e = nodes[n].edge.begin(); e != nodes[n].edge.end(); e++ ) 183 buf += sprintf(buf,"%d ", *e); 184 180 185 buf+=sprintf(buf,"\n"); 181 186 return buf-buf0; -
src/dgp/sgraph.hh
re7de6cc r3b02b04 7 7 #include <vector> 8 8 #include <bitset> 9 #include <stack> 9 10 10 11 #include "const.hh" … … 71 72 if(init_attached != p.init_attached) return false; 72 73 if(fin_attached != p.fin_attached) return false; 73 74 list<Boubble*>::const_iterator b1 = p.boubbles.begin(); 75 for(list<Boubble*>::const_iterator b = boubbles.begin(); b != boubbles.end(); b++) 76 { 77 if(b1 == p.boubbles.end()) 78 return false; 79 if(!(**b == **b1)) 80 return false; 81 } 82 if(b1 != p.boubbles.end()) 74 75 list<Boubble*>::const_iterator b,b1; 76 for(b=boubbles.begin(), b1=p.boubbles.begin(); b != boubbles.end() && b1 != p.boubbles.end(); b++,b1++) 77 if(!(**b == **b1)) 78 return false; 79 if(b != boubbles.end() || b1 != p.boubbles.end()) 83 80 return false; 84 81 85 82 return true; 86 83 } … … 172 169 { 173 170 171 SNode() { visible_as_neighbour = true; } 172 174 173 int mnode; 175 174 176 175 NodeProp prop; 176 177 vector<int> edge; 178 bool edge_contains_self; 179 bool visible_as_neighbour; 177 180 178 181 bitset<MAXNODES> LV; … … 231 234 int size() {return nodes.size(); } 232 235 236 friend class LViterator; 237 friend class LHiterator; 238 friend class LDiterator; 239 friend class LNiterator; 240 233 241 private: 234 242 … … 259 267 260 268 //---------------------------------------------------------------------------------------------------- 269 //---------------------------------------------------------------------------------------------------- 270 271 class XXiterator 272 { 273 protected: 274 275 bool checked(int i) { return _checked[i]; } 276 void check(int i) { _checked.set(i); } 277 278 void push(stack<int>& s, int i) 279 { 280 if(!checked(i)) 281 { 282 s.push(i); 283 check(i); 284 } 285 } 286 287 bitset<MAXNODES> _checked; 288 }; 289 290 //---------------------------------------------------------------------------------------------------- 291 //---------------------------------------------------------------------------------------------------- 292 293 class LViterator : public XXiterator 294 { 295 public: 296 LViterator(SGraph& sg, int n, bool s); 297 int next(); 298 299 private: 300 301 SGraph& sgraph; 302 MGraph& mgraph; 303 stack<int> waydown; 304 stack<int> wayup; 305 bool strict; 306 307 void push_ld(int i); 308 void push_lh(int i); 309 void push_ln(int i); 310 }; 311 312 inline LViterator::LViterator(SGraph& sg, int n, bool s=true) : sgraph(sg), mgraph(sg.mgraph), strict(s) 313 { 314 if(sg[n].edge_contains_self) // TO DODAÆ PO PRZEJŠCIU NA EDGE_CONTAINS_SELF 315 { 316 push_ld(n); 317 push_ln(n); 318 } 319 320 for(vector<int>::iterator i=sg[n].edge.begin(); i!=sg[n].edge.end(); ++i) 321 { 322 if(*i != n) 323 { 324 push_ld(*i); 325 push_ln(*i); 326 } 327 328 } 329 // if(!strict) 330 // { 331 // push_ld(n); 332 // push_ln(n); 333 // } 334 } 335 336 inline int LViterator::next() 337 { 338 if(wayup.empty()) 339 { 340 if(waydown.empty()) 341 return -1; // 342 else 343 { 344 int k = waydown.top(); 345 waydown.pop(); 346 push_ld(k); 347 push_ln(k); 348 if(wayup.empty()) 349 return -1; // k NIE MA POPRZEDNIKÓW, NIE MO¯E TE¯ ZATEM MIEÆ LEWOSTRONNYCH PODRZÊDNIKÓW 350 else 351 { 352 int i = wayup.top(); 353 wayup.pop(); 354 push_lh(i); 355 return i; 356 } 357 } 358 359 } 360 else 361 { 362 int i = wayup.top(); 363 wayup.pop(); 364 push_lh(i); 365 return i; 366 }; 367 } 368 369 inline void LViterator::push_ld(int i) 370 { 371 vector<Arc>& arcs = sgraph[i].deps; 372 for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 373 if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) 374 push(waydown,a->dst); 375 } 376 377 inline void LViterator::push_lh(int i) 378 { 379 vector<Arc>& arcs = sgraph[i].heads; 380 for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 381 if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) 382 push(wayup,a->dst); 383 } 384 385 inline void LViterator::push_ln(int i) 386 { 387 vector<int>& mpredecessors = mgraph[sgraph[i].mnode].pred; 388 for(vector<int>::iterator mp = mpredecessors.begin(); mp != mpredecessors.end(); ++mp) // poprzedniki w mgraph 389 { 390 vector<int>& spredecessors = mgraph[*mp].snodes; 391 for(vector<int>::iterator sp = spredecessors.begin(); sp != spredecessors.end(); ++sp ) 392 if(sgraph[*sp].visible_as_neighbour || !strict) 393 push(wayup,*sp); 394 } 395 } 396 397 398 //---------------------------------------------------------------------------------------------------- 399 //---------------------------------------------------------------------------------------------------- 400 401 class LNiterator 402 { 403 public: 404 LNiterator(SGraph& sg, int n); 405 406 int next(); 407 408 private: 409 410 SGraph& sgraph; 411 MGraph& mgraph; 412 int thenode; 413 stack<int> wayup; 414 415 void push_ln(int i); 416 }; 417 418 inline LNiterator::LNiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), thenode(n) 419 { 420 push_ln(n); 421 } 422 423 inline int LNiterator::next() 424 { 425 if(wayup.empty()) 426 return -1; 427 else 428 { 429 int i = wayup.top(); 430 wayup.pop(); 431 return i; 432 }; 433 } 434 435 inline void LNiterator::push_ln(int i) 436 { 437 vector<int>& mpredecessors = mgraph[sgraph[i].mnode].pred; 438 for(vector<int>::iterator mp = mpredecessors.begin(); mp != mpredecessors.end(); ++mp) // poprzedniki w mgraph 439 { 440 vector<int>& spredecessors = mgraph[*mp].snodes; 441 for(vector<int>::iterator sp = spredecessors.begin(); sp != spredecessors.end(); ++sp ) 442 wayup.push(*sp); 443 } 444 } 445 446 447 //---------------------------------------------------------------------------------------------------- 448 //---------------------------------------------------------------------------------------------------- 449 450 class LHiterator 451 { 452 public: 453 LHiterator(SGraph& sg, int n); 454 455 int next(); 456 457 private: 458 459 SGraph& sgraph; 460 MGraph& mgraph; 461 stack<int> wayup; 462 463 void push_lh(int i); 464 }; 465 466 inline LHiterator::LHiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph) 467 { 468 push_lh(n); 469 } 470 471 inline int LHiterator::next() 472 { 473 if(wayup.empty()) 474 return -1; 475 else 476 { 477 int i = wayup.top(); 478 wayup.pop(); 479 push_lh(i); 480 return i; 481 }; 482 } 483 484 inline void LHiterator::push_lh(int i) 485 { 486 vector<Arc>& arcs = sgraph[i].heads; 487 for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 488 if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) 489 wayup.push(a->dst); 490 } 491 492 //---------------------------------------------------------------------------------------------------- 493 //---------------------------------------------------------------------------------------------------- 494 495 class LDiterator 496 { 497 public: 498 LDiterator(SGraph& sg, int n); 499 500 int next(); 501 502 private: 503 504 SGraph& sgraph; 505 MGraph& mgraph; 506 int thenode; 507 stack<int> waydown; 508 509 void push_ld(int i); 510 }; 511 512 inline LDiterator::LDiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), thenode(n) 513 { 514 push_ld(n); 515 } 516 517 inline int LDiterator::next() 518 { 519 if(waydown.empty()) 520 return -1; 521 else 522 { 523 int k = waydown.top(); 524 waydown.pop(); 525 push_ld(k); 526 return k; 527 } 528 } 529 530 inline void LDiterator::push_ld(int i) 531 { 532 vector<Arc>& arcs = sgraph[i].deps; 533 for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 534 if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[thenode].mnode].pos) 535 waydown.push(a->dst); 536 } 537 538 261 539 262 540 #endif -
src/grp/grp
r5f4d9c3 r3b02b04 13 13 my $LIB_DIR="/usr/local/lib/utt"; 14 14 15 my $systemconfigfile="/ usr/local/etc/utt/grp.conf";15 my $systemconfigfile="/etc/utt/grp.conf"; 16 16 my $userconfigfile=home()."/.utt/grp.conf"; 17 17 -
src/tre/tre
re7de6cc r3b02b04 156 156 for t in trees 157 157 $count += 1 158 t1=ground(t) 158 # t1=ground(t) 159 160 t1=t 159 161 160 162 span = $FOREST ? " span:" + (ground_tree_min(t1).to_s + ","+ground_tree_max(t1).to_s)+";" : "" … … 170 172 when /h/ 171 173 print "#\n# tree #{$count}\n# ------\n" 172 printtree (t1[0],t1[1],0)174 printtree_dgp(t1[0],t1[1],0) 173 175 end 174 176 end … … 178 180 def nodeinfo(id) 179 181 info="" 182 gphid = $gphid[id] 180 183 if $INFO =~ /o/ 181 info += $ord1[ id].to_s184 info += $ord1[gphid].to_s + '/' + gphid.to_s + '/' + id.to_s 182 185 info += '.' if $INFO =~ /[nfm]/ 183 186 end 184 187 if $INFO =~ /n/ 185 info += id.to_s188 info += gphid.to_s 186 189 info += '.' if $INFO =~ /[fm]/ 187 190 end 188 191 if $INFO =~ /f/ 189 info += $form[ id]192 info += $form[gphid] 190 193 info += ';' if $INFO =~ /m/ 191 194 end 192 195 if $INFO =~ /m/ 193 info += $lem[ id]196 info += $lem[gphid] 194 197 end 195 198 info … … 215 218 print "%-16s" % (arc[2]+": ") 216 219 printtree(arc[1],arcs,o+1) 220 end 221 end 222 223 def printtree_dgp(root,arcs,o) 224 if o==0 225 print "%-16s" % "root: " 226 end 227 print nodeinfo(root),"\n" 228 for arc in arcs.select{ |a| a[0]==root }.sort{|a,b| a[1]<=>b[1] } 229 print " "*(o+1) 230 print "%-16s" % (arc[2]+": ") 231 printtree_dgp(arc[1],arcs,o+1) 217 232 end 218 233 end … … 341 356 def gentrees2 bos, eos 342 357 $thetrees=[]; 343 roots = ( 1...eos).select{|i| $vis.include? [i,eos]}.select{|i| $vis.include? [bos,i]}358 roots = (bos..eos).select{|i| $vis.include? [i,eos]}.select{|i| $vis.include? [bos,i]} 344 359 345 360 if $DEBUG then print "ROOTS: #{roots.inspect}\n" end … … 363 378 if $DEBUG then print "buildR--#{min}--#{max}--#{tree.inspect}\n" end 364 379 trees=[] 365 for a in $arcs.select{|a| a[0]==max && $vis.include?([min,a[1]]) } 366 if $DEBUG then print "ARC: #{a.inspect}\n" end 367 for r in buildR(a[4],a[3],tree+[a]) #!!! buildR(a[1],a[3],tree+[a]) 380 for arc in $arcs.select{|a| a[0]==max && $vis.include?([min,a[1]]) } 381 if $DEBUG then print "ARC: #{arc.inspect}\n" end 382 for r in buildR(arc[1],arc[0],tree+[arc]) #!!! buildR(a[1],a[3],tree+[a]) 383 # for r in buildR(arc[4],arc[3],tree+[arc]) #!!! buildR(a[1],a[3],tree+[a]) 368 384 (rmin,rmax,rarcs) = r 369 385 for l in buildR(min,rmin,rarcs) … … 395 411 for arc in $arcs.select{|a| a[1]==max && $lhs.include?([min,a[0]]) } 396 412 if $DEBUG then print "ARC: #{arc.inspect}\n" end 397 for r in buildR(arc[3],arc[4],tree+[arc]) ### buildR(arc[3],max,tree+[arc]) 413 for r in buildR(arc[0],arc[1],tree+[arc]) ### buildR(arc[3],max,tree+[arc]) 414 #for r in buildR(arc[3],arc[4],tree+[arc]) ### buildR(arc[3],max,tree+[arc]) 398 415 (rmin,rmax,rarcs) = r 399 416 for l in buildL(min,rmin,rarcs)
Note: See TracChangeset
for help on using the changeset viewer.