Changeset acbabee


Ignore:
Timestamp:
12/17/14 12:13:11 (9 years ago)
Author:
Tomasz Obrebski <obrebski@…>
Branches:
master
Children:
854bece
Parents:
d484a32
git-author:
Tomasz Obrebski <obrebski@…> (12/17/14 12:10:45)
git-committer:
Tomasz Obrebski <obrebski@…> (12/17/14 12:13:11)
Message:

many changes, mainly dgp1 algorithm

Files:
3 added
7 edited

Legend:

Unmodified
Added
Removed
  • src/compdic/compdic-dic-to-fst

    rf600a02 racbabee  
    22 
    33no_of_parts=0 
     4part_size=100000 
    45 
    56while [ $# -gt 2 ] 
     
    3738if [ $no_of_parts -eq 0 ] 
    3839then 
    39     no_of_parts=$(( `cat $1 | wc -l` / 75000 + 1 )) 
     40    no_of_parts=$(( `cat $1 | wc -l` / $part_size + 1 )) 
    4041fi 
    4142 
  • src/dgp/dgp1.cc

    rd484a32 racbabee  
    22using namespace std; 
    33 
    4 #include "dgp0.hh" 
     4#include "dgp1.hh" 
    55#include "global.hh" 
    66 
     
    7171//==================================================================================================== 
    7272 
    73 int find_existing_node(int mnodeind, NodeProp p, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLV) 
    74 { 
    75   MNode& mnode = mgraph[mnodeind]; 
    76   int ret=-1; 
    77   for(vector<int>::iterator ps=mnode.snodes.begin(); ps!=mnode.snodes.end(); ++ps) 
    78     { 
    79       if(debug) fprintf(stderr,"#find existing node: checking %d ... \n", *ps); 
    80       if(sgraph[*ps].prop==p) 
    81         if(sgraph[*ps].LH==newheadLH && sgraph[*ps].LV==newheadLV) 
    82           { 
    83             ret = *ps; 
    84             if(debug) fprintf(stderr,"#\tsucceeded because of LH/LV equality ()\n"); 
    85           } 
    86         else 
    87           { 
    88             if(debug) fprintf(stderr,"#\tfailed beacause of LH/LV inequality\n"); 
    89           } 
    90     } 
    91  
    92   if(debug) fprintf(stderr,"\n"); 
    93   return ret; 
     73int find_existing_node(int mnode, NodeProp p, Edge e) 
     74{ 
     75  for(vector<int>::iterator i = mgraph[mnode].snodes.begin(); i!=mgraph[mnode].snodes.end(); ++i) 
     76    if(sgraph[*i].prop==p && sgraph[*i].edge==e) 
     77      {  
     78        if(debug) fprintf(stderr,"\t\treusing %d\n",*i); 
     79        return *i; 
     80      } 
     81  return -1; 
    9482} 
    9583 
     
    161149//==================================================================================================== 
    162150 
    163 int create_new_head_node_left(int anc, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV) 
    164 { 
    165   int newheadind = sgraph.clone(anc,prop); 
     151int create_new_node(int anc, NodeProp& prop, Edge edge) 
     152{ 
     153  int newheadind = sgraph.clone(anc,prop,edge); 
    166154  nodelist.push_back(newheadind); 
    167   sgraph[newheadind].LH = LH; 
    168   sgraph[newheadind].LD = LD; 
    169   sgraph[newheadind].in_LH = true; 
    170   sgraph[newheadind].LV.reset(); 
    171  
    172155  copy_links(anc,newheadind); 
    173156  create_reverse_links(newheadind); 
    174    
    175   if(debug) sgraph.print_node_debug(stderr,"add new",newheadind,anc); 
     157  if(debug) sgraph.print_node_debug(stderr,"clone",newheadind,anc); 
    176158  // if(debug) print_sets(newheadind); 
    177159  return newheadind; 
    178160} 
    179161 
    180 int create_new_dep_node_left(int anc, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV) 
    181 { 
    182   int newind = sgraph.clone(anc,prop); 
    183   nodelist.push_back(newind); 
    184   sgraph[newind].LH.reset(); 
    185   sgraph[newind].LD=LD; 
    186   sgraph[newind].in_LH=false; //??????? 
    187   sgraph[newind].LV.reset(); 
    188  
    189   copy_links(anc,newind); 
    190   create_reverse_links(newind); 
    191    
    192   if(debug) sgraph.print_node_debug(stderr,"add new",newind,anc); 
    193   // if(debug) print_sets(newind); 
    194    
    195   return newind; 
    196 } 
    197  
    198 int create_new_head_node_right(int anc, NodeProp& prop, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLD, bitset<MAXNODES>& newheadLV) 
    199 { 
    200   int newheadind = sgraph.clone(anc,prop); 
    201   nodelist.push_back(newheadind); 
    202   sgraph[newheadind].LH=newheadLH; 
    203   sgraph[newheadind].LD=newheadLD; 
    204   sgraph[newheadind].in_LH=false; 
    205   sgraph[newheadind].LV=newheadLV; 
    206    
    207   copy_links(anc,newheadind); 
    208   create_reverse_links(newheadind); 
    209  
    210   if(debug) sgraph.print_node_debug(stderr,"add new",newheadind,anc); 
    211   // if(debug) print_sets(newheadind); 
    212    
    213   return newheadind; 
    214 } 
    215  
    216 int create_new_dep_node_right(int anc, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV) 
    217 { 
    218   int newind = sgraph.clone(anc,prop); 
    219   nodelist.push_back(newind); 
    220   sgraph[newind].LH=LH; 
    221   sgraph[newind].LD=LD; 
    222   sgraph[newind].in_LH=true; //??????? 
    223   sgraph[newind].LV.reset(); 
    224    
    225   copy_links(anc,newind); 
    226   create_reverse_links(newind); 
    227  
    228   if(debug) sgraph.print_node_debug(stderr,"ADD NEW",newind,anc); 
    229   // if(debug) print_sets(newind); 
    230    
    231   return newind; 
    232 } 
    233  
    234162//==================================================================================================== 
    235163 
     
    237165{ 
    238166 
    239   NodeProp &oldheadprop = sgraph[h].prop; 
    240   NodeProp &olddepprop = sgraph[d].prop; 
    241  
    242   NodeProp newheadprop  = compute_head_prop(oldheadprop,l,new_head_boubbles,olddepprop.flags); 
    243    
    244   int newheadind; 
    245   if(oldheadprop==newheadprop) 
    246     newheadind = h; 
    247   else 
    248   { 
    249     bitset<MAXNODES> newheadLH = sgraph[h].LH; 
    250     bitset<MAXNODES> newheadLV = sgraph[d].LV; 
    251     bitset<MAXNODES> newheadLD = sgraph[h].LD; 
    252  
    253     newheadind = find_existing_node(sgraph[h].mnode, newheadprop, newheadLH, newheadLV); 
    254     if( newheadind >= 0) // W£¡CZONE 
    255       sgraph[newheadind].LD |= newheadLD; 
    256     else 
     167  NodeProp &old_head_prop = sgraph[h].prop; 
     168  NodeProp &old_dep_prop = sgraph[d].prop; 
     169  NodeProp new_head_prop  = compute_head_prop(old_head_prop,l,new_head_boubbles,old_dep_prop.flags); 
     170  NodeProp new_dep_prop = compute_dep_prop(old_dep_prop,l,new_dep_boubbles); 
     171   
     172  Edge new_dep_edge(sgraph[d].edge); 
     173  int newd = find_existing_node(sgraph[d].mnode, new_dep_prop, new_dep_edge); 
     174  if( newd < 0  ) 
     175    newd = create_new_node(d,new_dep_prop,new_dep_edge); 
     176   
     177  Edge new_head_edge(sgraph[newd].edge,newd); 
     178  int newh = find_existing_node(sgraph[h].mnode, new_head_prop, new_head_edge); 
     179  if( newh < 0 ) 
     180    newh = create_new_node(h,new_head_prop,new_head_edge); 
     181     
     182  sgraph[newh].deps.push_back(Arc(newd,l.role,h,d)); 
     183  sgraph[newd].heads.push_back(Arc(newh,l.role,h,d)); 
     184 
     185  if(debug) 
     186    { 
     187      sgraph.print_arc(stderr,"link",newh,d,l.role,0); 
     188      sgraph.print_node_debug(stderr,"",newh,h); 
     189      sgraph.print_node_debug(stderr,"",newd,d); 
     190    } 
     191} 
     192 
     193//---------------------------------------------------------------------------------------------------- 
     194 
     195void connect_right(int h, int d, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles) 
     196{ 
     197  NodeProp &old_head_prop = sgraph[h].prop; 
     198  NodeProp &old_dep_prop = sgraph[d].prop; 
     199  NodeProp new_head_prop = compute_head_prop(old_head_prop,l,new_head_boubbles,old_dep_prop.flags); 
     200  NodeProp new_dep_prop = compute_dep_prop(old_dep_prop,l,new_dep_boubbles); 
     201 
     202  Edge new_head_edge(sgraph[h].edge); 
     203  int newh = find_existing_node(sgraph[h].mnode, new_head_prop, new_head_edge); 
     204  if( newh < 0 ) 
    257205      { 
    258         newheadind = create_new_head_node_left(h,newheadprop,newheadLH,newheadLD,newheadLV); 
    259         sgraph[newheadind].edge.clear(); 
    260         sgraph[newheadind].edge_contains_self = false; 
     206        newh = create_new_node(h,new_head_prop,new_head_edge); 
     207        sgraph[newh].visible_as_neighbour = false; 
    261208      } 
    262      
    263   } 
    264  
    265   NodeProp newdepprop = compute_dep_prop(olddepprop,l,new_dep_boubbles); 
    266  
    267   int newdepind; 
    268    
    269   if(olddepprop==newdepprop) 
    270     newdepind = d; 
    271   else 
    272   { 
    273     bitset<MAXNODES> newdepLH = sgraph[d].LH; 
    274     bitset<MAXNODES> newdepLV = sgraph[d].LV; 
    275     bitset<MAXNODES> newdepLD = sgraph[d].LD; 
    276  
    277     newdepind = find_existing_node(sgraph[d].mnode, newdepprop, newdepLH, newdepLV); 
    278     if( newdepind >= 0) // W£¡CZONE 
    279       sgraph[newdepind].LD |= newdepLD; // TYLKO DLA LD 
    280     else 
    281       { 
    282         newdepind = create_new_dep_node_left(d,newdepprop,newdepLH,newdepLD,newdepLV); 
    283         sgraph[newdepind].edge.clear(); 
    284         //sgraph[newdepind].edge.push_back(newdepind); // TO 
    285         sgraph[newdepind].edge_contains_self = true; // LUB TO 
    286       } 
    287   } 
    288    
    289  
    290   sgraph[newheadind].deps.push_back(Arc(newdepind,l.role,h,d)); 
    291   sgraph[newdepind].heads.push_back(Arc(newheadind,l.role,h,d)); 
    292   sgraph[newheadind].edge.push_back(newdepind); 
    293    
    294   if(sgraph[d].saturated()) sgraph[newheadind].LV |= sgraph[d].LV; 
    295  
    296   sgraph[newheadind].LD.set(d); 
    297   if(sgraph[d].saturated()) sgraph[newheadind].LD |= sgraph[d].LD; 
    298    
    299   if(debug) sgraph.print_arc(stderr,"new link",newheadind,d,l.role,0); 
    300   if(debug) sgraph.print_node_debug(stderr,"update",newheadind,h); 
    301   // if(debug) print_sets(newheadind); 
    302   if(debug) sgraph.print_node_debug(stderr,"update",newdepind,d); 
    303   // if(debug) print_sets(newdepind); 
    304 } 
    305  
    306 //---------------------------------------------------------------------------------------------------- 
    307  
    308 void connect_right(int h, int d, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles) 
    309 { 
    310   NodeProp &oldheadprop = sgraph[h].prop; 
    311  
    312   NodeProp newheadprop = compute_head_prop(oldheadprop,l,new_head_boubbles, sgraph[d].prop.flags); 
    313  
    314   int newheadind; 
    315    
    316   if(oldheadprop==newheadprop) 
    317     newheadind = h; 
    318   else 
    319   { 
    320     bitset<MAXNODES> newheadLH = sgraph[h].LH; 
    321     bitset<MAXNODES> newheadLV = sgraph[h].LV; 
    322     bitset<MAXNODES> newheadLD = sgraph[h].LD; 
    323  
    324     newheadind = find_existing_node(sgraph[h].mnode, newheadprop, newheadLH, newheadLV); 
    325  
    326     if(debug) fprintf(stderr,"#HEAD EXISTS %d\n",newheadind); 
    327  
    328     if( newheadind >= 0) // W£¡CZONE 
    329       sgraph[newheadind].LD |= newheadLD; // TYLKO DLA LD 
    330     else 
    331       { 
    332         newheadind = create_new_head_node_right(h,newheadprop,newheadLH,newheadLD,newheadLV); 
    333         //if(!sgraph[h].edge.empty()) sgraph[newheadind].edge.push_back(newheadind); // TO 
    334         sgraph[newheadind].edge_contains_self = sgraph[h].edge_contains_self;      // LUB TO 
    335         sgraph[newheadind].visible_as_neighbour = false; 
    336       } 
    337   } 
    338  
    339   NodeProp &olddepprop = sgraph[d].prop; 
    340   NodeProp newdepprop = compute_dep_prop(olddepprop,l,new_dep_boubbles); 
    341  
    342   int newdepind; 
    343    
    344   if(olddepprop==newdepprop) 
    345     newdepind = d; 
    346   else 
    347   { 
    348     bitset<MAXNODES> newdepLH = sgraph[d].LH; 
    349     bitset<MAXNODES> newdepLV = sgraph[d].LV; 
    350     bitset<MAXNODES> newdepLD = sgraph[d].LD; 
    351  
    352     newdepind = find_existing_node(sgraph[d].mnode, newdepprop, newdepLH, newdepLV); 
    353  
    354     if(debug) fprintf(stderr,"#DEP EXISTS %d\n",newdepind); 
    355  
    356     if( newdepind >= 0) // W£¡CZONE 
    357       sgraph[newdepind].LD |= newdepLD; // TYLKO DLA LD 
    358     else 
    359       { 
    360         newdepind = create_new_dep_node_right(d,newdepprop,newdepLH,newdepLD,newdepLV); 
    361         sgraph[newdepind].edge.clear(); 
    362         sgraph[newdepind].edge_contains_self = false; 
    363       } 
    364   } 
    365  
    366  
    367   sgraph[newdepind].heads.push_back(Arc(newheadind,l.role,h,d)); 
    368   sgraph[newheadind].deps.push_back(Arc(newdepind,l.role,h,d)); 
    369   //sgraph[newdepind].edge.push_back(newheadind); 
    370  
    371   sgraph[newdepind].LH.set(newheadind); 
    372  
    373   //  sgraph[*d].prop.merge_boubbles(new_dep_boubbles); 
    374    
    375   if(sgraph[newheadind].saturated()) sgraph[newdepind].LH |= sgraph[newheadind].LH; 
    376  
    377   if(debug) sgraph.print_arc(stderr,"new link",newheadind,newdepind,l.role,1); 
    378   if(debug) sgraph.print_node_debug(stderr,"update",newheadind,h); 
    379   if(debug) sgraph.print_node_debug(stderr,"update",newdepind,d); 
    380    
    381 } 
    382  
    383 //==================================================================================================== 
    384  
    385 // bool check_meeting_boubles(list<Boubble*>& hboubbles, list<Boubble*>& dboubbles) 
    386 // { 
    387 //   bool hremove=false;             // czy usun±æ ostatnio sprawdzany b±bel 
    388 //   bool dremove=false;             // czy usun±æ ostatnio sprawdzany b±bel 
    389  
    390 //   for(list<Boubble*>::iterator hb = hboubbles.begin(); hb != hboubbles.end(); hb = hremove ? hboubbles.erase(hb) : ++hb ) 
    391 //     { 
    392 //       hremove=false; 
    393 //       for(list<Boubble*>::iterator db = dboubbles.begin(); db != dboubbles.end(); db = dremove ? dboubbles.erase(db) : ++db ) 
    394 //      { 
    395 //        dremove=false; 
    396 //        if( (*hb)->rel()==(*db)->rel() && (*hb)->dir()==DOWN && (*db)->dir()==UP && (*hb)->reverse()!=(*db)->reverse() ) 
    397 //          { 
    398 //            int srcnode,dstnode; 
    399 //            if( (*hb)->reverse()==false ) 
    400 //              srcnode = (*hb)->src(), dstnode = (*db)->src(); 
    401 //            else 
    402 //              srcnode = (*db)->src(), dstnode = (*hb)->src(); 
    403 //            if( grammar.check_longrel(sgraph.cat(srcnode), sgraph.cat(dstnode), (*hb)->rel()) ) 
    404 //              { 
    405 //                hremove=dremove=true; 
    406 //                if(debug) fprintf(stderr,"BOUBBLES MET!!!\n"); 
    407 //              } 
    408 //            else 
    409 //              { 
    410 //                if(debug) fprintf(stderr,"BOUBBLES' MEETING FAILED!!!\n"); 
    411 //                return false; 
    412 //              } 
    413 //          } 
    414 //      } 
    415 //     } 
    416 //   return true; 
    417 // } 
     209 
     210  Edge new_dep_edge; 
     211  int newd = find_existing_node(sgraph[d].mnode, new_dep_prop, new_dep_edge); 
     212  if( newd < 0) 
     213    newd = create_new_node(d,new_dep_prop,new_dep_edge); 
     214 
     215 
     216  sgraph[newd].heads.push_back(Arc(newh,l.role,h,d)); 
     217  sgraph[newh].deps.push_back(Arc(newd,l.role,h,d)); 
     218 
     219  if(debug) 
     220    { 
     221      sgraph.print_arc(stderr,"link",newh,newd,l.role,1); 
     222      sgraph.print_node_debug(stderr,"",newh,h); 
     223      sgraph.print_node_debug(stderr,"",newd,d); 
     224    } 
     225   
     226} 
    418227 
    419228//==================================================================================================== 
     
    424233  bool dremove=false;             // czy usun±æ ostatnio sprawdzany b±bel 
    425234 
     235  // cerr << "CHECKING MEETING BUBBLES" << endl; 
     236 
    426237  for(list<Boubble*>::iterator hb = boubbles.begin(); hb != boubbles.end(); hb = hremove ? boubbles.erase(hb) : ++hb ) 
    427238    { 
    428       cout << endl << "hb:" << **hb ; 
    429239      hremove=false; 
    430240      for(list<Boubble*>::iterator db = hb; db != boubbles.end(); db = dremove ? boubbles.erase(db) : ++db ) 
    431241        { 
    432           cout << " db:" << **db; 
     242          // cerr << " db:" << **db; 
    433243          dremove=false; 
    434244          if( (*hb)->rel()==(*db)->rel() && (*hb)->reverse()!=(*db)->reverse() ) 
    435245            { 
    436               cout << "Z"; 
     246              // cerr << "Z";  
    437247              int srcnode,dstnode; 
    438248              if( (*hb)->reverse()==false ) 
     
    442252              if( grammar.check_longrel(sgraph.cat(srcnode), sgraph.cat(dstnode), (*hb)->rel()) ) 
    443253                { 
    444                   cout << " REMOVE "; 
     254                  // cerr << " REMOVE "; 
    445255                  hremove=dremove=true; 
    446256                  if(debug) fprintf(stderr,"BOUBBLES MET!!!\n"); 
     
    448258              else 
    449259                { 
    450                   cout << " FAIL "; 
     260                  // cerr << " FAIL "; 
    451261                  if(debug) fprintf(stderr,"BOUBBLES' MEETING FAILED!!!\n"); 
    452262                  return false; 
     
    471281      if( grammar.check_longrel(sgraph.cat((*b)->src()), sgraph.cat(node), (*b)->rel()) ) 
    472282        { 
    473           cout << endl << "REMOVE ChBatT " << **b << endl; 
     283          // cerr << endl << "REMOVE ChBatT " << **b << endl; 
    474284          remove=true; 
    475285        } 
     
    489299  int i; 
    490300  while((i=lvi.next()) >= 0) 
    491     { 
    492       //if(debug) sgraph.print_node_debug(stderr,"D-CUR>",i,-1); 
    493  
    494301      if(sgraph.saturated(i)) 
    495302        { 
    496           if(debug) {fprintf(stderr,"%d <--",i); } 
     303          if(debug) {fprintf(stderr,"\t%d <-- %d",i,j); } 
    497304           
    498305          list<const Link*> ji_links = grammar.connectable2( sgraph.cat(j), sgraph.cat(i), sgraph[j].prop.flags, sgraph[i].prop.flags); // ref do Roles!!! 
     
    517324                          if(debug) fprintf(stderr," ...SUCCESS!\n"); 
    518325                          connect_left( j, i, **ri, new_head_boubbles, new_dep_boubbles); 
    519                           lvi.update_edge(sgraph,i); 
     326                          // lvi.update_edge(sgraph,i); 
    520327                        } 
    521328                      else 
     
    526333        } 
    527334      else 
    528           if(debug) {fprintf(stderr,"%d <--     unsaturated\n",i); } 
    529     } 
    530    
     335        if(debug) {fprintf(stderr,"\t%d <-- %d\t%d unsaturated\n",i,j,i); }   
    531336} 
    532337//---------------------------------------------------------------------------------------------------- 
     
    537342  int i; 
    538343  while((i=lvi.next()) >= 0) 
    539     { 
    540       // if(debug) sgraph.print_node_debug(stderr,"H-CUR> ",i,-1); 
    541       if(sgraph.saturated(j)) 
    542         { 
    543           if(debug) fprintf(stderr, "%d -->",i); 
    544            
    545           list<const Link*> ij_links = grammar.connectable2( sgraph.cat(i), sgraph.cat(j), sgraph[i].prop.flags, sgraph[j].prop.flags ); 
    546           list<const Link*>::iterator ri = ij_links.begin(); 
    547           if(ri == ij_links.end()) { if(debug) fprintf(stderr,"     no roles\n"); } 
    548           else 
    549             { 
    550               for(; ri != ij_links.end(); ++ri ) 
    551                 { 
    552                   if(debug) fprintf(stderr,"     %s",(*ri)->role.str()); 
    553                   if( !grammar.check_constr2( sgraph[i].prop, sgraph[j].prop, 1, **ri ) ) 
    554                     { if(debug) fprintf(stderr," ...constraints failed\n"); } 
    555                   else 
    556                     { 
    557                       list<Boubble*> new_head_boubbles = collect_head_boubbles(i,j,(*ri)->role); 
    558                       list<Boubble*> new_dep_boubbles = collect_dep_boubbles(i,j,(*ri)->role); 
    559                        
    560                       if( check_meeting_boubles(new_head_boubbles) && 
    561                           check_meeting_boubles(new_dep_boubbles) && 
    562                           check_boubbles_at_target(new_head_boubbles,i) && 
    563                           check_boubbles_at_target(new_dep_boubbles,j) ) 
    564                         { 
    565                           if(debug) fprintf(stderr," ...SUCCESS!\n"); 
    566                           connect_right( i, j, **ri, new_head_boubbles, new_dep_boubbles ); 
    567                         } 
    568                       else 
    569                         { if(debug) fprintf(stderr," ...bubbles failed\n",i); } 
    570                     } 
    571                 } 
    572             } 
    573         } 
    574       else 
    575           if(debug) {fprintf(stderr,"%d <--     unsaturated\n",j); } 
    576     } 
     344    if(sgraph.saturated(j)) 
     345      { 
     346        if(debug) fprintf(stderr, "\t%d --> %d",i,j); 
     347         
     348        list<const Link*> ij_links = grammar.connectable2( sgraph.cat(i), sgraph.cat(j), sgraph[i].prop.flags, sgraph[j].prop.flags ); 
     349        list<const Link*>::iterator ri = ij_links.begin(); 
     350        if(ri == ij_links.end()) { if(debug) fprintf(stderr,"     no roles\n"); } 
     351        else 
     352          { 
     353            for(; ri != ij_links.end(); ++ri ) 
     354              { 
     355                if(debug) fprintf(stderr,"     %s",(*ri)->role.str()); 
     356                if( !grammar.check_constr2( sgraph[i].prop, sgraph[j].prop, 1, **ri ) ) 
     357                  { if(debug) fprintf(stderr," ...constraints failed\n"); } 
     358                else 
     359                  { 
     360                    list<Boubble*> new_head_boubbles = collect_head_boubbles(i,j,(*ri)->role); 
     361                    list<Boubble*> new_dep_boubbles = collect_dep_boubbles(i,j,(*ri)->role); 
     362                     
     363                    if( check_meeting_boubles(new_head_boubbles) && 
     364                        check_meeting_boubles(new_dep_boubbles) && 
     365                        check_boubbles_at_target(new_head_boubbles,i) && 
     366                        check_boubbles_at_target(new_dep_boubbles,j) ) 
     367                      { 
     368                        if(debug) fprintf(stderr," ...SUCCESS!\n"); 
     369                        connect_right( i, j, **ri, new_head_boubbles, new_dep_boubbles ); 
     370                      } 
     371                    else 
     372                      { if(debug) fprintf(stderr," ...bubbles failed\n",i); } 
     373                  } 
     374              } 
     375          } 
     376      } 
     377    else 
     378      if(debug) {fprintf(stderr,"\t* <-- %d    unsaturated\n",j); } 
    577379} 
    578380 
     
    662464    nodelist.push_back(basenode); 
    663465 
    664     if(debug) sgraph.print_node_debug(stderr,"add base",basenode,-1); // STDOUT!!! 
     466    if(debug) sgraph.print_node_debug(stderr,"node",basenode,-1); // STDOUT!!! 
    665467    // if(debug) print_sets(basenode); 
    666468 
     
    668470    while(++cursor != nodelist.end()) 
    669471    { 
    670       if(debug) sgraph.print_node_debug(stderr,"MAIN-CUR> ",*cursor,-1); 
     472      if(debug) sgraph.print_node_debug(stderr,"CUR>",*cursor,-1); 
    671473      try_connect_dependents(*cursor); 
    672474      try_connect_heads(*cursor); 
  • src/dgp/dgp1.hh

    re7de6cc racbabee  
    1 #ifndef _DGP0_HH 
    2 #define _DGP0_HH 
     1#ifndef _DGP1_HH 
     2#define _DGP1_HH 
    33 
    44#include "grammar.hh" 
  • src/dgp/sgraph.cc

    rd484a32 racbabee  
    1 #include "global.hh" 
    21#include "sgraph.hh" 
    32#include "grammar.hh" 
     
    1615  newnode.mnode=mnodeind; 
    1716 
    18   for(vector<int>::iterator pm=mgraph[newnode.mnode].pred.begin(); pm!=mgraph[newnode.mnode].pred.end(); ++pm) 
    19     for(vector<int>::iterator ps=mgraph[*pm].snodes.begin(); ps!=mgraph[*pm].snodes.end(); ++ps) 
    20       if(nodes[*ps].in_LH) 
    21       { 
    22         newnode.LV.set(*ps); 
    23         if(nodes[*ps].saturated()) newnode.LV |= nodes[*ps].LH; 
    24       } 
     17  // for(vector<int>::iterator pm=mgraph[newnode.mnode].pred.begin(); pm!=mgraph[newnode.mnode].pred.end(); ++pm) 
     18  //   for(vector<int>::iterator ps=mgraph[*pm].snodes.begin(); ps!=mgraph[*pm].snodes.end(); ++ps) 
     19  //     if(nodes[*ps].in_LH) 
     20  //     { 
     21  //       newnode.LV.set(*ps); 
     22  //       if(nodes[*ps].saturated()) newnode.LV |= nodes[*ps].LH; 
     23  //     } 
    2524 
    2625  mgraph[newnode.mnode].snodes.push_back(lastnodeind()); 
    2726 
    28   newnode.in_LH=true; 
     27  // newnode.in_LH=true; 
    2928 
    30   newnode.edge.push_back(lastnodeind()); 
     29  // newnode.edge.push_back(lastnodeind()); 
    3130 
    32   newnode.edge_contains_self = true ; 
     31  newnode.edge.insert_self(); 
    3332 
    3433  return lastnodeind(); 
     
    5554//==================================================================================================== 
    5655 
    57 int SGraph::clone(int ancind, NodeProp newprop) 
     56int SGraph::clone(int ancind, NodeProp newprop, Edge edge) 
    5857{ 
    5958  SNode &newnode=makenewnode(); 
    6059  SNode &ancnode = nodes[ancind]; 
    6160 
    62   newnode.prop=newprop; 
    63   newnode.mnode=ancnode.mnode; 
     61  newnode.prop = newprop; 
     62  newnode.edge = edge; 
     63  newnode.mnode = ancnode.mnode; 
    6464  mgraph[newnode.mnode].snodes.push_back(lastnodeind()); 
    6565 
     
    9090{ 
    9191  if(dir==0) 
    92     fprintf(f,"%s  %s:%d <-- %d\n", msg, role.str(), dep, head); 
     92    fprintf(f,"%s\t%d <-- %d\t%s\n", msg, dep, head, role.str()); 
    9393  else 
    94     fprintf(f,"%s  %s:%d --> %d\n", msg, role.str(), head, dep); 
     94    fprintf(f,"%s\t%d --> %d\t%s\n", msg, head, dep, role.str()); 
    9595} 
    9696 
     
    172172{ 
    173173  char *buf0 = buf; 
    174   buf+=sprintf(buf,"%-10s",pref); 
     174  buf+=sprintf(buf,"%-8s",pref); 
    175175  buf+=sprintf(buf,"%d.%s",n,form(n)); 
    176176  buf+=sprintf(buf,";"); 
    177177  buf+=sprintf(buf,"%s ",cat(n).str()); 
    178178  while(buf-buf0<40) buf+=sprintf(buf," "); 
    179   buf+=sprint_node(buf,n,anc,HEADS|DEPS|SETS|CONSTRAINTS); 
     179  buf+=sprint_node(buf,n,anc,HEADS|DEPS|CONSTRAINTS); 
    180180   
    181181  buf+=sprintf(buf,"/"); 
    182   for(vector<int>::iterator e = nodes[n].edge.begin(); e != nodes[n].edge.end(); e++ ) 
     182  if(nodes[n].edge.self()) 
     183    buf += sprintf(buf,"* "); 
     184  for(list<int>::iterator e = nodes[n].edge.others().begin(); e != nodes[n].edge.others().end(); e++ ) 
    183185    buf += sprintf(buf,"%d ", *e); 
    184186 
  • src/dgp/sgraph.hh

    rd484a32 racbabee  
    1313#include "thesymbols.hh" 
    1414#include "boubble.hh" 
    15  
     15#include "global.hh" 
    1616 
    1717using namespace std; 
     
    116116} 
    117117 
    118 //---------------------------------------------------------------------------------------------------- 
    119  
    120 inline 
    121 NodeProp::~NodeProp() 
    122 { 
    123   clear_boubbles(); 
    124 } 
    125 //---------------------------------------------------------------------------------------------------- 
    126  
    127 inline 
    128 NodeProp::NodeProp() 
    129 { 
    130   clear(); 
    131 } 
    132  
    133 //---------------------------------------------------------------------------------------------------- 
    134  
    135 inline 
    136 NodeProp::NodeProp(const NodeProp& p) 
    137 { 
    138   copy(p); 
    139 } 
    140  
    141 //---------------------------------------------------------------------------------------------------- 
    142  
    143 inline 
    144 NodeProp& NodeProp::operator=(const NodeProp& p) 
    145 { 
    146   clear(); 
    147   copy(p); 
    148   return *this; 
    149 } 
    150  
    151 //---------------------------------------------------------------------------------------------------- 
    152  
    153 inline 
    154 void NodeProp::clear() 
     118inline NodeProp::~NodeProp() { clear_boubbles(); } 
     119inline NodeProp::NodeProp() { clear(); } 
     120inline NodeProp::NodeProp(const NodeProp& p) { copy(p); } 
     121inline NodeProp& NodeProp::operator=(const NodeProp& p) { clear(); copy(p); return *this; } 
     122inline void NodeProp::clear() 
    155123{ 
    156124  required.reset(); 
     
    163131 
    164132//==================================================================================================== 
     133// CLASS Edge 
     134//==================================================================================================== 
     135 
     136class Edge 
     137{ 
     138public: 
     139  Edge() : _self(false) { } 
     140  Edge(const Edge& e, int map_self) { assign(e,map_self); } 
     141 
     142  bool self() const { return _self; } 
     143  list<int>& others() { return _others; } 
     144 
     145  void insert_self(bool b=true) { _self=b; } 
     146  void insert(int n) { list<int>::iterator i=others().begin(); while(i!=others().end() && *i<n) ++i; others().insert(i,n);} 
     147  void insert(list<int> l) { for(list<int>::const_iterator i=l.begin(); i!=l.end(); i++) insert(*i); } 
     148 
     149  void assign(const Edge& e, int map_self=-1) { _others = e._others; if(e.self()) { _self = false; insert(map_self); } } 
     150  const bool operator==(const Edge& e) const { return _self == e._self && _others == e._others; } 
     151   
     152private: 
     153  bool _self; 
     154  list<int> _others; 
     155}; 
     156 
     157//==================================================================================================== 
    165158// CLASS SNode 
    166159//==================================================================================================== 
     
    175168  NodeProp prop; 
    176169 
    177   vector<int> edge; 
    178   bool        edge_contains_self; 
     170  Edge edge; 
    179171  bool visible_as_neighbour; 
    180172 
     
    189181  void clear(); 
    190182  bool saturated(); 
     183 
     184  // void edge_clear()               { edge.clear(); edge_contains_self=false;} 
     185  // void edge_set(int i)            { edge.clear(); edge_contains_self=false; edge.push_back(i); } 
     186  // void edge_set(vector<int>& v)   { edge.assign(v.begin(),v.end()); edge_contains_self=false; } 
     187  // void edge_set_self(bool b=true) { edge.clear(); edge_contains_self=b; } 
     188  // void edge_add(int i)            { edge.push_back(i); } 
     189  // void edge_add(vector<int>& v)   { edge.insert(edge.end(),v.begin(),v.end()); } 
     190  // void edge_add_self(bool b=true) { edge_contains_self=b; } 
    191191}; 
    192192 
     
    216216  void clear()                                  { nodes.clear(); } 
    217217  int  add_base_snode(int mnodeind); 
    218   int  clone(int ancind, NodeProp newprop); 
     218  int  clone(int ancind, NodeProp newprop, Edge edge); 
    219219  void update_left(int headind, int depind); 
    220220  void update_right(int headind, int depind); 
     
    299299 
    300300private: 
    301  
     301  int snode; 
    302302  SGraph& sgraph; 
    303303  MGraph& mgraph; 
     
    312312}; 
    313313 
    314 inline LViterator::LViterator(SGraph& sg, int n, bool s=true) : sgraph(sg), mgraph(sg.mgraph), strict(s) 
    315 { 
    316   if(sg[n].edge_contains_self) // TO DODAÆ PO PRZEJŠCIU NA EDGE_CONTAINS_SELF 
     314inline LViterator::LViterator(SGraph& sg, int n, bool s=true) : snode(n), sgraph(sg), mgraph(sg.mgraph), strict(s) 
     315{ 
     316  if(sg[n].edge.self()) 
    317317    { 
    318318      push_ld(n); 
     
    320320    } 
    321321 
    322   for(vector<int>::iterator i=sg[n].edge.begin(); i!=sg[n].edge.end(); ++i) 
    323     { 
    324       if(*i != n) 
    325         { 
    326           push_ld(*i); 
    327           push_ln(*i); 
    328         } 
    329        
    330     } 
    331 } 
    332  
    333 inline void LViterator::update_edge(SGraph& sg, int n) 
    334 { 
    335   for(vector<int>::iterator i=sg[n].edge.begin(); i!=sg[n].edge.end(); ++i) 
     322  for(list<int>::iterator i=sg[n].edge.others().begin(); i!=sg[n].edge.others().end(); ++i) 
    336323    { 
    337324      push_ld(*i); 
    338325      push_ln(*i); 
     326       
     327    } 
     328} 
     329 
     330inline void LViterator::update_edge(SGraph& sg, int n) 
     331{ 
     332  if(sg[n].edge.self())  
     333    { 
     334      push_ld(n); 
     335      push_ln(n); 
     336    } 
     337 
     338  for(list<int>::iterator i=sg[n].edge.others().begin(); i!=sg[n].edge.others().end(); ++i) 
     339    { 
     340      push_ld(*i); 
     341      push_ln(*i); 
    339342    } 
    340343} 
     
    345348    { 
    346349      if(waydown.empty()) 
    347         return -1; //  
     350        { 
     351          if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,-1); 
     352          return -1; //  
     353        } 
    348354      else 
    349355        { 
     
    353359          push_ln(k); 
    354360          if(wayup.empty()) 
    355             return -1; // k NIE MA POPRZEDNIKÓW, NIE MO¯E TE¯ ZATEM MIEÆ LEWOSTRONNYCH PODRZÊDNIKÓW 
     361            { 
     362              if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,-1); 
     363              return -1; // k NIE MA POPRZEDNIKÓW, NIE MO¯E TE¯ ZATEM MIEÆ LEWOSTRONNYCH PODRZÊDNIKÓW 
     364            } 
    356365          else 
    357366            { 
     
    359368              wayup.pop(); 
    360369              push_lh(i); 
     370              if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,i); 
    361371              return i; 
    362372            } 
     
    364374       
    365375    } 
     376  else 
     377    { 
     378      int i = wayup.top(); 
     379      wayup.pop(); 
     380      push_lh(i); 
     381      if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,i); 
     382      return i; 
     383    }; 
     384} 
     385 
     386inline void LViterator::push_ld(int i) 
     387{ 
     388  vector<Arc>& arcs = sgraph[i].deps; 
     389  for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 
     390    if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) 
     391      { 
     392        push(waydown,a->dst); 
     393        if(debug) fprintf(stderr,"\t\tLViterator(%d)\tPUSH_LD waydown %d\n",snode,a->dst); 
     394      } 
     395} 
     396 
     397inline void LViterator::push_lh(int i) 
     398{ 
     399  vector<Arc>& arcs = sgraph[i].heads; 
     400  for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 
     401    if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) 
     402      { 
     403        push(wayup,a->dst); 
     404        if(debug) fprintf(stderr,"\t\tLViterator(%d)\tPUSH_LH wayup %d\n",snode,a->dst); 
     405      } 
     406} 
     407 
     408inline void LViterator::push_ln(int i) 
     409{ 
     410  vector<int>& mpredecessors = mgraph[sgraph[i].mnode].pred; 
     411  for(vector<int>::iterator mp = mpredecessors.begin(); mp != mpredecessors.end(); ++mp) // poprzedniki w mgraph 
     412    { 
     413      vector<int>& spredecessors = mgraph[*mp].snodes; 
     414      for(vector<int>::iterator sp = spredecessors.begin(); sp != spredecessors.end(); ++sp ) 
     415        if(sgraph[*sp].visible_as_neighbour || !strict) 
     416          { 
     417            push(wayup,*sp); 
     418            if(debug) fprintf(stderr,"\t\tLViterator(%d)\tPUSH_LN wayup %d\n",snode, *sp); 
     419          } 
     420    } 
     421} 
     422 
     423 
     424//---------------------------------------------------------------------------------------------------- 
     425//---------------------------------------------------------------------------------------------------- 
     426 
     427class LNiterator 
     428{ 
     429public: 
     430  LNiterator(SGraph& sg, int n); 
     431 
     432  int next(); 
     433 
     434private: 
     435  int snode; 
     436  SGraph& sgraph; 
     437  MGraph& mgraph; 
     438  stack<int> wayup; 
     439 
     440  void push_ln(int i); 
     441}; 
     442 
     443inline LNiterator::LNiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), snode(n) 
     444{ 
     445  push_ln(n); 
     446} 
     447 
     448inline int LNiterator::next() 
     449{ 
     450  if(wayup.empty()) 
     451    { 
     452      if(debug) fprintf(stderr,"\t\tLNiterator(%d)\treturn %d\n",snode,-1); 
     453      return -1; 
     454    } 
     455  else 
     456    { 
     457      int i = wayup.top(); 
     458      wayup.pop(); 
     459      if(debug) fprintf(stderr,"\t\tLNiterator(%d)\treturn %d\n",snode,i); 
     460      return i; 
     461    }; 
     462} 
     463 
     464inline void LNiterator::push_ln(int i) 
     465{ 
     466  vector<int>& mpredecessors = mgraph[sgraph[i].mnode].pred; 
     467  for(vector<int>::iterator mp = mpredecessors.begin(); mp != mpredecessors.end(); ++mp) // poprzedniki w mgraph 
     468    { 
     469      vector<int>& spredecessors = mgraph[*mp].snodes; 
     470      for(vector<int>::iterator sp = spredecessors.begin(); sp != spredecessors.end(); ++sp ) 
     471        { 
     472          wayup.push(*sp); 
     473          if(debug) fprintf(stderr,"\t\tLNiterator(%d)\tPUSH %d\n",snode,-1); 
     474        } 
     475    } 
     476} 
     477 
     478 
     479//---------------------------------------------------------------------------------------------------- 
     480//---------------------------------------------------------------------------------------------------- 
     481 
     482class LHiterator 
     483{ 
     484public: 
     485  LHiterator(SGraph& sg, int n); 
     486 
     487  int next(); 
     488 
     489private: 
     490  int snode; 
     491  SGraph& sgraph; 
     492  MGraph& mgraph; 
     493  stack<int> wayup; 
     494 
     495  void push_lh(int i); 
     496}; 
     497 
     498inline LHiterator::LHiterator(SGraph& sg, int n) : snode(n), sgraph(sg), mgraph(sg.mgraph) 
     499{ 
     500  push_lh(n); 
     501} 
     502 
     503inline int LHiterator::next() 
     504{ 
     505  if(wayup.empty()) 
     506        return -1;  
    366507  else 
    367508    { 
     
    373514} 
    374515 
    375 inline void LViterator::push_ld(int i) 
    376 { 
    377   vector<Arc>& arcs = sgraph[i].deps; 
    378   for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 
    379     if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) 
    380       push(waydown,a->dst); 
    381 } 
    382  
    383 inline void LViterator::push_lh(int i) 
     516inline void LHiterator::push_lh(int i) 
    384517{ 
    385518  vector<Arc>& arcs = sgraph[i].heads; 
    386519  for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 
    387520    if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) 
    388       push(wayup,a->dst); 
    389 } 
    390  
    391 inline void LViterator::push_ln(int i) 
    392 { 
    393   vector<int>& mpredecessors = mgraph[sgraph[i].mnode].pred; 
    394   for(vector<int>::iterator mp = mpredecessors.begin(); mp != mpredecessors.end(); ++mp) // poprzedniki w mgraph 
    395     { 
    396       vector<int>& spredecessors = mgraph[*mp].snodes; 
    397       for(vector<int>::iterator sp = spredecessors.begin(); sp != spredecessors.end(); ++sp ) 
    398         if(sgraph[*sp].visible_as_neighbour || !strict) 
    399           push(wayup,*sp); 
    400     } 
    401 } 
    402  
    403  
    404 //---------------------------------------------------------------------------------------------------- 
    405 //---------------------------------------------------------------------------------------------------- 
    406  
    407 class LNiterator 
     521      { 
     522        wayup.push(a->dst); 
     523        if(debug) fprintf(stderr,"\t\tLHiterator(%d)\tPUSH %d\n",snode,-1); 
     524      } 
     525} 
     526 
     527//---------------------------------------------------------------------------------------------------- 
     528//---------------------------------------------------------------------------------------------------- 
     529 
     530class LDiterator 
    408531{ 
    409532public: 
    410   LNiterator(SGraph& sg, int n); 
     533  LDiterator(SGraph& sg, int n); 
    411534 
    412535  int next(); 
    413536 
    414537private: 
    415  
     538  int snode; 
    416539  SGraph& sgraph; 
    417540  MGraph& mgraph; 
    418   int thenode; 
    419   stack<int> wayup; 
    420  
    421   void push_ln(int i); 
    422 }; 
    423  
    424 inline LNiterator::LNiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), thenode(n) 
    425 { 
    426   push_ln(n); 
    427 } 
    428  
    429 inline int LNiterator::next() 
    430 { 
    431   if(wayup.empty()) 
    432     return -1; 
    433   else 
    434     { 
    435       int i = wayup.top(); 
    436       wayup.pop(); 
    437       return i; 
    438     }; 
    439 } 
    440  
    441 inline void LNiterator::push_ln(int i) 
    442 { 
    443   vector<int>& mpredecessors = mgraph[sgraph[i].mnode].pred; 
    444   for(vector<int>::iterator mp = mpredecessors.begin(); mp != mpredecessors.end(); ++mp) // poprzedniki w mgraph 
    445     { 
    446       vector<int>& spredecessors = mgraph[*mp].snodes; 
    447       for(vector<int>::iterator sp = spredecessors.begin(); sp != spredecessors.end(); ++sp ) 
    448           wayup.push(*sp); 
    449     } 
    450 } 
    451  
    452  
    453 //---------------------------------------------------------------------------------------------------- 
    454 //---------------------------------------------------------------------------------------------------- 
    455  
    456 class LHiterator 
    457 { 
    458 public: 
    459   LHiterator(SGraph& sg, int n); 
    460  
    461   int next(); 
    462  
    463 private: 
    464  
    465   SGraph& sgraph; 
    466   MGraph& mgraph; 
    467   stack<int> wayup; 
    468  
    469   void push_lh(int i); 
    470 }; 
    471  
    472 inline LHiterator::LHiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph) 
    473 { 
    474   push_lh(n); 
    475 } 
    476  
    477 inline int LHiterator::next() 
    478 { 
    479   if(wayup.empty()) 
    480         return -1;  
    481   else 
    482     { 
    483       int i = wayup.top(); 
    484       wayup.pop(); 
    485       push_lh(i); 
    486       return i; 
    487     }; 
    488 } 
    489  
    490 inline void LHiterator::push_lh(int i) 
    491 { 
    492   vector<Arc>& arcs = sgraph[i].heads; 
    493   for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 
    494     if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) 
    495       wayup.push(a->dst); 
    496 } 
    497  
    498 //---------------------------------------------------------------------------------------------------- 
    499 //---------------------------------------------------------------------------------------------------- 
    500  
    501 class LDiterator 
    502 { 
    503 public: 
    504   LDiterator(SGraph& sg, int n); 
    505  
    506   int next(); 
    507  
    508 private: 
    509  
    510   SGraph& sgraph; 
    511   MGraph& mgraph; 
    512   int thenode; 
    513541  stack<int> waydown; 
    514542 
     
    516544}; 
    517545 
    518 inline LDiterator::LDiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), thenode(n) 
     546inline LDiterator::LDiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), snode(n) 
    519547{ 
    520548  push_ld(n); 
     
    538566  vector<Arc>& arcs = sgraph[i].deps; 
    539567  for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 
    540     if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[thenode].mnode].pos) 
    541       waydown.push(a->dst); 
    542 } 
    543  
    544  
     568    if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[snode].mnode].pos) 
     569      { 
     570        waydown.push(a->dst); 
     571        if(debug) fprintf(stderr,"\t\tLDiterator(%d)\tPUSH %d\n",snode,-1); 
     572      } 
     573} 
    545574 
    546575#endif 
  • src/sen/sen.l

    rac25afd racbabee  
    5454.*                        { ECHO; set_position(); } 
    5555 
    56 <<EOF>>                   { printf("%04d 00 EOS *\n",pos+len); exit(1); } 
     56<<EOF>>                   { printf("%04d 00 EOS *\n",pos+len); exit(0); } 
    5757 
    5858%% 
  • src/tre/tre

    r0a58b3f racbabee  
    1313[ '--format',   '-F',   GetoptLong::REQUIRED_ARGUMENT ], 
    1414[ '--info',     '-I',   GetoptLong::REQUIRED_ARGUMENT ], 
     15[ '--dgpids',           GetoptLong::NO_ARGUMENT ], 
     16[ '--graph',            GetoptLong::NO_ARGUMENT ], 
     17[ '--uniq',     '-u',   GetoptLong::NO_ARGUMENT ], 
     18[ '--utt',              GetoptLong::NO_ARGUMENT ], 
    1519[ '--span',     '-s',   GetoptLong::REQUIRED_ARGUMENT ], 
    1620[ '--maxsize',          GetoptLong::REQUIRED_ARGUMENT ], 
    1721[ '--forest',           GetoptLong::NO_ARGUMENT ], 
    18 [ '--ground',           GetoptLong::NO_ARGUMENT ], 
    1922[ '--only-trees','-t',  GetoptLong::NO_ARGUMENT ]) 
    2023 
    21 $helptext= 
    22 "The program generates trees from the graph output by dgp. dgp must\n"+ 
    23 "must be run with '--info=ds' option.\n\n"+ 
    24 "Command:       tre [options]\n\n"+ 
    25 "Options:\n"+ 
    26 "--help         -h      Print help (this text) and exit.\n"+ 
    27 "--debug        -d      Verbose output. For developers only.\n"+ 
    28 "--format=s     -F s    Output format. Recognized values:\n"+ 
    29 "                               a       root + list of arcs\n"+ 
    30 "                               p       parenthesized notation\n"+ 
    31 "                               h       human readable indented tree format\n"+ 
    32 "                       Multiple values are allowed. (default p)\n"+ 
    33 "--info=s       -I s    Information printed. Recognized values:\n"+ 
    34 "                               n       node identifier\n"+ 
    35 "                               f       surface form\n"+ 
    36 "                               m       morphological information\n"+ 
    37 "                               l       arc labels\n"+ 
    38 "--only-trees   -t      Do not copy input. Print trees only.\n" 
     24$helptext = <<END 
     25The program generates trees from the graph output by dgp. dgp must be run  
     26with '--info=ds' option. 
     27 
     28Command:       tre [options] 
     29 
     30Options: 
     31--help         -h      Print help (this text) and exit. 
     32--debug        -d      Verbose output. For developers only. 
     33--format=s     -F s    Output format. Recognized values: 
     34                               a       root + list of arcs 
     35                               p       parenthesized notation 
     36                               h       human readable indented format 
     37                               c       CONLL format 
     38                       Multiple values are allowed. (default p) 
     39--info=s       -I s    Information printed. Recognized values: 
     40                               n       node identifier 
     41                               f       surface form 
     42                               m       morphological information 
     43                               l       arc labels\ 
     44--gphids               Used gph node identifiers (default: linear) 
     45--dgpids               Used dgp node identifiers (default: linear) 
     46--graph                Do not generate trees, just print the graph. 
     47--uniq         -u      Remove duplicate trees. 
     48--utt                  UTT formatted output. 
     49 
     50END 
    3951 
    4052$DEBUG=false 
    4153$FORMAT='p' 
    4254$INFO='DEFAULT' 
    43 $ONLYTREES=false 
     55$UTTOUTPUT=false 
    4456$START=nil 
    4557$END=nil 
    4658$FOREST=false 
    4759$MAXSIZE=nil 
     60$GPHIDS=false 
     61$DGPIDS=false 
     62$GRAPH==false 
    4863 
    4964opts.each do |opt, arg| 
     
    5873  when '--info' 
    5974    $INFO=arg 
    60   when '--only-trees' 
    61     $ONLYTREES=true 
     75  when '--gphids' 
     76    $GPHIDS=true 
     77  when '--dgpids' 
     78    $DGPIDS=true 
     79  when '--graph' 
     80    $GRAPH=true 
     81  when '--uniq' 
     82    $UNIQ=true 
     83  when '--utt' 
     84    $UTTOUTPUT=true 
    6285  when '--forest' 
    6386    $FOREST=true 
    64   when '--ground' 
    65     $GROUND=true 
    6687  when '--maxsize' 
    6788    $MAXSIZE=arg.to_i 
     
    7697  case $FORMAT 
    7798    when 'p','a' 
    78     $INFO='nl' 
     99    $INFO='fl' 
    79100    when 'h' 
    80101    $INFO='fmnl' 
     
    95116  for line in input 
    96117    seg=Seg.new(line) 
    97     print line unless $ONLYTREES || seg.field(3) == 'EOS' 
     118    print line if $UTTOUTPUT && seg.field(3) == 'EOS' 
    98119     
    99120    if dgp=seg['dgp'] 
     
    122143 
    123144        $pref = "#{seg[1]} #{seg[2]} SYN *" 
    124  
    125145        parsegraph(nodes) 
    126  
    127146        set_ord #(0...(nodes.length)).each{|i| set_distance_from_i i } 
    128  
    129147        printgraph if $DEBUG 
    130  
    131         if $GROUND 
    132           printground 
     148        if $GRAPH 
     149          if $FORMAT =~ /c/ 
     150            printconll 
     151          else 
     152            printground 
     153          end 
    133154        else 
    134155          thetrees = $FOREST ? genforest : gentrees 
    135            
    136           output_trees thetrees 
    137            
    138           print line unless $ONLYTREES 
    139            
    140           $gphid=[]   # POWTÓRZENIE 
     156          outputs = output_trees thetrees 
     157          outputs = outputs.sort.uniq if $UNIQ 
     158          print outputs.join 
     159          print line if $UTTOUTPUT 
     160          $gphid=[] 
    141161          $form=[] 
    142162          $lem=[]  
     
    154174 
    155175def output_trees trees 
     176   
     177  outputs = [] 
     178   
    156179  for t in trees 
    157180    $count += 1 
     
    160183    t1=t 
    161184 
    162     span = $FOREST ? " span:" + (ground_tree_min(t1).to_s + ","+ground_tree_max(t1).to_s)+";" : "" 
     185    # span = $FOREST ? " span:" + (ground_tree_min(t1).to_s + ","+ground_tree_max(t1).to_s)+";" : "" 
     186    # case $FORMAT 
     187    # when /a/ 
     188    #   outputs << "#{$pref} tre:#{$count}#{span} #{arc_output(t1)}\n" 
     189    # when /p/ 
     190    #   outputs << "#{$pref}#{span} tre:#{$count} par:#{par_output(t1)}\n" 
     191    # when /h/ 
     192    #   outputs << "#\n# tree #{$count}\n# ------\n#{dgp_output(t1,0)}" 
     193    # when /c/ 
     194    #   outputs << conll_output(t1,0) 
     195    # end 
     196 
    163197    case $FORMAT 
    164198    when /a/ 
    165       print "#{$pref} tre:#{$count}#{span} #{arcsinfo(t1[0],t1[1])}" 
    166 #       print arcsinfo(t1[0],t1[1]) 
    167       print "\n" 
     199      outputs << "#{arc_output(t1)}\n" 
    168200    when /p/ 
    169       print "#{$pref}#{span} tre:#{$count} par:" 
    170       printpar(t1[0],t1[1]) 
    171       print "\n" 
     201      outputs << "#{par_output(t1)}\n" 
    172202    when /h/ 
    173       print "#\n# tree #{$count}\n# ------\n" 
    174       printtree_dgp(t1[0],t1[1],0) 
    175     end 
    176   end 
    177 end 
    178  
     203      outputs << human_output(t1,0) 
     204    when /c/ 
     205      outputs << conll_output(t1,0) 
     206    end 
     207 
     208  end 
     209 
     210  outputs 
     211 
     212end 
     213 
     214def id_output id 
     215  if $DGPIDS then id elsif $GPHIDS then $gphid[id] else $ord1[$gphid[id]] end 
     216end 
    179217 
    180218def nodeinfo(id) 
     
    186224  end 
    187225  if $INFO =~ /n/ 
    188     info += gphid.to_s                            
     226    info += id_output(id).to_s                            
    189227    info += '.' if $INFO =~ /[fm]/ 
    190228  end 
     
    200238 
    201239 
    202 def arcsinfo(root,arcs) 
     240def arc_output(tree) 
     241  root, arcs = tree 
    203242  "head:#{nodeinfo(root)} links:" + arcs.map{|a| "(#{($INFO =~ /l/) ? a[2]+":" : ""}#{nodeinfo(a[0])}-#{nodeinfo(a[1])})"}.join("") 
    204 #   for a in arcs 
    205 #     print ';' 
    206 #     print "#{a[2]}:" if $INFO =~ /l/ 
    207 #       print nodeinfo(a[0])+'-'+nodeinfo(a[1]) 
    208 #   end 
    209243end 
    210244 
     
    221255end 
    222256 
    223 def printtree_dgp(root,arcs,o) 
     257def human_output(tree,o) 
     258  root, arcs = tree 
     259  output = '' 
    224260  if o==0 
    225         print "%-16s" % "root: " 
    226   end 
    227   print nodeinfo(root),"\n" 
     261        output += "%-16s" % "root: " 
     262  end 
     263  output += nodeinfo(root) + "\n" 
    228264  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) 
    232   end 
    233 end 
    234  
    235 # old: 
    236 # def printpar(root,arcs) 
    237 #   print nodeinfo(root) 
    238 #   deps = arcs.select{ |a| a[0]==root }.sort{|a,b| a[1]<=>b[1] } 
    239 #   unless deps == [] 
    240 #     print '(' 
    241 #     cont=false 
    242 #     for arc in deps 
    243 #       if cont then print ',' else cont=true end 
    244 #       print arc[2],':' if $INFO =~ /l/ 
    245 #       printpar(arc[1],arcs) 
    246 #     end 
    247 #     print ')' 
    248 #   end 
    249 # end 
    250  
    251 def printpar(root,arcs) 
    252    
     265    output += "   "*(o+1) 
     266    output += "%-16s" % (arc[2]+": ") 
     267    output += human_output([arc[1],arcs],o+1) 
     268  end 
     269  output 
     270end 
     271 
     272def conll_output(tree,o) 
     273  root,arcs = tree 
     274  nodes = ([root] + arcs.map{|a| a[1]}).sort{|a,b| $gphid[a] <=> $gphid[b]} 
     275  conll_lines = [] 
     276  for i in nodes 
     277    gphid = $gphid[i] 
     278    id = $ord1[gphid] 
     279    form = $form[gphid] 
     280    /^(?<lemma>.*),(?<cpostag>[^\/]*)(\/(?<feats>.+))?/ =~ $lem[gphid] 
     281    thearcs = arcs.select{|a| a[1]==i }.map{|a| [$ord1[$gphid[a[0]]],a[2]] }  
     282    thearcs = [[0,'root']] if thearcs.empty? 
     283    for a in thearcs 
     284      head,deprel = a 
     285      conll_lines << [id,form,lemma,cpostag,cpostag,feats,head,deprel,nil,nil].map{|s| s ? s.to_s : "_"}.join("\t") 
     286    end 
     287  end 
     288  conll_lines.join("\n") + "\n\n" 
     289end 
     290 
     291def par_output(tree) 
     292  root, arcs = tree 
    253293  ldeps = arcs.select{|a| a[0]==root and $gphid[a[1]] < $gphid[root]}.sort{|a,b| $gphid[a[1]]<=>$gphid[b[1]] } 
    254294  rdeps = arcs.select{|a| a[0]==root and $gphid[a[1]] > $gphid[root]}.sort{|a,b| $gphid[a[1]]<=>$gphid[b[1]] } 
    255295 
    256   for arc in ldeps 
    257     print ' (' 
    258     print arc[2].upcase if $INFO =~ /l/ 
    259     printpar(arc[1],arcs) 
    260     print ')' 
    261   end 
    262  
    263   print ' ',nodeinfo(root) 
    264  
    265   for arc in rdeps 
    266     print ' (' 
    267     print arc[2].upcase if $INFO =~ /l/ 
    268     printpar(arc[1],arcs) 
    269     print ')' 
    270   end 
     296  output = '' 
     297 
     298  output_left  = ldeps.map{|arc| ' (' + (($INFO =~ /l/) ? arc[2].upcase : '') + par_output([arc[1],arcs]) + ')'}.join 
     299  output_right = rdeps.map{|arc| ' (' + (($INFO =~ /l/) ? arc[2].upcase : '') + par_output([arc[1],arcs]) + ')'}.join 
     300 
     301  # for arc in ldeps 
     302  #   output += ' (' 
     303  #   output += arc[2].upcase if $INFO =~ /l/ 
     304  #   output += par_output(arc[1],arcs) 
     305  #   output += ')' 
     306  # end 
     307 
     308  # print ' ',nodeinfo(root) 
     309 
     310  # for arc in rdeps 
     311  #   print ' (' 
     312  #   print arc[2].upcase if $INFO =~ /l/ 
     313  #   printpar(arc[1],arcs) 
     314  #   print ')' 
     315  # end 
     316 
     317  output_left + ' ' + nodeinfo(root) + output_right 
     318 
    271319end 
    272320 
     
    467515end 
    468516 
     517def printconll 
     518  for i in 1...($form.length-1) 
     519    id = $ord1[i] 
     520    form = $form[i] 
     521    /^(?<lemma>.*),(?<cpostag>[^\/]*)(\/(?<feats>.+))?/ =~ $lem[i] 
     522    arcs = $arcs.select{|a| $ord1[$gphid[a[1]]] == $ord1[i]}.map{|a| [$ord1[$gphid[a[0]]],a[2]]}.sort.uniq 
     523    arcs = [[0,'root']] if arcs.empty? 
     524    for a in arcs 
     525      head,deprel = a 
     526      puts [id,form,lemma,cpostag,cpostag,feats,head,deprel,nil,nil].map{|s| s ? s.to_s : "_"}.join("\t") 
     527    end 
     528  end 
     529  puts 
     530end 
     531 
    469532 
    470533def set_to_s(s) "{#{s.join(',')}}" end 
Note: See TracChangeset for help on using the changeset viewer.