- Timestamp:
- 01/17/13 20:50:41 (12 years ago)
- Branches:
- master
- Children:
- d2f119e
- Parents:
- 555c7f8
- git-author:
- Tomasz Obrebski <to@…> (01/17/13 20:50:41)
- git-committer:
- Tomasz Obrebski <to@…> (01/17/13 20:50:41)
- Location:
- src/dgp
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/dgp/boubble.hh
re7de6cc r3b02b04 26 26 Boubble(list<Role> u, list<Role> d, LongRel l, int s=-1); 27 27 Boubble(const char* pathstr, const char* l, int s=-1); 28 // Boubble(const Boubble& b) {_src=b._src; _upath=b._upath; _dpath=b._dpath; _rel=b._rel; }; 28 29 29 30 Dir dir(); … … 138 139 } 139 140 140 if(d==DOWN && _upath.empty() && !_dpath.empty() )141 if(d==DOWN && _upath.empty() && !_dpath.empty() && _dpath.front() == r) 141 142 { 142 143 Boubble* newboubble = new Boubble(_upath,_dpath,_rel,_src); -
src/dgp/dgp1.cc
ra15e59b r3b02b04 10 10 list<int> nodelist; 11 11 list<int>::iterator processed; 12 13 14 void print_sets(int n); 15 12 16 13 17 //==================================================================================================== … … 44 48 ret.forbidden |= grammar.constr_exclude(link.role); 45 49 46 ret.boubbles =bs;50 ret.boubbles.merge(bs); //DOBRZE 47 51 ret.flags |= ( depflags & grammar.pass_flags(link.role) ); 48 52 … … 58 62 { 59 63 NodeProp ret=depprop; 60 ret.boubbles =bs;64 ret.boubbles.merge(bs); //DOBRZE 61 65 return ret; 62 66 } … … 67 71 { 68 72 MNode& mnode = mgraph[mnodeind]; 73 int ret=-1; 69 74 for(vector<int>::iterator ps=mnode.snodes.begin(); ps!=mnode.snodes.end(); ++ps) 70 if(sgraph[*ps].prop==p && sgraph[*ps].LH==newheadLH && sgraph[*ps].LV==newheadLV) return *ps; 71 return -1; 75 { 76 if(debug) fprintf(stderr,"#find existing node: checking %d ... \n", *ps); 77 if(sgraph[*ps].prop==p) 78 if(sgraph[*ps].LH==newheadLH && sgraph[*ps].LV==newheadLV) 79 { 80 ret = *ps; 81 // fprintf(stderr,"FIND EXISTING NODE SUCCEEDED BEACAUSE OF LH/LV equality ()\n"); 82 } 83 else 84 { 85 // fprintf(stderr,"FIND EXISTING NODE FAILED BEACAUSE OF LH/LV inequality\n"); 86 } 87 } 88 89 if(debug) fprintf(stderr,"\n"); 90 return ret; 72 91 } 73 92 … … 83 102 ret.push_back(new_boubble); 84 103 } 104 85 105 return ret; 86 106 } … … 120 140 //==================================================================================================== 121 141 122 int create_new_head_node_left(list<int>::iterator h, NodeProp& newheadprop, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLD, bitset<MAXNODES>& newheadLV) 123 { 124 int newheadind = sgraph.clone(*h,newheadprop); 125 list<int>::iterator nextit=h; ++nextit; 126 nodelist.insert(nextit,newheadind); 142 void copy_links(int i, int j) 143 { 144 sgraph[j].heads = sgraph[i].heads; 145 sgraph[j].deps = sgraph[i].deps; 146 } 147 148 149 void create_reverse_links(int n) 150 { 151 for(vector<Arc>::iterator a=sgraph[n].heads.begin(); a != sgraph[n].heads.end(); a++) 152 sgraph[a->dst].deps.push_back(Arc(n,a->role,a->headanc,a->depanc)); 153 154 for(vector<Arc>::iterator a=sgraph[n].deps.begin(); a != sgraph[n].deps.end(); a++) 155 sgraph[a->dst].heads.push_back(Arc(n,a->role,a->headanc,a->depanc)); 156 } 157 158 //==================================================================================================== 159 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); 165 nodelist.push_back(newheadind); 127 166 sgraph[newheadind].LH=newheadLH; 128 167 sgraph[newheadind].LD = newheadLD; 129 168 sgraph[newheadind].in_LH=true; 130 169 sgraph[newheadind].LV.reset(); 131 132 if(debug) sgraph.print_node_debug(stderr,"C ",newheadind,*h); 133 170 171 copy_links(h,newheadind); 172 create_reverse_links(newheadind); 173 174 if(debug) sgraph.print_node_debug(stderr,"C ",newheadind,h); 175 if(debug) print_sets(newheadind); 134 176 return newheadind; 135 177 } 136 178 137 int create_new_dep_node_left(list<int>::iterator d, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV) 138 { 139 int newind = sgraph.clone(*d,prop); 140 list<int>::iterator nextit=d; ++nextit; 141 nodelist.insert(nextit,newind); 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); 184 nodelist.push_back(newind); 142 185 sgraph[newind].LH.reset(); 143 186 sgraph[newind].LD=LD; 144 187 sgraph[newind].in_LH=false; //??????? 145 188 sgraph[newind].LV.reset(); 146 147 if(debug) sgraph.print_node_debug(stderr,"C ",newind,*d); 189 190 copy_links(d,newind); 191 create_reverse_links(newind); 192 193 if(debug) sgraph.print_node_debug(stderr,"C ",newind,d); 194 if(debug) print_sets(newind); 148 195 149 196 return newind; 150 197 } 151 198 152 int create_new_head_node_right(list<int>::iterator h, NodeProp& newheadprop, bitset<MAXNODES>& newheadLH, bitset<MAXNODES>& newheadLD, bitset<MAXNODES>& newheadLV) 153 { 154 int newheadind = sgraph.clone(*h,newheadprop); 155 list<int>::iterator nextit=h; ++nextit; 156 nodelist.insert(nextit,newheadind); 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); 204 nodelist.push_back(newheadind); 157 205 sgraph[newheadind].LH=newheadLH; 158 206 sgraph[newheadind].LD=newheadLD; … … 160 208 sgraph[newheadind].LV=newheadLV; 161 209 162 if(debug) sgraph.print_node_debug(stderr,"C ",newheadind,*h); 210 copy_links(h,newheadind); 211 create_reverse_links(newheadind); 212 213 if(debug) sgraph.print_node_debug(stderr,"C ",newheadind,h); 214 if(debug) print_sets(newheadind); 163 215 164 216 return newheadind; 165 217 } 166 218 167 int create_new_dep_node_right(list<int>::iterator d, NodeProp& prop, bitset<MAXNODES>& LH, bitset<MAXNODES>& LD, bitset<MAXNODES>& LV) 168 { 169 int newind = sgraph.clone(*d,prop); 170 list<int>::iterator nextit=d; ++nextit; 171 nodelist.insert(nextit,newind); 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); 222 nodelist.push_back(newind); 172 223 sgraph[newind].LH=LH; 173 224 sgraph[newind].LD=LD; … … 175 226 sgraph[newind].LV.reset(); 176 227 177 if(debug) sgraph.print_node_debug(stderr,"C ",newind,*d); 228 copy_links(d,newind); 229 create_reverse_links(newind); 230 231 if(debug) sgraph.print_node_debug(stderr,"C ",newind,d); 232 if(debug) print_sets(newind); 178 233 179 234 return newind; … … 182 237 //==================================================================================================== 183 238 184 void connect_left( list<int>::iterator h, list<int>::iteratord, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles)185 { 186 187 NodeProp &oldheadprop = sgraph[ *h].prop;188 NodeProp &olddepprop = sgraph[ *d].prop;239 void connect_left(int h, int d, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles) 240 { 241 242 NodeProp &oldheadprop = sgraph[h].prop; 243 NodeProp &olddepprop = sgraph[d].prop; 189 244 190 245 NodeProp newheadprop = compute_head_prop(oldheadprop,l,new_head_boubbles,olddepprop.flags); … … 192 247 int newheadind; 193 248 if(oldheadprop==newheadprop) 194 newheadind = *h;249 newheadind = h; 195 250 else 196 251 { 197 bitset<MAXNODES> newheadLH = sgraph[*h].LH; 198 bitset<MAXNODES> newheadLV = sgraph[*d].LV; 199 bitset<MAXNODES> newheadLD = sgraph[*h].LD; 200 201 newheadind = find_existing_node(sgraph[*h].mnode, newheadprop, newheadLH, newheadLV); 202 if( newheadind >= 0 ) 252 bitset<MAXNODES> newheadLH = sgraph[h].LH; 253 bitset<MAXNODES> newheadLV = sgraph[d].LV; 254 bitset<MAXNODES> newheadLD = sgraph[h].LD; 255 256 // vector<int> newedge; 257 258 newheadind = find_existing_node(sgraph[h].mnode, newheadprop, newheadLH, newheadLV); 259 if( newheadind >= 0) // W£¡CZONE 203 260 sgraph[newheadind].LD |= newheadLD; 204 261 else 205 newheadind = create_new_head_node_left(h,newheadprop,newheadLH,newheadLD,newheadLV); 262 { 263 newheadind = create_new_head_node_left(h,newheadprop,newheadLH,newheadLD,newheadLV); 264 sgraph[newheadind].edge.clear(); 265 sgraph[newheadind].edge_contains_self = false; 266 } 267 206 268 } 207 269 208 209 210 270 NodeProp newdepprop = compute_dep_prop(olddepprop,l,new_dep_boubbles); 211 271 … … 213 273 214 274 if(olddepprop==newdepprop) 215 newdepind = *d;275 newdepind = d; 216 276 else 217 277 { 218 bitset<MAXNODES> newdepLH = sgraph[ *d].LH;219 bitset<MAXNODES> newdepLV = sgraph[ *d].LV;220 bitset<MAXNODES> newdepLD = sgraph[ *d].LD;221 222 newdepind = find_existing_node(sgraph[ *d].mnode, newdepprop, newdepLH, newdepLV);223 if( newdepind >= 0 )278 bitset<MAXNODES> newdepLH = sgraph[d].LH; 279 bitset<MAXNODES> newdepLV = sgraph[d].LV; 280 bitset<MAXNODES> newdepLD = sgraph[d].LD; 281 282 newdepind = find_existing_node(sgraph[d].mnode, newdepprop, newdepLH, newdepLV); 283 if( newdepind >= 0) // W£¡CZONE 224 284 sgraph[newdepind].LD |= newdepLD; // TYLKO DLA LD 225 285 else 226 newdepind = create_new_dep_node_left(d,newdepprop,newdepLH,newdepLD,newdepLV); 286 { 287 newdepind = create_new_dep_node_left(d,newdepprop,newdepLH,newdepLD,newdepLV); 288 sgraph[newdepind].edge.clear(); 289 //sgraph[newdepind].edge.push_back(newdepind); // TO 290 sgraph[newdepind].edge_contains_self = true; // LUB TO 291 } 227 292 } 228 229 sgraph[newheadind].deps.push_back(Arc(newdepind,l.role,*h,*d)); 230 231 if(sgraph[*d].saturated()) sgraph[newheadind].LV |= sgraph[*d].LV; 232 233 sgraph[newheadind].LD.set(*d); 234 if(sgraph[*d].saturated()) sgraph[newheadind].LD |= sgraph[*d].LD; 235 236 if(debug) sgraph.print_arc(stderr,newheadind,*d,l.role,0); 237 if(debug) sgraph.print_node_debug(stderr,"U ",newheadind,*h); 238 if(debug) sgraph.print_node_debug(stderr,"U ",*d,*d); 293 294 295 sgraph[newheadind].deps.push_back(Arc(newdepind,l.role,h,d)); 296 sgraph[newdepind].heads.push_back(Arc(newheadind,l.role,h,d)); 297 sgraph[newheadind].edge.push_back(newdepind); 298 299 if(sgraph[d].saturated()) sgraph[newheadind].LV |= sgraph[d].LV; 300 301 sgraph[newheadind].LD.set(d); 302 if(sgraph[d].saturated()) sgraph[newheadind].LD |= sgraph[d].LD; 303 304 if(debug) sgraph.print_arc(stderr,newheadind,d,l.role,0); 305 if(debug) sgraph.print_node_debug(stderr,"U ",newheadind,h); 306 if(debug) print_sets(newheadind); 307 if(debug) sgraph.print_node_debug(stderr,"U ",newdepind,d); 308 if(debug) print_sets(newdepind); 239 309 } 240 310 241 311 //---------------------------------------------------------------------------------------------------- 242 312 243 void connect_right( list<int>::iterator h, list<int>::iteratord, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles)244 { 245 NodeProp &oldheadprop = sgraph[ *h].prop;246 247 NodeProp newheadprop = compute_head_prop(oldheadprop,l,new_head_boubbles, sgraph[ *d].prop.flags);313 void connect_right(int h, int d, const Link& l, list<Boubble*>& new_head_boubbles, list<Boubble*>& new_dep_boubbles) 314 { 315 NodeProp &oldheadprop = sgraph[h].prop; 316 317 NodeProp newheadprop = compute_head_prop(oldheadprop,l,new_head_boubbles, sgraph[d].prop.flags); 248 318 249 319 int newheadind; 250 320 251 321 if(oldheadprop==newheadprop) 252 newheadind = *h;322 newheadind = h; 253 323 else 254 324 { 255 bitset<MAXNODES> newheadLH = sgraph[*h].LH; 256 bitset<MAXNODES> newheadLV = sgraph[*h].LV; 257 bitset<MAXNODES> newheadLD = sgraph[*h].LD; 258 259 newheadind = find_existing_node(sgraph[*h].mnode, newheadprop, newheadLH, newheadLV); 260 if( newheadind >= 0 ) 325 bitset<MAXNODES> newheadLH = sgraph[h].LH; 326 bitset<MAXNODES> newheadLV = sgraph[h].LV; 327 bitset<MAXNODES> newheadLD = sgraph[h].LD; 328 329 newheadind = find_existing_node(sgraph[h].mnode, newheadprop, newheadLH, newheadLV); 330 331 if(debug) fprintf(stderr,"#HEAD EXISTS %d\n",newheadind); 332 333 if( newheadind >= 0) // W£¡CZONE 261 334 sgraph[newheadind].LD |= newheadLD; // TYLKO DLA LD 262 335 else 263 newheadind = create_new_head_node_right(h,newheadprop,newheadLH,newheadLD,newheadLV); 336 { 337 newheadind = create_new_head_node_right(h,newheadprop,newheadLH,newheadLD,newheadLV); 338 //if(!sgraph[h].edge.empty()) sgraph[newheadind].edge.push_back(newheadind); // TO 339 sgraph[newheadind].edge_contains_self = sgraph[h].edge_contains_self; // LUB TO 340 sgraph[newheadind].visible_as_neighbour = false; 341 } 264 342 } 265 343 266 NodeProp &olddepprop = sgraph[ *d].prop;344 NodeProp &olddepprop = sgraph[d].prop; 267 345 NodeProp newdepprop = compute_dep_prop(olddepprop,l,new_dep_boubbles); 268 346 … … 270 348 271 349 if(olddepprop==newdepprop) 272 newdepind = *d;350 newdepind = d; 273 351 else 274 352 { 275 bitset<MAXNODES> newdepLH = sgraph[*d].LH; 276 bitset<MAXNODES> newdepLV = sgraph[*d].LV; 277 bitset<MAXNODES> newdepLD = sgraph[*d].LD; 278 279 newdepind = find_existing_node(sgraph[*d].mnode, newdepprop, newdepLH, newdepLV); 280 if( newdepind >= 0 ) 353 bitset<MAXNODES> newdepLH = sgraph[d].LH; 354 bitset<MAXNODES> newdepLV = sgraph[d].LV; 355 bitset<MAXNODES> newdepLD = sgraph[d].LD; 356 357 newdepind = find_existing_node(sgraph[d].mnode, newdepprop, newdepLH, newdepLV); 358 359 if(debug) fprintf(stderr,"#DEP EXISTS %d\n",newdepind); 360 361 if( newdepind >= 0) // W£¡CZONE 281 362 sgraph[newdepind].LD |= newdepLD; // TYLKO DLA LD 282 363 else 283 newdepind = create_new_dep_node_right(d,newdepprop,newdepLH,newdepLD,newdepLV); 364 { 365 newdepind = create_new_dep_node_right(d,newdepprop,newdepLH,newdepLD,newdepLV); 366 sgraph[newdepind].edge.clear(); 367 sgraph[newdepind].edge_contains_self = false; 368 } 284 369 } 285 370 286 371 287 288 289 sgraph[newdepind].heads.push_back(Arc(newheadind,l.role,*h,*d));372 sgraph[newdepind].heads.push_back(Arc(newheadind,l.role,h,d)); 373 sgraph[newheadind].deps.push_back(Arc(newdepind,l.role,h,d)); 374 //sgraph[newdepind].edge.push_back(newheadind); 290 375 291 376 sgraph[newdepind].LH.set(newheadind); … … 296 381 297 382 if(debug) sgraph.print_arc(stderr,newheadind,newdepind,l.role,1); 298 if(debug) sgraph.print_node_debug(stderr,"U ",newheadind, *h);299 if(debug) sgraph.print_node_debug(stderr,"U ",newdepind, *d);383 if(debug) sgraph.print_node_debug(stderr,"U ",newheadind,h); 384 if(debug) sgraph.print_node_debug(stderr,"U ",newdepind,d); 300 385 301 386 } … … 323 408 } 324 409 325 // bool check_boubbles_at_target(list<Boubble*> boubbles, int node) 326 // { 327 // for(list<Boubble*>::iterator b = boubbles.begin(); b != boubbles.end(); ++b ) 328 // if( (*b)->is_at_target() && !grammar.check_longrel(sgraph.cat((*b)->src()), sgraph.cat(node), (*b)->rel()) ) 329 // return false; 330 // return true; 331 // } 332 333 //==================================================================================================== 334 335 void try_connect_dependents(list<int>::iterator j) 336 { 337 for(list<int>::iterator i(j); i!=nodelist.begin(); --i) 338 if(sgraph.visible(*i,*j) && sgraph.saturated(*i)) 339 { 340 if(debug) {fprintf(stderr,"## %d <-- %d ... ",*i,*j); } 341 342 list<const Link*> ji_links = grammar.connectable2( sgraph.cat(*j), sgraph.cat(*i), sgraph[*j].prop.flags, sgraph[*i].prop.flags); // ref do Roles!!! 410 //==================================================================================================== 411 412 void try_connect_dependents(int j) 413 { 414 // for(list<int>::iterator i(j); i!=nodelist.begin(); --i) 415 // if(sgraph.visible(*i,*j) && sgraph.saturated(*i)) 416 LViterator lvi(sgraph,j); 417 int i; 418 while((i=lvi.next()) >= 0) 419 if(sgraph.saturated(i)) 420 { 421 if(debug) {fprintf(stderr,"## %d <-- %d ... ",i,j); } 422 423 list<const Link*> ji_links = grammar.connectable2( sgraph.cat(j), sgraph.cat(i), sgraph[j].prop.flags, sgraph[i].prop.flags); // ref do Roles!!! 343 424 list<const Link*>::iterator ri = ji_links.begin(); 344 425 if(ri == ji_links.end()) { if(debug) fprintf(stderr,"no roles\n"); } … … 346 427 { 347 428 for(; ri != ji_links.end(); ++ri ) 348 if(!grammar.check_constr2(sgraph[ *j].prop,sgraph[*i].prop,0,**ri ))429 if(!grammar.check_constr2(sgraph[j].prop,sgraph[i].prop,0,**ri )) 349 430 { if(debug) fprintf(stderr,"constraints failed\n"); } 350 431 else 351 432 { 352 list<Boubble*> new_head_boubbles = collect_head_boubbles( *j,*i,(*ri)->role);353 list<Boubble*> new_dep_boubbles = collect_dep_boubbles( *j,*i,(*ri)->role);433 list<Boubble*> new_head_boubbles = collect_head_boubbles(j,i,(*ri)->role); 434 list<Boubble*> new_dep_boubbles = collect_dep_boubbles(j,i,(*ri)->role); 354 435 355 if( !(check_boubbles_at_target(new_head_boubbles, *j) && check_boubbles_at_target(new_dep_boubbles,*i)) )436 if( !(check_boubbles_at_target(new_head_boubbles,j) && check_boubbles_at_target(new_dep_boubbles,i)) ) 356 437 { if(debug) fprintf(stderr,"boubbles failed\n"); } 357 438 else … … 368 449 //---------------------------------------------------------------------------------------------------- 369 450 370 void try_connect_heads(list<int>::iterator j) 371 { 372 for(list<int>::iterator i(j); i!=nodelist.begin(); --i) 373 if(sgraph.visible(*i,*j)) 374 { 375 if(debug) fprintf(stderr, "## %d --> %d ... ",*i,*j); 376 377 list<const Link*> ij_links = grammar.connectable2( sgraph.cat(*i), sgraph.cat(*j), sgraph[*i].prop.flags, sgraph[*j].prop.flags ); 451 void try_connect_heads(int j) 452 { 453 // for(list<int>::iterator i(j); i!=nodelist.begin(); --i) 454 // if(sgraph.visible(*i,*j) && sgraph.saturated(*j)) 455 456 LViterator lvi(sgraph,j); 457 int i; 458 while((i=lvi.next()) >= 0) 459 if(sgraph.saturated(j)) 460 { 461 if(debug) fprintf(stderr, "## %d --> %d ... ",i,j); 462 463 list<const Link*> ij_links = grammar.connectable2( sgraph.cat(i), sgraph.cat(j), sgraph[i].prop.flags, sgraph[j].prop.flags ); 378 464 list<const Link*>::iterator ri = ij_links.begin(); 379 465 if(ri == ij_links.end()) { if(debug) fprintf(stderr,"no roles\n"); } … … 381 467 { 382 468 for(; ri != ij_links.end(); ++ri ) 383 if( !grammar.check_constr2( sgraph[ *i].prop, sgraph[*j].prop, 1, **ri ) )469 if( !grammar.check_constr2( sgraph[i].prop, sgraph[j].prop, 1, **ri ) ) 384 470 { if(debug) fprintf(stderr,"constraints failed\n"); } 385 471 else 386 472 { 387 list<Boubble*> new_head_boubbles = collect_head_boubbles( *i,*j,(*ri)->role);388 list<Boubble*> new_dep_boubbles = collect_dep_boubbles( *i,*j,(*ri)->role);473 list<Boubble*> new_head_boubbles = collect_head_boubbles(i,j,(*ri)->role); 474 list<Boubble*> new_dep_boubbles = collect_dep_boubbles(i,j,(*ri)->role); 389 475 390 if( !(check_boubbles_at_target(new_head_boubbles, *i) && check_boubbles_at_target(new_dep_boubbles,*j)) )476 if( !(check_boubbles_at_target(new_head_boubbles,i) && check_boubbles_at_target(new_dep_boubbles,j)) ) 391 477 { if(debug) fprintf(stderr,"boubbles failed\n"); } 392 478 else … … 399 485 } 400 486 } 401 487 488 //==================================================================================================== 489 490 void update_sets() 491 { 492 for(int n=0; n<sgraph.size(); ++n) 493 { 494 LViterator lvi(sgraph,n,false); 495 LHiterator lhi(sgraph,n); 496 LDiterator ldi(sgraph,n); 497 int i; 498 499 // printf("UPDATING LV[%d]:",n); 500 while((i=lvi.next())>=0) 501 { 502 // printf(" %d",i); 503 sgraph[n].LV.set(i); 504 } 505 // printf("\n"); 506 507 while((i=lhi.next())>=0) sgraph[n].LH.set(i); 508 while((i=ldi.next())>=0) sgraph[n].LD.set(i); 509 } 510 } 511 512 //==================================================================================================== 513 514 void print_sets(int n) 515 { 516 LViterator lvi(sgraph,n); 517 LHiterator lhi(sgraph,n); 518 LDiterator ldi(sgraph,n); 519 520 int i; 521 printf("LV[%d]: ",n); 522 while((i=lvi.next())>=0) 523 { 524 printf("%d ",i); 525 sgraph[n].LV.set(i); 526 } 527 528 printf("LH[%d]: ",n); 529 while((i=lhi.next())>=0) 530 { 531 printf("%d ",i); 532 sgraph[n].LH.set(i); 533 } 534 printf("LD[%d]: ",n); 535 while((i=ldi.next())>=0) 536 { 537 printf("%d ",i); 538 sgraph[n].LD.set(i); 539 } 540 printf("\n"); 541 } 542 402 543 //==================================================================================================== 403 544 … … 430 571 nodelist.push_back(basenode); 431 572 432 if(debug) {sgraph.print_node_debug(stderr,"B ",basenode,-1);} // STDOUT!!! 573 if(debug) sgraph.print_node_debug(stderr,"B ",basenode,-1); // STDOUT!!! 574 if(debug) print_sets(basenode); 433 575 434 576 list<int>::iterator cursor=processed; 435 577 while(++cursor != nodelist.end()) 436 578 { 437 try_connect_dependents(cursor); 438 try_connect_heads(cursor); 579 if(debug) sgraph.print_node_debug(stderr,"> ",*cursor,-1); 580 try_connect_dependents(*cursor); 581 try_connect_heads(*cursor); 439 582 processed=cursor; 440 583 } 441 584 442 585 } 443 reverse_links(); 444 } 586 // reverse_links(); 587 update_sets(); 588 } -
src/dgp/grammar.cc
ra15e59b r3b02b04 298 298 { 299 299 char cat1[MAXLINE],flags1[MAXLINE],cat2[MAXLINE],flags2[MAXLINE],type[MAXLINE],props[MAXLINE]; 300 301 if(sscanf(arg1,"%[^;];%s",cat1,flags1)==1) *flags1='\0'; 302 if(sscanf(arg2,"%[^;];%s",cat2,flags2)==1) *flags2='\0'; 303 if(sscanf(arg3,"%[^&]%s",type,props)==1) *props='\0'; 300 char* double_slash_position; 301 // pierwszy argument 302 // if(sscanf(arg1,"%[^;];%s",cat1,flags1)==1) *flags1='\0'; 303 if((double_slash_position=strstr(arg1,"//")) != NULL) // czy s± flagi 304 { 305 int cat_length=double_slash_position-arg1; 306 strncpy(cat1, arg1, cat_length); cat1[cat_length]='\0'; 307 strcpy(flags1, arg1+cat_length+2); 308 } 309 else 310 { 311 strcpy(cat1, arg1); 312 flags1[0]='\0'; 313 } 314 // drugi argument 315 // if(sscanf(arg2,"%[^;];%s",cat2,flags2)==1) *flags2='\0'; 316 if((double_slash_position=strstr(arg2,"//")) != NULL) // czy s± flagi 317 { 318 int cat_length=double_slash_position-arg2; 319 strncpy(cat2, arg2, cat_length); cat2[cat_length]='\0'; 320 strcpy(flags2, arg2+cat_length+2); 321 } 322 else 323 { 324 strcpy(cat2,arg2); 325 flags2[0]='\0'; 326 } 327 // trzeci argument 328 if(sscanf(arg3,"%[^&]%s",type,props)==1) props[0]='\0'; 304 329 305 // printf("line=%s\n\tcat1=%s flags1=%s cat2=%s flags2=%s type=%sprops=%s\n",line,cat1,flags1,cat2,flags2,type,props);330 // printf("line=%s\n\tcat1=<%s> flags1=%s cat2=<%s> flags2=%s type=<%s> props=%s\n",line,cat1,flags1,cat2,flags2,type,props); 306 331 307 332 if( chk_cat(cat1) && chk_cat(cat2) && chk_type(type) ) … … 346 371 347 372 // compute_gt(); 348 373 349 374 return true; 350 375 -
src/dgp/main.cc
ra15e59b r3b02b04 38 38 bool printtimeinfo=false; 39 39 40 40 41 void output(); 41 42 … … 43 44 { 44 45 gengetopt_args_info args; 46 struct timeval readgrammar_starttime,readgrammar_endtime; 45 47 46 48 if(cmdline_parser(argc,argv,&args) != 0) … … 71 73 } 72 74 75 gettimeofday(&readgrammar_starttime,NULL); 76 73 77 grammar.read(grammarf); 74 78 fclose(grammarf); 75 79 80 gettimeofday(&readgrammar_endtime,NULL); 76 81 82 if(printtimeinfo) 83 fprintf(stderr,"### START TIME: %10.2fms\n", (float)MICROSECONDSELAPSED(readgrammar_starttime,readgrammar_endtime)/1000 ); 77 84 85 //////////////////////////////////////////////////////////////////////////////////////////////////// 86 // TESTOWANIE POPRAWNOŠCI ODCZYTU GRAMATYKI 78 87 // grammar.write(cout); 79 88 // exit(0); 89 //////////////////////////////////////////////////////////////////////////////////////////////////// 80 90 81 91 struct timeval starttime,afterinput,afterparse,endtime; … … 101 111 { 102 112 gettimeofday(&afterinput,NULL); 113 103 114 dgp1(); // parametry!!! MGraph, SGraph, Grammar 115 104 116 gettimeofday(&afterparse,NULL); 105 117 output(); -
src/dgp/sgraph.cc
ra15e59b r3b02b04 28 28 newnode.in_LH=true; 29 29 30 newnode.edge.push_back(lastnodeind()); 31 30 32 return lastnodeind(); 31 33 } … … 55 57 SNode &newnode=makenewnode(); 56 58 SNode &ancnode = nodes[ancind]; 57 58 59 59 60 60 newnode.prop=newprop; … … 178 178 179 179 buf+=sprint_node(buf,n,anc,HEADS|DEPS|SETS|CONSTRAINTS); 180 181 buf+=sprintf(buf,"/"); 182 for(vector<int>::iterator e = nodes[n].edge.begin(); e != nodes[n].edge.end(); e++ ) 183 buf += sprintf(buf,"%d ", *e); 184 180 185 buf+=sprintf(buf,"\n"); 181 186 return buf-buf0; -
src/dgp/sgraph.hh
re7de6cc r3b02b04 7 7 #include <vector> 8 8 #include <bitset> 9 #include <stack> 9 10 10 11 #include "const.hh" … … 71 72 if(init_attached != p.init_attached) return false; 72 73 if(fin_attached != p.fin_attached) return false; 73 74 list<Boubble*>::const_iterator b1 = p.boubbles.begin(); 75 for(list<Boubble*>::const_iterator b = boubbles.begin(); b != boubbles.end(); b++) 76 { 77 if(b1 == p.boubbles.end()) 78 return false; 79 if(!(**b == **b1)) 80 return false; 81 } 82 if(b1 != p.boubbles.end()) 74 75 list<Boubble*>::const_iterator b,b1; 76 for(b=boubbles.begin(), b1=p.boubbles.begin(); b != boubbles.end() && b1 != p.boubbles.end(); b++,b1++) 77 if(!(**b == **b1)) 78 return false; 79 if(b != boubbles.end() || b1 != p.boubbles.end()) 83 80 return false; 84 81 85 82 return true; 86 83 } … … 172 169 { 173 170 171 SNode() { visible_as_neighbour = true; } 172 174 173 int mnode; 175 174 176 175 NodeProp prop; 176 177 vector<int> edge; 178 bool edge_contains_self; 179 bool visible_as_neighbour; 177 180 178 181 bitset<MAXNODES> LV; … … 231 234 int size() {return nodes.size(); } 232 235 236 friend class LViterator; 237 friend class LHiterator; 238 friend class LDiterator; 239 friend class LNiterator; 240 233 241 private: 234 242 … … 259 267 260 268 //---------------------------------------------------------------------------------------------------- 269 //---------------------------------------------------------------------------------------------------- 270 271 class XXiterator 272 { 273 protected: 274 275 bool checked(int i) { return _checked[i]; } 276 void check(int i) { _checked.set(i); } 277 278 void push(stack<int>& s, int i) 279 { 280 if(!checked(i)) 281 { 282 s.push(i); 283 check(i); 284 } 285 } 286 287 bitset<MAXNODES> _checked; 288 }; 289 290 //---------------------------------------------------------------------------------------------------- 291 //---------------------------------------------------------------------------------------------------- 292 293 class LViterator : public XXiterator 294 { 295 public: 296 LViterator(SGraph& sg, int n, bool s); 297 int next(); 298 299 private: 300 301 SGraph& sgraph; 302 MGraph& mgraph; 303 stack<int> waydown; 304 stack<int> wayup; 305 bool strict; 306 307 void push_ld(int i); 308 void push_lh(int i); 309 void push_ln(int i); 310 }; 311 312 inline LViterator::LViterator(SGraph& sg, int n, bool s=true) : sgraph(sg), mgraph(sg.mgraph), strict(s) 313 { 314 if(sg[n].edge_contains_self) // TO DODAÆ PO PRZEJŠCIU NA EDGE_CONTAINS_SELF 315 { 316 push_ld(n); 317 push_ln(n); 318 } 319 320 for(vector<int>::iterator i=sg[n].edge.begin(); i!=sg[n].edge.end(); ++i) 321 { 322 if(*i != n) 323 { 324 push_ld(*i); 325 push_ln(*i); 326 } 327 328 } 329 // if(!strict) 330 // { 331 // push_ld(n); 332 // push_ln(n); 333 // } 334 } 335 336 inline int LViterator::next() 337 { 338 if(wayup.empty()) 339 { 340 if(waydown.empty()) 341 return -1; // 342 else 343 { 344 int k = waydown.top(); 345 waydown.pop(); 346 push_ld(k); 347 push_ln(k); 348 if(wayup.empty()) 349 return -1; // k NIE MA POPRZEDNIKÓW, NIE MO¯E TE¯ ZATEM MIEÆ LEWOSTRONNYCH PODRZÊDNIKÓW 350 else 351 { 352 int i = wayup.top(); 353 wayup.pop(); 354 push_lh(i); 355 return i; 356 } 357 } 358 359 } 360 else 361 { 362 int i = wayup.top(); 363 wayup.pop(); 364 push_lh(i); 365 return i; 366 }; 367 } 368 369 inline void LViterator::push_ld(int i) 370 { 371 vector<Arc>& arcs = sgraph[i].deps; 372 for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 373 if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) 374 push(waydown,a->dst); 375 } 376 377 inline void LViterator::push_lh(int i) 378 { 379 vector<Arc>& arcs = sgraph[i].heads; 380 for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 381 if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) 382 push(wayup,a->dst); 383 } 384 385 inline void LViterator::push_ln(int i) 386 { 387 vector<int>& mpredecessors = mgraph[sgraph[i].mnode].pred; 388 for(vector<int>::iterator mp = mpredecessors.begin(); mp != mpredecessors.end(); ++mp) // poprzedniki w mgraph 389 { 390 vector<int>& spredecessors = mgraph[*mp].snodes; 391 for(vector<int>::iterator sp = spredecessors.begin(); sp != spredecessors.end(); ++sp ) 392 if(sgraph[*sp].visible_as_neighbour || !strict) 393 push(wayup,*sp); 394 } 395 } 396 397 398 //---------------------------------------------------------------------------------------------------- 399 //---------------------------------------------------------------------------------------------------- 400 401 class LNiterator 402 { 403 public: 404 LNiterator(SGraph& sg, int n); 405 406 int next(); 407 408 private: 409 410 SGraph& sgraph; 411 MGraph& mgraph; 412 int thenode; 413 stack<int> wayup; 414 415 void push_ln(int i); 416 }; 417 418 inline LNiterator::LNiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), thenode(n) 419 { 420 push_ln(n); 421 } 422 423 inline int LNiterator::next() 424 { 425 if(wayup.empty()) 426 return -1; 427 else 428 { 429 int i = wayup.top(); 430 wayup.pop(); 431 return i; 432 }; 433 } 434 435 inline void LNiterator::push_ln(int i) 436 { 437 vector<int>& mpredecessors = mgraph[sgraph[i].mnode].pred; 438 for(vector<int>::iterator mp = mpredecessors.begin(); mp != mpredecessors.end(); ++mp) // poprzedniki w mgraph 439 { 440 vector<int>& spredecessors = mgraph[*mp].snodes; 441 for(vector<int>::iterator sp = spredecessors.begin(); sp != spredecessors.end(); ++sp ) 442 wayup.push(*sp); 443 } 444 } 445 446 447 //---------------------------------------------------------------------------------------------------- 448 //---------------------------------------------------------------------------------------------------- 449 450 class LHiterator 451 { 452 public: 453 LHiterator(SGraph& sg, int n); 454 455 int next(); 456 457 private: 458 459 SGraph& sgraph; 460 MGraph& mgraph; 461 stack<int> wayup; 462 463 void push_lh(int i); 464 }; 465 466 inline LHiterator::LHiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph) 467 { 468 push_lh(n); 469 } 470 471 inline int LHiterator::next() 472 { 473 if(wayup.empty()) 474 return -1; 475 else 476 { 477 int i = wayup.top(); 478 wayup.pop(); 479 push_lh(i); 480 return i; 481 }; 482 } 483 484 inline void LHiterator::push_lh(int i) 485 { 486 vector<Arc>& arcs = sgraph[i].heads; 487 for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 488 if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[i].mnode].pos) 489 wayup.push(a->dst); 490 } 491 492 //---------------------------------------------------------------------------------------------------- 493 //---------------------------------------------------------------------------------------------------- 494 495 class LDiterator 496 { 497 public: 498 LDiterator(SGraph& sg, int n); 499 500 int next(); 501 502 private: 503 504 SGraph& sgraph; 505 MGraph& mgraph; 506 int thenode; 507 stack<int> waydown; 508 509 void push_ld(int i); 510 }; 511 512 inline LDiterator::LDiterator(SGraph& sg, int n) : sgraph(sg), mgraph(sg.mgraph), thenode(n) 513 { 514 push_ld(n); 515 } 516 517 inline int LDiterator::next() 518 { 519 if(waydown.empty()) 520 return -1; 521 else 522 { 523 int k = waydown.top(); 524 waydown.pop(); 525 push_ld(k); 526 return k; 527 } 528 } 529 530 inline void LDiterator::push_ld(int i) 531 { 532 vector<Arc>& arcs = sgraph[i].deps; 533 for(vector<Arc>::iterator a = arcs.begin(); a != arcs.end(); ++a) 534 if(mgraph[sgraph[a->dst].mnode].pos < mgraph[sgraph[thenode].mnode].pos) 535 waydown.push(a->dst); 536 } 537 538 261 539 262 540 #endif
Note: See TracChangeset
for help on using the changeset viewer.