Changeset acbabee for src/dgp/dgp1.cc
- Timestamp:
- 12/17/14 12:13:11 (10 years ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/dgp/dgp1.cc
rd484a32 racbabee 2 2 using namespace std; 3 3 4 #include "dgp 0.hh"4 #include "dgp1.hh" 5 5 #include "global.hh" 6 6 … … 71 71 //==================================================================================================== 72 72 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; 73 int 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; 94 82 } 95 83 … … 161 149 //==================================================================================================== 162 150 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 );151 int create_new_node(int anc, NodeProp& prop, Edge edge) 152 { 153 int newheadind = sgraph.clone(anc,prop,edge); 166 154 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 172 155 copy_links(anc,newheadind); 173 156 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); 176 158 // if(debug) print_sets(newheadind); 177 159 return newheadind; 178 160 } 179 161 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 234 162 //==================================================================================================== 235 163 … … 237 165 { 238 166 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 195 void 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 ) 257 205 { 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; 261 208 } 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 } 418 227 419 228 //==================================================================================================== … … 424 233 bool dremove=false; // czy usun±æ ostatnio sprawdzany b±bel 425 234 235 // cerr << "CHECKING MEETING BUBBLES" << endl; 236 426 237 for(list<Boubble*>::iterator hb = boubbles.begin(); hb != boubbles.end(); hb = hremove ? boubbles.erase(hb) : ++hb ) 427 238 { 428 cout << endl << "hb:" << **hb ;429 239 hremove=false; 430 240 for(list<Boubble*>::iterator db = hb; db != boubbles.end(); db = dremove ? boubbles.erase(db) : ++db ) 431 241 { 432 cout<< " db:" << **db;242 // cerr << " db:" << **db; 433 243 dremove=false; 434 244 if( (*hb)->rel()==(*db)->rel() && (*hb)->reverse()!=(*db)->reverse() ) 435 245 { 436 cout << "Z";246 // cerr << "Z"; 437 247 int srcnode,dstnode; 438 248 if( (*hb)->reverse()==false ) … … 442 252 if( grammar.check_longrel(sgraph.cat(srcnode), sgraph.cat(dstnode), (*hb)->rel()) ) 443 253 { 444 cout<< " REMOVE ";254 // cerr << " REMOVE "; 445 255 hremove=dremove=true; 446 256 if(debug) fprintf(stderr,"BOUBBLES MET!!!\n"); … … 448 258 else 449 259 { 450 cout<< " FAIL ";260 // cerr << " FAIL "; 451 261 if(debug) fprintf(stderr,"BOUBBLES' MEETING FAILED!!!\n"); 452 262 return false; … … 471 281 if( grammar.check_longrel(sgraph.cat((*b)->src()), sgraph.cat(node), (*b)->rel()) ) 472 282 { 473 cout<< endl << "REMOVE ChBatT " << **b << endl;283 // cerr << endl << "REMOVE ChBatT " << **b << endl; 474 284 remove=true; 475 285 } … … 489 299 int i; 490 300 while((i=lvi.next()) >= 0) 491 {492 //if(debug) sgraph.print_node_debug(stderr,"D-CUR>",i,-1);493 494 301 if(sgraph.saturated(i)) 495 302 { 496 if(debug) {fprintf(stderr," %d <--",i); }303 if(debug) {fprintf(stderr,"\t%d <-- %d",i,j); } 497 304 498 305 list<const Link*> ji_links = grammar.connectable2( sgraph.cat(j), sgraph.cat(i), sgraph[j].prop.flags, sgraph[i].prop.flags); // ref do Roles!!! … … 517 324 if(debug) fprintf(stderr," ...SUCCESS!\n"); 518 325 connect_left( j, i, **ri, new_head_boubbles, new_dep_boubbles); 519 lvi.update_edge(sgraph,i);326 // lvi.update_edge(sgraph,i); 520 327 } 521 328 else … … 526 333 } 527 334 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); } 531 336 } 532 337 //---------------------------------------------------------------------------------------------------- … … 537 342 int i; 538 343 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); } 577 379 } 578 380 … … 662 464 nodelist.push_back(basenode); 663 465 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!!! 665 467 // if(debug) print_sets(basenode); 666 468 … … 668 470 while(++cursor != nodelist.end()) 669 471 { 670 if(debug) sgraph.print_node_debug(stderr," MAIN-CUR>",*cursor,-1);472 if(debug) sgraph.print_node_debug(stderr,"CUR>",*cursor,-1); 671 473 try_connect_dependents(*cursor); 672 474 try_connect_heads(*cursor);
Note: See TracChangeset
for help on using the changeset viewer.