Changeset 519eaf5 for src/dgp/dgp1.cc
- Timestamp:
- 03/30/14 23:59:06 (11 years ago)
- Branches:
- master
- Children:
- 0a58b3f
- Parents:
- f924e4b
- git-author:
- Tomasz Obrebski <obrebski@…> (03/30/14 23:59:06)
- git-committer:
- Tomasz Obrebski <obrebski@…> (03/30/14 23:59:06)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/dgp/dgp1.cc
rb97a556 r519eaf5 1 #include <iostream> 2 using namespace std; 3 1 4 #include "dgp0.hh" 2 5 #include "global.hh" … … 79 82 { 80 83 ret = *ps; 81 // fprintf(stderr,"FIND EXISTING NODE SUCCEEDED BEACAUSE OFLH/LV equality ()\n");84 fprintf(stderr,"#\tsucceeded because of LH/LV equality ()\n"); 82 85 } 83 86 else 84 87 { 85 // fprintf(stderr,"FIND EXISTING NODE FAILED BEACAUSE OFLH/LV inequality\n");88 fprintf(stderr,"#\tfailed beacause of LH/LV inequality\n"); 86 89 } 87 90 } … … 158 161 //==================================================================================================== 159 162 160 int create_new_head_node_left(int h, NodeProp& newheadprop, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLD, bitset<MAXNODES>& newheadLV) 161 { 162 int newheadind = sgraph.clone(h,newheadprop); 163 // list<int>::iterator nextit=h; ++nextit; 164 // nodelist.insert(nextit,newheadind); 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); 165 166 nodelist.push_back(newheadind); 166 sgraph[newheadind].LH =newheadLH;167 sgraph[newheadind].LD = newheadLD;168 sgraph[newheadind].in_LH =true;167 sgraph[newheadind].LH = LH; 168 sgraph[newheadind].LD = LD; 169 sgraph[newheadind].in_LH = true; 169 170 sgraph[newheadind].LV.reset(); 170 171 171 copy_links( h,newheadind);172 copy_links(anc,newheadind); 172 173 create_reverse_links(newheadind); 173 174 174 if(debug) sgraph.print_node_debug(stderr," C ",newheadind,h);175 if(debug) sgraph.print_node_debug(stderr,"add new",newheadind,anc); 175 176 // if(debug) print_sets(newheadind); 176 177 return newheadind; 177 178 } 178 179 179 int create_new_dep_node_left(int d, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV) 180 { 181 int newind = sgraph.clone(d,prop); 182 // list<int>::iterator nextit=d; ++nextit; 183 // nodelist.insert(nextit,newind); 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); 184 183 nodelist.push_back(newind); 185 184 sgraph[newind].LH.reset(); … … 188 187 sgraph[newind].LV.reset(); 189 188 190 copy_links( d,newind);189 copy_links(anc,newind); 191 190 create_reverse_links(newind); 192 191 193 if(debug) sgraph.print_node_debug(stderr," C ",newind,d);192 if(debug) sgraph.print_node_debug(stderr,"add new",newind,anc); 194 193 // if(debug) print_sets(newind); 195 194 … … 197 196 } 198 197 199 int create_new_head_node_right(int h, NodeProp& newheadprop, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLD, bitset<MAXNODES>& newheadLV) 200 { 201 int newheadind = sgraph.clone(h,newheadprop); 202 // list<int>::iterator nextit=h; ++nextit; 203 // nodelist.insert(nextit,newheadind); 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); 204 201 nodelist.push_back(newheadind); 205 202 sgraph[newheadind].LH=newheadLH; … … 208 205 sgraph[newheadind].LV=newheadLV; 209 206 210 copy_links( h,newheadind);207 copy_links(anc,newheadind); 211 208 create_reverse_links(newheadind); 212 209 213 if(debug) sgraph.print_node_debug(stderr," C ",newheadind,h);210 if(debug) sgraph.print_node_debug(stderr,"add new",newheadind,anc); 214 211 // if(debug) print_sets(newheadind); 215 212 … … 217 214 } 218 215 219 int create_new_dep_node_right(int d, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV)220 { 221 int newind = sgraph.clone( d,prop);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); 222 219 nodelist.push_back(newind); 223 220 sgraph[newind].LH=LH; … … 226 223 sgraph[newind].LV.reset(); 227 224 228 copy_links( d,newind);225 copy_links(anc,newind); 229 226 create_reverse_links(newind); 230 227 231 if(debug) sgraph.print_node_debug(stderr," C ",newind,d);228 if(debug) sgraph.print_node_debug(stderr,"ADD NEW",newind,anc); 232 229 // if(debug) print_sets(newind); 233 230 … … 253 250 bitset<MAXNODES> newheadLV = sgraph[d].LV; 254 251 bitset<MAXNODES> newheadLD = sgraph[h].LD; 255 256 // vector<int> newedge;257 252 258 253 newheadind = find_existing_node(sgraph[h].mnode, newheadprop, newheadLH, newheadLV); … … 302 297 if(sgraph[d].saturated()) sgraph[newheadind].LD |= sgraph[d].LD; 303 298 304 if(debug) sgraph.print_arc(stderr, newheadind,d,l.role,0);305 if(debug) sgraph.print_node_debug(stderr," U",newheadind,h);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); 306 301 // if(debug) print_sets(newheadind); 307 if(debug) sgraph.print_node_debug(stderr," U",newdepind,d);302 if(debug) sgraph.print_node_debug(stderr,"update",newdepind,d); 308 303 // if(debug) print_sets(newdepind); 309 304 } … … 380 375 if(sgraph[newheadind].saturated()) sgraph[newdepind].LH |= sgraph[newheadind].LH; 381 376 382 if(debug) sgraph.print_arc(stderr,newheadind,newdepind,l.role,1); 383 if(debug) sgraph.print_node_debug(stderr,"U ",newheadind,h); 384 if(debug) sgraph.print_node_debug(stderr,"U ",newdepind,d); 385 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 // } 418 419 //==================================================================================================== 420 421 bool check_meeting_boubles(list<Boubble*>& boubbles) 422 { 423 bool hremove=false; // czy usun±æ ostatnio sprawdzany b±bel 424 bool dremove=false; // czy usun±æ ostatnio sprawdzany b±bel 425 426 for(list<Boubble*>::iterator hb = boubbles.begin(); hb != boubbles.end(); hb = hremove ? boubbles.erase(hb) : ++hb ) 427 { 428 cout << endl << "hb:" << **hb ; 429 hremove=false; 430 for(list<Boubble*>::iterator db = hb; db != boubbles.end(); db = dremove ? boubbles.erase(db) : ++db ) 431 { 432 cout << " db:" << **db; 433 dremove=false; 434 if( (*hb)->rel()==(*db)->rel() && (*hb)->reverse()!=(*db)->reverse() ) 435 { 436 cout << "Z"; 437 int srcnode,dstnode; 438 if( (*hb)->reverse()==false ) 439 srcnode = (*hb)->src(), dstnode = (*db)->src(); 440 else 441 srcnode = (*db)->src(), dstnode = (*hb)->src(); 442 if( grammar.check_longrel(sgraph.cat(srcnode), sgraph.cat(dstnode), (*hb)->rel()) ) 443 { 444 cout << " REMOVE "; 445 hremove=dremove=true; 446 if(debug) fprintf(stderr,"BOUBBLES MET!!!\n"); 447 } 448 else 449 { 450 cout << " FAIL "; 451 if(debug) fprintf(stderr,"BOUBBLES' MEETING FAILED!!!\n"); 452 return false; 453 } 454 } 455 } 456 } 457 return true; 386 458 } 387 459 … … 393 465 bool check_boubbles_at_target(list<Boubble*>& boubbles, int node) 394 466 { 395 list<Boubble*>::iterator last; // ostatnio sprawdzany b±bel396 467 bool remove=false; // czy usun±æ ostatnio sprawdzany b±bel 397 468 … … 399 470 if( (*b)->is_at_target() ) 400 471 if( grammar.check_longrel(sgraph.cat((*b)->src()), sgraph.cat(node), (*b)->rel()) ) 401 remove=true; 472 { 473 cout << endl << "REMOVE ChBatT " << **b << endl; 474 remove=true; 475 } 402 476 else 403 477 return false; … … 412 486 void try_connect_dependents(int j) 413 487 { 414 // for(list<int>::iterator i(j); i!=nodelist.begin(); --i)415 // if(sgraph.visible(*i,*j) && sgraph.saturated(*i))416 488 LViterator lvi(sgraph,j); 417 489 int i; 418 490 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!!! 424 list<const Link*>::iterator ri = ji_links.begin(); 425 if(ri == ji_links.end()) { if(debug) fprintf(stderr,"no roles\n"); } 491 { 492 //if(debug) sgraph.print_node_debug(stderr,"D-CUR>",i,-1); 493 494 if(sgraph.saturated(i)) 495 { 496 if(debug) {fprintf(stderr,"%d <--",i); } 497 498 list<const Link*> ji_links = grammar.connectable2( sgraph.cat(j), sgraph.cat(i), sgraph[j].prop.flags, sgraph[i].prop.flags); // ref do Roles!!! 499 list<const Link*>::iterator ri = ji_links.begin(); 500 if(ri == ji_links.end()) { if(debug) fprintf(stderr," no roles\n"); } 501 else 502 { 503 for(; ri != ji_links.end(); ++ri ) 504 { 505 if(debug) fprintf(stderr," %s",(*ri)->role.str()); 506 if(!grammar.check_constr2(sgraph[j].prop,sgraph[i].prop,0,**ri )) 507 { if(debug) fprintf(stderr," ...constraints failed\n"); } 508 else 509 { 510 list<Boubble*> new_head_boubbles = collect_head_boubbles(j,i,(*ri)->role); 511 list<Boubble*> new_dep_boubbles = collect_dep_boubbles(j,i,(*ri)->role); 512 if( check_meeting_boubles(new_head_boubbles) && 513 check_meeting_boubles(new_dep_boubbles) && 514 check_boubbles_at_target(new_head_boubbles,j) && 515 check_boubbles_at_target(new_dep_boubbles,i) ) 516 { 517 if(debug) fprintf(stderr," ...SUCCESS!\n"); 518 connect_left( j, i, **ri, new_head_boubbles, new_dep_boubbles); 519 } 520 else 521 { if(debug) fprintf(stderr," ...boubbles failed\n"); } 522 } 523 } 524 } 525 } 426 526 else 427 { 428 for(; ri != ji_links.end(); ++ri ) 429 if(!grammar.check_constr2(sgraph[j].prop,sgraph[i].prop,0,**ri )) 430 { if(debug) fprintf(stderr,"constraints failed\n"); } 431 else 432 { 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); 435 436 if( !(check_boubbles_at_target(new_head_boubbles,j) && check_boubbles_at_target(new_dep_boubbles,i)) ) 437 { if(debug) fprintf(stderr,"boubbles failed\n"); } 438 else 439 { 440 if(debug) fprintf(stderr,"success\n"); 441 connect_left( j, i, **ri, new_head_boubbles, new_dep_boubbles); 442 } 443 } 444 } 445 } 446 } 447 448 527 if(debug) {fprintf(stderr,"%d <-- unsaturated\n",i); } 528 } 529 530 } 449 531 //---------------------------------------------------------------------------------------------------- 450 532 451 533 void try_connect_heads(int j) 452 534 { 453 // for(list<int>::iterator i(j); i!=nodelist.begin(); --i)454 // if(sgraph.visible(*i,*j) && sgraph.saturated(*j))455 456 535 LViterator lvi(sgraph,j); 457 536 int i; 458 537 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 ); 464 list<const Link*>::iterator ri = ij_links.begin(); 465 if(ri == ij_links.end()) { if(debug) fprintf(stderr,"no roles\n"); } 538 { 539 // if(debug) sgraph.print_node_debug(stderr,"H-CUR> ",i,-1); 540 if(sgraph.saturated(j)) 541 { 542 if(debug) fprintf(stderr, "%d -->",i); 543 544 list<const Link*> ij_links = grammar.connectable2( sgraph.cat(i), sgraph.cat(j), sgraph[i].prop.flags, sgraph[j].prop.flags ); 545 list<const Link*>::iterator ri = ij_links.begin(); 546 if(ri == ij_links.end()) { if(debug) fprintf(stderr," no roles\n"); } 547 else 548 { 549 for(; ri != ij_links.end(); ++ri ) 550 { 551 if(debug) fprintf(stderr," %s",(*ri)->role.str()); 552 if( !grammar.check_constr2( sgraph[i].prop, sgraph[j].prop, 1, **ri ) ) 553 { if(debug) fprintf(stderr," ...constraints failed\n"); } 554 else 555 { 556 list<Boubble*> new_head_boubbles = collect_head_boubbles(i,j,(*ri)->role); 557 list<Boubble*> new_dep_boubbles = collect_dep_boubbles(i,j,(*ri)->role); 558 559 if( check_meeting_boubles(new_head_boubbles) && 560 check_meeting_boubles(new_dep_boubbles) && 561 check_boubbles_at_target(new_head_boubbles,i) && 562 check_boubbles_at_target(new_dep_boubbles,j) ) 563 { 564 if(debug) fprintf(stderr," ...SUCCESS!\n"); 565 connect_right( i, j, **ri, new_head_boubbles, new_dep_boubbles ); 566 } 567 else 568 { if(debug) fprintf(stderr," ...bubbles failed\n",i); } 569 } 570 } 571 } 572 } 466 573 else 467 { 468 for(; ri != ij_links.end(); ++ri ) 469 if( !grammar.check_constr2( sgraph[i].prop, sgraph[j].prop, 1, **ri ) ) 470 { if(debug) fprintf(stderr,"constraints failed\n"); } 471 else 472 { 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); 475 476 if( !(check_boubbles_at_target(new_head_boubbles,i) && check_boubbles_at_target(new_dep_boubbles,j)) ) 477 { if(debug) fprintf(stderr,"boubbles failed\n"); } 478 else 479 { 480 if(debug) fprintf(stderr,"success\n"); 481 connect_right( i, j, **ri, new_head_boubbles, new_dep_boubbles ); 482 } 483 } 484 } 574 if(debug) {fprintf(stderr,"%d <-- unsaturated\n",j); } 485 575 } 486 576 } … … 571 661 nodelist.push_back(basenode); 572 662 573 if(debug) sgraph.print_node_debug(stderr," B",basenode,-1); // STDOUT!!!574 if(debug) print_sets(basenode);663 if(debug) sgraph.print_node_debug(stderr,"add base",basenode,-1); // STDOUT!!! 664 // if(debug) print_sets(basenode); 575 665 576 666 list<int>::iterator cursor=processed; 577 667 while(++cursor != nodelist.end()) 578 668 { 579 if(debug) sgraph.print_node_debug(stderr," > ",*cursor,-1);669 if(debug) sgraph.print_node_debug(stderr,"MAIN-CUR> ",*cursor,-1); 580 670 try_connect_dependents(*cursor); 581 671 try_connect_heads(*cursor);
Note: See TracChangeset
for help on using the changeset viewer.