- 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)
- Location:
- src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/compdic/compdic-dic-to-fst
rf600a02 racbabee 2 2 3 3 no_of_parts=0 4 part_size=100000 4 5 5 6 while [ $# -gt 2 ] … … 37 38 if [ $no_of_parts -eq 0 ] 38 39 then 39 no_of_parts=$(( `cat $1 | wc -l` / 75000+ 1 ))40 no_of_parts=$(( `cat $1 | wc -l` / $part_size + 1 )) 40 41 fi 41 42 -
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); -
src/dgp/dgp1.hh
re7de6cc racbabee 1 #ifndef _DGP 0_HH2 #define _DGP 0_HH1 #ifndef _DGP1_HH 2 #define _DGP1_HH 3 3 4 4 #include "grammar.hh" -
src/dgp/sgraph.cc
rd484a32 racbabee 1 #include "global.hh"2 1 #include "sgraph.hh" 3 2 #include "grammar.hh" … … 16 15 newnode.mnode=mnodeind; 17 16 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 // } 25 24 26 25 mgraph[newnode.mnode].snodes.push_back(lastnodeind()); 27 26 28 newnode.in_LH=true;27 // newnode.in_LH=true; 29 28 30 newnode.edge.push_back(lastnodeind());29 // newnode.edge.push_back(lastnodeind()); 31 30 32 newnode.edge _contains_self = true;31 newnode.edge.insert_self(); 33 32 34 33 return lastnodeind(); … … 55 54 //==================================================================================================== 56 55 57 int SGraph::clone(int ancind, NodeProp newprop )56 int SGraph::clone(int ancind, NodeProp newprop, Edge edge) 58 57 { 59 58 SNode &newnode=makenewnode(); 60 59 SNode &ancnode = nodes[ancind]; 61 60 62 newnode.prop=newprop; 63 newnode.mnode=ancnode.mnode; 61 newnode.prop = newprop; 62 newnode.edge = edge; 63 newnode.mnode = ancnode.mnode; 64 64 mgraph[newnode.mnode].snodes.push_back(lastnodeind()); 65 65 … … 90 90 { 91 91 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()); 93 93 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()); 95 95 } 96 96 … … 172 172 { 173 173 char *buf0 = buf; 174 buf+=sprintf(buf,"%- 10s",pref);174 buf+=sprintf(buf,"%-8s",pref); 175 175 buf+=sprintf(buf,"%d.%s",n,form(n)); 176 176 buf+=sprintf(buf,";"); 177 177 buf+=sprintf(buf,"%s ",cat(n).str()); 178 178 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); 180 180 181 181 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++ ) 183 185 buf += sprintf(buf,"%d ", *e); 184 186 -
src/dgp/sgraph.hh
rd484a32 racbabee 13 13 #include "thesymbols.hh" 14 14 #include "boubble.hh" 15 15 #include "global.hh" 16 16 17 17 using namespace std; … … 116 116 } 117 117 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() 118 inline NodeProp::~NodeProp() { clear_boubbles(); } 119 inline NodeProp::NodeProp() { clear(); } 120 inline NodeProp::NodeProp(const NodeProp& p) { copy(p); } 121 inline NodeProp& NodeProp::operator=(const NodeProp& p) { clear(); copy(p); return *this; } 122 inline void NodeProp::clear() 155 123 { 156 124 required.reset(); … … 163 131 164 132 //==================================================================================================== 133 // CLASS Edge 134 //==================================================================================================== 135 136 class Edge 137 { 138 public: 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 152 private: 153 bool _self; 154 list<int> _others; 155 }; 156 157 //==================================================================================================== 165 158 // CLASS SNode 166 159 //==================================================================================================== … … 175 168 NodeProp prop; 176 169 177 vector<int> edge; 178 bool edge_contains_self; 170 Edge edge; 179 171 bool visible_as_neighbour; 180 172 … … 189 181 void clear(); 190 182 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; } 191 191 }; 192 192 … … 216 216 void clear() { nodes.clear(); } 217 217 int add_base_snode(int mnodeind); 218 int clone(int ancind, NodeProp newprop );218 int clone(int ancind, NodeProp newprop, Edge edge); 219 219 void update_left(int headind, int depind); 220 220 void update_right(int headind, int depind); … … 299 299 300 300 private: 301 301 int snode; 302 302 SGraph& sgraph; 303 303 MGraph& mgraph; … … 312 312 }; 313 313 314 inline LViterator::LViterator(SGraph& sg, int n, bool s=true) : s graph(sg), mgraph(sg.mgraph), strict(s)315 { 316 if(sg[n].edge _contains_self) // TO DODAÆ PO PRZEJŠCIU NA EDGE_CONTAINS_SELF314 inline 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()) 317 317 { 318 318 push_ld(n); … … 320 320 } 321 321 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) 336 323 { 337 324 push_ld(*i); 338 325 push_ln(*i); 326 327 } 328 } 329 330 inline 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); 339 342 } 340 343 } … … 345 348 { 346 349 if(waydown.empty()) 347 return -1; // 350 { 351 if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,-1); 352 return -1; // 353 } 348 354 else 349 355 { … … 353 359 push_ln(k); 354 360 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 } 356 365 else 357 366 { … … 359 368 wayup.pop(); 360 369 push_lh(i); 370 if(debug) fprintf(stderr,"\t\tLViterator(%d)\treturn %d\n",snode,i); 361 371 return i; 362 372 } … … 364 374 365 375 } 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 386 inline 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 397 inline 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 408 inline 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 427 class LNiterator 428 { 429 public: 430 LNiterator(SGraph& sg, int n); 431 432 int next(); 433 434 private: 435 int snode; 436 SGraph& sgraph; 437 MGraph& mgraph; 438 stack<int> wayup; 439 440 void push_ln(int i); 441 }; 442 443 inline LNiterator::LNiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), snode(n) 444 { 445 push_ln(n); 446 } 447 448 inline 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 464 inline 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 482 class LHiterator 483 { 484 public: 485 LHiterator(SGraph& sg, int n); 486 487 int next(); 488 489 private: 490 int snode; 491 SGraph& sgraph; 492 MGraph& mgraph; 493 stack<int> wayup; 494 495 void push_lh(int i); 496 }; 497 498 inline LHiterator::LHiterator(SGraph& sg, int n) : snode(n), sgraph(sg), mgraph(sg.mgraph) 499 { 500 push_lh(n); 501 } 502 503 inline int LHiterator::next() 504 { 505 if(wayup.empty()) 506 return -1; 366 507 else 367 508 { … … 373 514 } 374 515 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) 516 inline void LHiterator::push_lh(int i) 384 517 { 385 518 vector<Arc>& arcs = sgraph[i].heads; 386 519 for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 387 520 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 530 class LDiterator 408 531 { 409 532 public: 410 L Niterator(SGraph& sg, int n);533 LDiterator(SGraph& sg, int n); 411 534 412 535 int next(); 413 536 414 537 private: 415 538 int snode; 416 539 SGraph& sgraph; 417 540 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 else434 {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 mgraph445 {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 LHiterator457 {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 else482 {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 LDiterator502 {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;513 541 stack<int> waydown; 514 542 … … 516 544 }; 517 545 518 inline LDiterator::LDiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), thenode(n)546 inline LDiterator::LDiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), snode(n) 519 547 { 520 548 push_ld(n); … … 538 566 vector<Arc>& arcs = sgraph[i].deps; 539 567 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 } 545 574 546 575 #endif -
src/sen/sen.l
rac25afd racbabee 54 54 .* { ECHO; set_position(); } 55 55 56 <<EOF>> { printf("%04d 00 EOS *\n",pos+len); exit( 1); }56 <<EOF>> { printf("%04d 00 EOS *\n",pos+len); exit(0); } 57 57 58 58 %% -
src/tre/tre
r0a58b3f racbabee 13 13 [ '--format', '-F', GetoptLong::REQUIRED_ARGUMENT ], 14 14 [ '--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 ], 15 19 [ '--span', '-s', GetoptLong::REQUIRED_ARGUMENT ], 16 20 [ '--maxsize', GetoptLong::REQUIRED_ARGUMENT ], 17 21 [ '--forest', GetoptLong::NO_ARGUMENT ], 18 [ '--ground', GetoptLong::NO_ARGUMENT ],19 22 [ '--only-trees','-t', GetoptLong::NO_ARGUMENT ]) 20 23 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 25 The program generates trees from the graph output by dgp. dgp must be run 26 with '--info=ds' option. 27 28 Command: tre [options] 29 30 Options: 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 50 END 39 51 40 52 $DEBUG=false 41 53 $FORMAT='p' 42 54 $INFO='DEFAULT' 43 $ ONLYTREES=false55 $UTTOUTPUT=false 44 56 $START=nil 45 57 $END=nil 46 58 $FOREST=false 47 59 $MAXSIZE=nil 60 $GPHIDS=false 61 $DGPIDS=false 62 $GRAPH==false 48 63 49 64 opts.each do |opt, arg| … … 58 73 when '--info' 59 74 $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 62 85 when '--forest' 63 86 $FOREST=true 64 when '--ground'65 $GROUND=true66 87 when '--maxsize' 67 88 $MAXSIZE=arg.to_i … … 76 97 case $FORMAT 77 98 when 'p','a' 78 $INFO=' nl'99 $INFO='fl' 79 100 when 'h' 80 101 $INFO='fmnl' … … 95 116 for line in input 96 117 seg=Seg.new(line) 97 print line unless $ONLYTREES ||seg.field(3) == 'EOS'118 print line if $UTTOUTPUT && seg.field(3) == 'EOS' 98 119 99 120 if dgp=seg['dgp'] … … 122 143 123 144 $pref = "#{seg[1]} #{seg[2]} SYN *" 124 125 145 parsegraph(nodes) 126 127 146 set_ord #(0...(nodes.length)).each{|i| set_distance_from_i i } 128 129 147 printgraph if $DEBUG 130 131 if $GROUND 132 printground 148 if $GRAPH 149 if $FORMAT =~ /c/ 150 printconll 151 else 152 printground 153 end 133 154 else 134 155 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=[] 141 161 $form=[] 142 162 $lem=[] … … 154 174 155 175 def output_trees trees 176 177 outputs = [] 178 156 179 for t in trees 157 180 $count += 1 … … 160 183 t1=t 161 184 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 163 197 case $FORMAT 164 198 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" 168 200 when /p/ 169 print "#{$pref}#{span} tre:#{$count} par:" 170 printpar(t1[0],t1[1]) 171 print "\n" 201 outputs << "#{par_output(t1)}\n" 172 202 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 212 end 213 214 def id_output id 215 if $DGPIDS then id elsif $GPHIDS then $gphid[id] else $ord1[$gphid[id]] end 216 end 179 217 180 218 def nodeinfo(id) … … 186 224 end 187 225 if $INFO =~ /n/ 188 info += gphid.to_s226 info += id_output(id).to_s 189 227 info += '.' if $INFO =~ /[fm]/ 190 228 end … … 200 238 201 239 202 def arcsinfo(root,arcs) 240 def arc_output(tree) 241 root, arcs = tree 203 242 "head:#{nodeinfo(root)} links:" + arcs.map{|a| "(#{($INFO =~ /l/) ? a[2]+":" : ""}#{nodeinfo(a[0])}-#{nodeinfo(a[1])})"}.join("") 204 # for a in arcs205 # print ';'206 # print "#{a[2]}:" if $INFO =~ /l/207 # print nodeinfo(a[0])+'-'+nodeinfo(a[1])208 # end209 243 end 210 244 … … 221 255 end 222 256 223 def printtree_dgp(root,arcs,o) 257 def human_output(tree,o) 258 root, arcs = tree 259 output = '' 224 260 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" 228 264 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 270 end 271 272 def 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" 289 end 290 291 def par_output(tree) 292 root, arcs = tree 253 293 ldeps = arcs.select{|a| a[0]==root and $gphid[a[1]] < $gphid[root]}.sort{|a,b| $gphid[a[1]]<=>$gphid[b[1]] } 254 294 rdeps = arcs.select{|a| a[0]==root and $gphid[a[1]] > $gphid[root]}.sort{|a,b| $gphid[a[1]]<=>$gphid[b[1]] } 255 295 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 271 319 end 272 320 … … 467 515 end 468 516 517 def 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 530 end 531 469 532 470 533 def set_to_s(s) "{#{s.join(',')}}" end
Note: See TracChangeset
for help on using the changeset viewer.