Changeset 3b02b04


Ignore:
Timestamp:
01/17/13 20:50:41 (11 years ago)
Author:
Tomasz Obrebski <to@…>
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)
Message:

prawie ca�kiem nowe dgc, du�e zmiany w dgp, pomniejsze poprawki

Files:
4 deleted
16 edited

Legend:

Unmodified
Added
Removed
  • conf/compdic.conf.m4

    rabd28d1 r3b02b04  
    99# 
    1010# All lines must looks like: 
    11 # parameter_name [=] value 
     11# parameter_name=value (BASH SYNTAX!) 
    1212# 
    13 symbols = LANG_DIR/LANGUAGE/LANGUAGE.sym 
     13symbols=LANG_DIR/LANGUAGE/LANGUAGE.sym 
     14dictionary_home=/home/to/dane/pmdbf 
  • conf/dgc.conf.m4

    rabd28d1 r3b02b04  
    1212# 
    1313categories = LANG_DIR/LANGUAGE/lem.bin.cats 
     14# categories = /home/to/dane/pmdbf/lem.cats 
    1415grammar = LANG_DIR/gram.dgc 
     16# grammar = /home/to/dane/grammar/gram.dgc 
    1517outputfile = LANG_DIR/gram.dgp 
     18# outputfile = /home/to/dane/grammar/gram.dgp 
  • conf/dgp.conf.m4

    rcfdf333 r3b02b04  
    1313 
    1414grammar = LANG_DIR/gram.dgp 
     15# grammar = /home/to/dane/grammar/gram.dgp 
    1516process = W 
    1617process = BOS 
  • conf/lem.conf.m4

    rabd28d1 r3b02b04  
    1212# 
    1313dictionary = LANG_DIR/LANGUAGE/lem.bin 
     14#dictionary = /home/to/dane/pmdbf/lem.bin 
    1415#dictionary-home = LANG_DIR 
    1516process = W 
  • lib/attr.pm

    r5f4d9c3 r3b02b04  
    1111our $av_re     = qr/(?:$attr_re$val_re+)/; 
    1212our $avlist_re = qr/(?:$av_re+)/; 
    13 our $cat_re    = qr/(?:$pos_re(?:\/$avlist_re)?)/; 
     13our $cat_re    = qr/(?:(?:$pos_re|\*)(?:\/$avlist_re)?)/; 
    1414 
    1515sub match(\@\@) 
  • share/Makefile

    rabd28d1 r3b02b04  
    99        install -m 0644 pl_PL.ISO-8859-2/gue.bin $(LANG_DIR)/pl_PL.ISO-8859-2 
    1010        install -m 0644 pl_PL.ISO-8859-2/lem.bin $(LANG_DIR)/pl_PL.ISO-8859-2 
    11         install -m 0644 pl_PL.ISO-8859-2/lem.bin.cats $(LANG_DIR)/pl_PL.ISO-8859-2 
     11        install -m 0644 pl_PL.ISO-8859-2/lem.fst $(LANG_DIR)/pl_PL.ISO-8859-2 
     12        install -m 0644 pl_PL.ISO-8859-2/lem.cats $(LANG_DIR)/pl_PL.ISO-8859-2 
    1213        install -m 0644 pl_PL.ISO-8859-2/pl_PL.ISO-8859-2.sym $(LANG_DIR)/pl_PL.ISO-8859-2 
    1314        install -m 0644 pl_PL.UTF-8/lem.bin $(LANG_DIR)/pl_PL.UTF-8 
     
    2324        rm $(LANG_DIR)/pl_PL.UTF-8/lem.bin 
    2425        rm $(LANG_DIR)/pl_PL.ISO-8859-2/pl_PL.ISO-8859-2.sym 
    25         rm $(LANG_DIR)/pl_PL.ISO-8859-2/lem.bin.cats 
     26        rm $(LANG_DIR)/pl_PL.ISO-8859-2/lem.cats 
    2627        rm $(LANG_DIR)/pl_PL.ISO-8859-2/lem.bin 
     28        rm $(LANG_DIR)/pl_PL.ISO-8859-2/lem.fst 
    2729        rm $(LANG_DIR)/pl_PL.ISO-8859-2/gue.bin 
    2830        rm $(LANG_DIR)/pl_PL.ISO-8859-2/cor.bin 
  • src/dgc/Makefile

    re7de6cc r3b02b04  
    77ifdef BIN_DIR 
    88        install -m 0755 dgc $(BIN_DIR) 
     9        install -m 0755 l2src $(BIN_DIR) 
    910endif 
    1011 
     
    1314ifdef BIN_DIR 
    1415        rm $(BIN_DIR)/dgc 
     16        rm $(BIN_DIR)/l2src 
    1517endif 
    1618 
  • src/dgc/dgc

    re7de6cc r3b02b04  
    99use lib "$ENV{'HOME'}/.local/lib/utt"; 
    1010 
    11 use strict; 
     11#use strict; 
    1212use Getopt::Long; 
    1313use Data::Dumper; 
    1414use attr; 
    1515use File::HomeDir; 
     16use Parse::RecDescent; 
     17 
     18$::RD_HINT=1; 
     19# use List::MoreUtils; 
    1620 
    1721my $systemconfigfile='/etc/utt/dgc.conf'; 
    18 my $userconfigfile=home()."/.utt/dgc.conf"; 
     22my $userconfigfile=0; #home()."/.utt/dgc.conf"; 
    1923 
    2024Getopt::Long::Configure('no_ignore_case_always'); 
     
    3135  if(open(CONFIG, $file)){ 
    3236        while (<CONFIG>) { 
    33                 chomp; 
    34                 s/#.*//; 
    35                 s/^\s+//; 
    36                 s/\s+$//; 
     37                chomp; s/#.*//; s/^\s+//; s/\s+$//; 
    3738                next unless length; 
    3839                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; } 
    5445 
    5546        } 
     
    9081die("At least one of --cats and --dic must be given.\n") if !$catfile && !$dicfile; 
    9182 
    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 
     84our %in;      #gramatyka wej¶ciowa 
     85our %idx;     #indeks gramatyki wej¶ciowej (niektóre stwierdzenia) 
     86our %out;     #gramatyka wyj¶ciowa 
     87our %class;   #tablica klas 
     88 
     89our $attr_re       = $attr::attr_re; 
     90our $cat_re        = $attr::cat_re; 
     91our $cats_re       = qr/(?:$attr::cat_re\s*(?:,\s*$attr::cat_re)*)/; 
     92our $class_re      = qr/(?:\@\w+)/; 
     93our $av_re         = $attr::av_re; 
     94our $avlist_re     = $attr::avlist_re; 
     95our $role_re       = qr/(?:[[:lower:][:digit:]_]+)/; 
     96our $prop_re       = qr/(?:[[:upper:]]+)/; 
     97our $proplist_re   = qr/(?:(?:\&$prop_re)+)/; 
     98 
     99my $inputlineno=0; 
     100 
     101our $statementgrammar = q( 
     102 
     103statement : statement1 ";" { $item[1] } 
     104 
     105statement1: /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 
     133acat:       /$attr::cat_re/ 
     134 
     135attr:       /$attr::attr_re/ 
     136 
     137xcat:       classexpr 
     138 
     139role:       /\w+/ 
     140 
     141flag:       /\w+/ 
     142 
     143optflags:   "//" flagconstr { $item[2] } 
     144 
     145flagconstr: /\w+[+-]/ 
     146 
     147prop:       '&' /\w+/ { $item[2] } 
     148 
     149classname:  /\$\w+[+-]/ 
     150 
     151classexpr  : classexpr1 '|' classexpr   { main::union($item[1],$item[3]) } 
     152           | classexpr1 '~' classexpr   { main::intersection( $item[1], main::complement($item[3]) ) } 
     153           | classexpr1 
     154 
     155classexpr1 : classexpr2 '&' classexpr1  { main::intersection($item[1],$item[3]) } 
     156           | classexpr2 
     157 
     158classexpr2 : '~' classexpr2            { main::complement($item[2]) } 
     159           | classexpr3 
     160 
     161classexpr3 : classexpr4 '/' /$attr::avlist_re/  { main::intersection($item[1], [main::extension('*/' . $item[3])] ) } 
     162           | classexpr4 
     163 
     164classexpr4 : class 
     165           | cat 
     166           | '(' classexpr ')'          { $item[2] } 
     167 
     168class :    classname                    { $main::class{$item[1]} or @{[]} } 
     169 
     170cat :      /$main::cat_re/              { [main::extension($item[1])] } 
     171 
     172); 
     173 
     174our $statementparser = Parse::RecDescent->new($statementgrammar); 
     175 
     176sub 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 
     188if(!$outputfile)          { *OUTPUT = *STDOUT; } 
     189elsif($outputfile eq "-") { *OUTPUT = *STDOUT; } 
     190else                      { open(OUTPUT, ">$outputfile") or die("Can't open output file: $outputfile!"); } 
     191 
     192if(!$gramfile)            { *INPUT = *STDIN; } 
     193elsif($gramfile eq "-")   { *INPUT = *STDIN; } 
     194else                      { open(INPUT, "cat $gramfile | m4 |") or die("Unable to open: $gramfile!"); } 
     195 
     196# *INPUT = *STDIN; ############### TYMCZASOWO 
    127197 
    128198loadcats($catfile) if $catfile; 
     
    130200 
    131201 
    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 
    154203 
    155204while(<INPUT>) 
    156205{ 
     206    $inputlineno++; 
    157207    s/#.*//; 
    158208    s/^\s+//; 
    159209    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 
     223my $inline = 0; 
     224my $outline = 0; 
     225 
     226 
     227# print Dumper($idx{gov}->{subj}); 
     228 
     229 
     230for my $x (@{$in{cat}})    { print_outin("CAT $x->{cat}", $x); } 
     231 
     232for my $x (@{$in{flag}})   { print_outin("FLAG $x->{flag}", $x); } 
     233 
     234for my $x (@{$in{role}})   { print_outin("ROLE $x->{role}", $x); } 
     235 
     236for my $x (@{$in{long}})    { print_outin("LONG $x->{rel} " . join(",",@{$x->{up}}) . "^" . join(",",@{$x->{down}}), $x) } 
     237 
     238for my $x (@{$in{left}})   { print_outin("LEFT $x->{role}", $x)  if chk_role($x->{role}, $x) } 
     239 
     240for my $x (@{$in{right}})  { print_outin("RIGHT $x->{role}", $x) if chk_role($x->{role}, $x) } 
     241 
     242for my $x (@{$in{sgl}})    { print_outin("SGL $x->{role}", $x)   if chk_role($x->{role}, $x) } 
     243 
     244for my $x (@{$in{req}}) 
     245{ 
     246    if( chk_role($x->{role}, $x) ) 
    161247    { 
    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}}) 
    183249        { 
    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); 
    189251        } 
    190252    } 
    191     elsif(/^LEFT\s+\S+$/) 
     253} 
     254 
     255for my $x (@{$in{initr}}) { print_outin("INITR $x->{role}", $x)    if chk_role($x->{role}, $x) } 
     256 
     257for my $x (@{$in{finr}}) { print_outin("FINR $x->{role}", $x)      if chk_role($x->{role}, $x) } 
     258 
     259for my $x (@{$in{initf}}) { print_outin("INITF $x->{flag}", $x) } # SPRAWDZIÆ CZY FLAGA JEST ZADEKLAROWANA 
     260 
     261for my $x (@{$in{finf}}) { print_outin("FINF $x->{flag}", $x); } # SPRAWDZIÆ CZY FLAGA JEST ZADEKLAROWANA 
     262 
     263for my $x (@{$in{set}}) 
     264{ 
     265    for my $atomcat (map{$_->{cat}} @{$x->{cats}}) 
    192266    { 
    193         ++$nleft; 
    194         print OUTPUT "$_\n"; 
     267        print_outin("SET $atomcat $x->{flag}", $x); 
     268    }    
     269} 
     270 
     271for my $x (@{$in{pass}})    { print_outin("PASS $x->{role} $x->{flag}", $x); } 
     272 
     273for my $x (@{$in{constre}}) { print_outin("CONSTRE $x->{role1} $x->{role2}", $x) if chk_role($x->{role1}, $x) & chk_role($x->{role2}, $x) } 
     274 
     275for my $x (@{$in{constri}}) { print_outin("CONSTRI $x->{role1} $x->{role2}", $x) if chk_role($x->{role1}, $x) & chk_role($x->{role2}, $x) } 
     276 
     277for 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        } 
    195298    } 
    196     elsif(/^RIGHT\s+\S+$/) 
     299} 
     300 
     301 
     302sub chk_role 
     303{ 
     304    ($role, $statement_details) = @_; 
     305    if($idx{role}{$role}) { 1; } else { print_error("undefined role", $statement_details); 0; } 
     306} 
     307 
     308sub 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 
     316sub 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 
     325sub extractcats 
     326{ 
     327    my $file = shift; 
     328    open DICFILE, "$file"; 
     329    while(<DICFILE>) 
    197330    { 
    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        } 
    200338    } 
    201     elsif(/^INIT\s+[[:lower:]]\S*$/) 
     339    close DICFILE; 
     340} 
     341 
     342 
     343sub loadcats 
     344{ 
     345    my $file = shift; 
     346    open CATFILE, "$file"; 
     347    while(<CATFILE>) 
    202348    { 
    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($_)},                 $_); 
    206353    } 
    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 
     357sub extension 
     358{ 
     359    my $cat = shift; 
     360    my $catexp = attr::parse($cat); 
     361    grep { attr::match(@{$_->{catexp}},@{$catexp}) } @{$in{cat}}; 
     362} 
     363 
     364sub uniq  { my %seen; grep { ! $seen{$_}++ } @_ } 
     365sub union { [ uniq( map { @{$_} } @_ ) ] } 
     366sub intersection { my $n=@_; my %seen; [ grep { ++$seen{$_} == $n } map { @{$_} } @_ ] } 
     367sub 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 
    227504    # elsif(/^INIT\s+([[:upper:]]\S*)$/) 
    228505    # { 
     
    251528    #   } 
    252529    # } 
    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 komentarze 
    339         } 
    340         else 
    341     { 
    342         print STDERR "Illegal format: $_\n"; 
    343     } 
    344 } 
    345  
    346  
    347 sub addlinks 
    348 { 
    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 addlinks1 
    385 { 
    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 extractcats 
    441 { 
    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 loadcats 
    460 { 
    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  
    2626  Boubble(list<Role> u, list<Role> d, LongRel l, int s=-1); 
    2727  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; }; 
    2829 
    2930  Dir dir(); 
     
    138139    } 
    139140   
    140   if(d==DOWN && _upath.empty() && !_dpath.empty()) 
     141  if(d==DOWN && _upath.empty() && !_dpath.empty() && _dpath.front() == r) 
    141142    { 
    142143      Boubble* newboubble = new Boubble(_upath,_dpath,_rel,_src); 
  • src/dgp/dgp1.cc

    ra15e59b r3b02b04  
    1010list<int> nodelist; 
    1111list<int>::iterator processed; 
     12 
     13 
     14void print_sets(int n); 
     15 
    1216 
    1317//==================================================================================================== 
     
    4448  ret.forbidden |= grammar.constr_exclude(link.role); 
    4549 
    46   ret.boubbles=bs; 
     50  ret.boubbles.merge(bs); //DOBRZE 
    4751  ret.flags |= ( depflags & grammar.pass_flags(link.role) ); 
    4852 
     
    5862{ 
    5963  NodeProp ret=depprop; 
    60   ret.boubbles=bs; 
     64  ret.boubbles.merge(bs); //DOBRZE 
    6165  return ret; 
    6266} 
     
    6771{ 
    6872  MNode& mnode = mgraph[mnodeind]; 
     73  int ret=-1; 
    6974  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; 
    7291} 
    7392 
     
    83102        ret.push_back(new_boubble); 
    84103    } 
     104 
    85105  return ret; 
    86106} 
     
    120140//==================================================================================================== 
    121141 
    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); 
     142void copy_links(int i, int j) 
     143{ 
     144  sgraph[j].heads = sgraph[i].heads; 
     145  sgraph[j].deps = sgraph[i].deps; 
     146} 
     147 
     148 
     149void 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 
     160int 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); 
    127166  sgraph[newheadind].LH=newheadLH; 
    128167  sgraph[newheadind].LD = newheadLD; 
    129168  sgraph[newheadind].in_LH=true; 
    130169  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); 
    134176  return newheadind; 
    135177} 
    136178 
    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); 
     179int 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); 
    142185  sgraph[newind].LH.reset(); 
    143186  sgraph[newind].LD=LD; 
    144187  sgraph[newind].in_LH=false; //??????? 
    145188  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); 
    148195   
    149196  return newind; 
    150197} 
    151198 
    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); 
     199int 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); 
    157205  sgraph[newheadind].LH=newheadLH; 
    158206  sgraph[newheadind].LD=newheadLD; 
     
    160208  sgraph[newheadind].LV=newheadLV; 
    161209   
    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); 
    163215   
    164216  return newheadind; 
    165217} 
    166218 
    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); 
     219int 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); 
    172223  sgraph[newind].LH=LH; 
    173224  sgraph[newind].LD=LD; 
     
    175226  sgraph[newind].LV.reset(); 
    176227   
    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); 
    178233   
    179234  return newind; 
     
    182237//==================================================================================================== 
    183238 
    184 void connect_left(list<int>::iterator h, list<int>::iterator d, 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; 
     239void 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; 
    189244 
    190245  NodeProp newheadprop  = compute_head_prop(oldheadprop,l,new_head_boubbles,olddepprop.flags); 
     
    192247  int newheadind; 
    193248  if(oldheadprop==newheadprop) 
    194     newheadind = *h; 
     249    newheadind = h; 
    195250  else 
    196251  { 
    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 
    203260      sgraph[newheadind].LD |= newheadLD; 
    204261    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     
    206268  } 
    207269 
    208  
    209  
    210270  NodeProp newdepprop = compute_dep_prop(olddepprop,l,new_dep_boubbles); 
    211271 
     
    213273   
    214274  if(olddepprop==newdepprop) 
    215     newdepind = *d; 
     275    newdepind = d; 
    216276  else 
    217277  { 
    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 
    224284      sgraph[newdepind].LD |= newdepLD; // TYLKO DLA LD 
    225285    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      } 
    227292  } 
    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); 
    239309} 
    240310 
    241311//---------------------------------------------------------------------------------------------------- 
    242312 
    243 void connect_right(list<int>::iterator h, list<int>::iterator d, 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); 
     313void 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); 
    248318 
    249319  int newheadind; 
    250320   
    251321  if(oldheadprop==newheadprop) 
    252     newheadind = *h; 
     322    newheadind = h; 
    253323  else 
    254324  { 
    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 
    261334      sgraph[newheadind].LD |= newheadLD; // TYLKO DLA LD 
    262335    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      } 
    264342  } 
    265343 
    266   NodeProp &olddepprop = sgraph[*d].prop; 
     344  NodeProp &olddepprop = sgraph[d].prop; 
    267345  NodeProp newdepprop = compute_dep_prop(olddepprop,l,new_dep_boubbles); 
    268346 
     
    270348   
    271349  if(olddepprop==newdepprop) 
    272     newdepind = *d; 
     350    newdepind = d; 
    273351  else 
    274352  { 
    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 
    281362      sgraph[newdepind].LD |= newdepLD; // TYLKO DLA LD 
    282363    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      } 
    284369  } 
    285370 
    286371 
    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); 
    290375 
    291376  sgraph[newdepind].LH.set(newheadind); 
     
    296381 
    297382  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); 
    300385   
    301386} 
     
    323408} 
    324409 
    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 
     412void 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!!! 
    343424      list<const Link*>::iterator ri = ji_links.begin(); 
    344425      if(ri == ji_links.end()) { if(debug) fprintf(stderr,"no roles\n"); } 
     
    346427        { 
    347428          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 )) 
    349430              { if(debug) fprintf(stderr,"constraints failed\n"); } 
    350431            else 
    351432              { 
    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); 
    354435                 
    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)) ) 
    356437                  { if(debug) fprintf(stderr,"boubbles failed\n"); } 
    357438                else 
     
    368449//---------------------------------------------------------------------------------------------------- 
    369450 
    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 ); 
     451void 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 ); 
    378464      list<const Link*>::iterator ri = ij_links.begin(); 
    379465      if(ri == ij_links.end()) { if(debug) fprintf(stderr,"no roles\n"); } 
     
    381467        { 
    382468          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 ) ) 
    384470              { if(debug) fprintf(stderr,"constraints failed\n"); } 
    385471            else 
    386472              { 
    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); 
    389475                 
    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)) ) 
    391477                  { if(debug) fprintf(stderr,"boubbles failed\n"); } 
    392478                else 
     
    399485    } 
    400486} 
    401    
     487 
     488//==================================================================================================== 
     489 
     490void 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 
     514void 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 
    402543//==================================================================================================== 
    403544 
     
    430571    nodelist.push_back(basenode); 
    431572 
    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); 
    433575 
    434576    list<int>::iterator cursor=processed; 
    435577    while(++cursor != nodelist.end()) 
    436578    { 
    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); 
    439582      processed=cursor; 
    440583    } 
    441584 
    442585  } 
    443   reverse_links(); 
    444 } 
     586   // reverse_links(); 
     587  update_sets(); 
     588} 
  • src/dgp/grammar.cc

    ra15e59b r3b02b04  
    298298        {  
    299299          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'; 
    304329           
    305           //      printf("line=%s\n\tcat1=%s flags1=%s cat2=%s flags2=%s type=%s props=%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); 
    306331 
    307332          if( chk_cat(cat1) && chk_cat(cat2) && chk_type(type) ) 
     
    346371   
    347372  //   compute_gt(); 
    348    
     373 
    349374  return true; 
    350375   
  • src/dgp/main.cc

    ra15e59b r3b02b04  
    3838bool printtimeinfo=false; 
    3939 
     40 
    4041void output(); 
    4142 
     
    4344{ 
    4445  gengetopt_args_info args; 
     46  struct timeval readgrammar_starttime,readgrammar_endtime; 
    4547 
    4648  if(cmdline_parser(argc,argv,&args) != 0) 
     
    7173    } 
    7274 
     75  gettimeofday(&readgrammar_starttime,NULL); 
     76 
    7377  grammar.read(grammarf); 
    7478  fclose(grammarf); 
    7579 
     80  gettimeofday(&readgrammar_endtime,NULL); 
    7681 
     82  if(printtimeinfo) 
     83    fprintf(stderr,"### START  TIME: %10.2fms\n", (float)MICROSECONDSELAPSED(readgrammar_starttime,readgrammar_endtime)/1000 ); 
    7784 
     85//////////////////////////////////////////////////////////////////////////////////////////////////// 
     86// TESTOWANIE POPRAWNOŠCI ODCZYTU GRAMATYKI 
    7887  // grammar.write(cout); 
    7988  // exit(0); 
     89//////////////////////////////////////////////////////////////////////////////////////////////////// 
    8090 
    8191  struct timeval starttime,afterinput,afterparse,endtime; 
     
    101111    { 
    102112      gettimeofday(&afterinput,NULL); 
     113       
    103114      dgp1(); // parametry!!! MGraph, SGraph, Grammar 
     115 
    104116      gettimeofday(&afterparse,NULL); 
    105117      output(); 
  • src/dgp/sgraph.cc

    ra15e59b r3b02b04  
    2828  newnode.in_LH=true; 
    2929 
     30  newnode.edge.push_back(lastnodeind()); 
     31 
    3032  return lastnodeind(); 
    3133} 
     
    5557  SNode &newnode=makenewnode(); 
    5658  SNode &ancnode = nodes[ancind]; 
    57  
    58  
    5959 
    6060  newnode.prop=newprop; 
     
    178178 
    179179  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 
    180185  buf+=sprintf(buf,"\n"); 
    181186  return buf-buf0; 
  • src/dgp/sgraph.hh

    re7de6cc r3b02b04  
    77#include <vector> 
    88#include <bitset> 
     9#include <stack> 
    910 
    1011#include "const.hh" 
     
    7172  if(init_attached != p.init_attached) return false; 
    7273  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()) 
    8380    return false; 
    84    
     81 
    8582  return true; 
    8683} 
     
    172169{ 
    173170   
     171  SNode() { visible_as_neighbour = true; } 
     172 
    174173  int mnode; 
    175174 
    176175  NodeProp prop; 
     176 
     177  vector<int> edge; 
     178  bool        edge_contains_self; 
     179  bool visible_as_neighbour; 
    177180 
    178181  bitset<MAXNODES> LV; 
     
    231234  int size()              {return nodes.size(); } 
    232235 
     236  friend class LViterator; 
     237  friend class LHiterator; 
     238  friend class LDiterator; 
     239  friend class LNiterator; 
     240 
    233241private: 
    234242 
     
    259267 
    260268//---------------------------------------------------------------------------------------------------- 
     269//---------------------------------------------------------------------------------------------------- 
     270 
     271class XXiterator 
     272{ 
     273protected: 
     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 
     293class LViterator : public XXiterator 
     294{ 
     295public: 
     296  LViterator(SGraph& sg, int n, bool s); 
     297  int next(); 
     298 
     299private: 
     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 
     312inline 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 
     336inline 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 
     369inline 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 
     377inline 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 
     385inline 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 
     401class LNiterator 
     402{ 
     403public: 
     404  LNiterator(SGraph& sg, int n); 
     405 
     406  int next(); 
     407 
     408private: 
     409 
     410  SGraph& sgraph; 
     411  MGraph& mgraph; 
     412  int thenode; 
     413  stack<int> wayup; 
     414 
     415  void push_ln(int i); 
     416}; 
     417 
     418inline LNiterator::LNiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), thenode(n) 
     419{ 
     420  push_ln(n); 
     421} 
     422 
     423inline 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 
     435inline 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 
     450class LHiterator 
     451{ 
     452public: 
     453  LHiterator(SGraph& sg, int n); 
     454 
     455  int next(); 
     456 
     457private: 
     458 
     459  SGraph& sgraph; 
     460  MGraph& mgraph; 
     461  stack<int> wayup; 
     462 
     463  void push_lh(int i); 
     464}; 
     465 
     466inline LHiterator::LHiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph) 
     467{ 
     468  push_lh(n); 
     469} 
     470 
     471inline 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 
     484inline 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 
     495class LDiterator 
     496{ 
     497public: 
     498  LDiterator(SGraph& sg, int n); 
     499 
     500  int next(); 
     501 
     502private: 
     503 
     504  SGraph& sgraph; 
     505  MGraph& mgraph; 
     506  int thenode; 
     507  stack<int> waydown; 
     508 
     509  void push_ld(int i); 
     510}; 
     511 
     512inline LDiterator::LDiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), thenode(n) 
     513{ 
     514  push_ld(n); 
     515} 
     516 
     517inline 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 
     530inline 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 
    261539 
    262540#endif 
  • src/grp/grp

    r5f4d9c3 r3b02b04  
    1313my $LIB_DIR="/usr/local/lib/utt"; 
    1414 
    15 my $systemconfigfile="/usr/local/etc/utt/grp.conf"; 
     15my $systemconfigfile="/etc/utt/grp.conf"; 
    1616my $userconfigfile=home()."/.utt/grp.conf"; 
    1717 
  • src/tre/tre

    re7de6cc r3b02b04  
    156156  for t in trees 
    157157    $count += 1 
    158     t1=ground(t) 
     158    # t1=ground(t) 
     159 
     160    t1=t 
    159161 
    160162    span = $FOREST ? " span:" + (ground_tree_min(t1).to_s + ","+ground_tree_max(t1).to_s)+";" : "" 
     
    170172    when /h/ 
    171173      print "#\n# tree #{$count}\n# ------\n" 
    172       printtree(t1[0],t1[1],0) 
     174      printtree_dgp(t1[0],t1[1],0) 
    173175    end 
    174176  end 
     
    178180def nodeinfo(id) 
    179181  info="" 
     182  gphid = $gphid[id] 
    180183  if $INFO =~ /o/ 
    181     info += $ord1[id].to_s                            
     184    info += $ord1[gphid].to_s + '/' + gphid.to_s + '/' + id.to_s 
    182185    info += '.' if $INFO =~ /[nfm]/ 
    183186  end 
    184187  if $INFO =~ /n/ 
    185     info += id.to_s                            
     188    info += gphid.to_s                            
    186189    info += '.' if $INFO =~ /[fm]/ 
    187190  end 
    188191  if $INFO =~ /f/ 
    189     info += $form[id]  
     192    info += $form[gphid]  
    190193    info += ';' if $INFO =~ /m/ 
    191194  end 
    192195  if $INFO =~ /m/ 
    193     info += $lem[id]   
     196    info += $lem[gphid]   
    194197  end 
    195198  info 
     
    215218    print "%-16s" % (arc[2]+": ") 
    216219    printtree(arc[1],arcs,o+1) 
     220  end 
     221end 
     222 
     223def 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) 
    217232  end 
    218233end 
     
    341356def gentrees2 bos, eos 
    342357  $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]} 
    344359 
    345360  if $DEBUG then print "ROOTS: #{roots.inspect}\n" end 
     
    363378  if $DEBUG then print "buildR--#{min}--#{max}--#{tree.inspect}\n" end 
    364379  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]) 
    368384      (rmin,rmax,rarcs) = r 
    369385      for l in buildR(min,rmin,rarcs) 
     
    395411  for arc in $arcs.select{|a| a[1]==max && $lhs.include?([min,a[0]]) } 
    396412    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]) 
    398415      (rmin,rmax,rarcs) = r 
    399416      for l in buildL(min,rmin,rarcs) 
Note: See TracChangeset for help on using the changeset viewer.