Changeset e7de6cc for src/dgp/dgp0.cc
- Timestamp:
- 02/21/12 20:02:51 (13 years ago)
- Branches:
- master
- Children:
- b242df2
- Parents:
- 354ba3d
- git-author:
- Tomasz Obrebski <to@…> (02/21/12 20:02:51)
- git-committer:
- Tomasz Obrebski <to@…> (02/21/12 20:02:51)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/dgp/dgp0.cc
r5f4d9c3 re7de6cc 6 6 extern SGraph sgraph; 7 7 8 SNode* snodes;9 10 8 extern bool debug; 11 9 … … 16 14 void set_initial_constraints(int node) 17 15 { 18 s nodes[node].prop.forbidden.reset();19 s nodes[node].prop.required=grammar.obl[snodes[node].mnode->cat];16 sgraph[node].prop.forbidden.reset(); 17 sgraph[node].prop.required=grammar.is_obl(mgraph[sgraph[node].mnode].cat); 20 18 } 21 19 … … 23 21 bool changing_constraints(int head, Role role) 24 22 { 25 return grammar. sgl[role] || snodes[head].prop.required[role];23 return grammar.is_sgl(role) || sgraph[head].prop.required[role]; 26 24 } 27 25 28 26 void apply_constraints(int head, Role role) 29 27 { 30 if(grammar. sgl[role]) snodes[head].prop.forbidden.set(role);31 s nodes[head].prop.required.reset(role);28 if(grammar.is_sgl(role)) sgraph[head].prop.forbidden.set(role); 29 sgraph[head].prop.required.reset(role); 32 30 } 33 31 … … 35 33 { 36 34 NodeProp ret=headprop; 37 if(grammar. sgl[role]) ret.forbidden.set(role);35 if(grammar.is_sgl(role)) ret.forbidden.set(role); 38 36 ret.required.reset(role); 39 37 return ret; … … 44 42 NodeProp ret=headprop; 45 43 46 if(grammar. sgl[role]) ret.forbidden.set(role);44 if(grammar.is_sgl(role)) ret.forbidden.set(role); 47 45 ret.required.reset(role); 48 46 return ret; … … 52 50 { 53 51 for(vector<int>::iterator ps=mnode.snodes.begin(); ps!=mnode.snodes.end(); ++ps) 54 if(s nodes[*ps].prop==p && snodes[*ps].LH==newheadLH && snodes[*ps].LV==newheadLV)52 if(sgraph[*ps].prop==p && sgraph[*ps].LH==newheadLH && sgraph[*ps].LV==newheadLV) 55 53 return *ps; 56 54 return -1; … … 59 57 void connect_left(list<int>::iterator h, list<int>::iterator d, Role r) 60 58 { 61 NodeProp &oldheadprop = snodes[*h].prop; 62 NodeProp newheadprop; 63 bitset<MAXNODES> newheadLV; 64 bitset<MAXNODES> newheadLH; 65 bitset<MAXNODES> newheadLD; 66 67 newheadprop=compute_prop_left(oldheadprop,r); 59 NodeProp &oldheadprop = sgraph[*h].prop; 60 NodeProp newheadprop = compute_prop_left(oldheadprop,r); 68 61 69 62 int newheadind; … … 72 65 else 73 66 { 74 newheadLH = snodes[*h].LH;75 newheadLV = snodes[*d].LV;76 newheadLD = snodes[*h].LD;77 78 newheadind = get_node( *(snodes[*h].mnode), newheadprop, newheadLH, newheadLV);67 bitset<MAXNODES> newheadLH = sgraph[*h].LH; 68 bitset<MAXNODES> newheadLV = sgraph[*d].LV; 69 bitset<MAXNODES> newheadLD = sgraph[*h].LD; 70 71 newheadind = get_node(mgraph[sgraph[*h].mnode], newheadprop, newheadLH, newheadLV); 79 72 if( newheadind < 0 ) 80 73 { … … 82 75 list<int>::iterator nextit=h; ++nextit; 83 76 nodelist.insert(nextit,newheadind); 84 s nodes[newheadind].LH=newheadLH;85 s nodes[newheadind].in_LH=true;86 s nodes[newheadind].LV.reset();87 s nodes[newheadind].LD = newheadLD;77 sgraph[newheadind].LH=newheadLH; 78 sgraph[newheadind].LD = newheadLD; 79 sgraph[newheadind].in_LH=true; 80 sgraph[newheadind].LV.reset(); 88 81 89 82 if(debug) sgraph.print_node_debug(stderr," C ",newheadind); 90 83 } 91 84 else 92 s nodes[newheadind].LD |= newheadLD; // TYLKO DLA LD85 sgraph[newheadind].LD |= newheadLD; // TYLKO DLA LD 93 86 } 94 87 95 snodes[newheadind].deps.push_back(Arc(*d,r,*h)); 96 97 if(snodes[*d].saturated()) snodes[newheadind].LV |= snodes[*d].LV; 98 snodes[newheadind].LD.set(*d); 99 if(snodes[*d].saturated()) snodes[newheadind].LD |= snodes[*d].LD; 100 101 if(debug) 102 sgraph.print_arc(stderr,*d,newheadind,r,0), sgraph.print_node_debug(stderr," U ",newheadind); 103 } 104 88 sgraph[newheadind].deps.push_back(Arc(*d,r,*h)); 89 90 if(sgraph[*d].saturated()) sgraph[newheadind].LV |= sgraph[*d].LV; 91 92 sgraph[newheadind].LD.set(*d); 93 if(sgraph[*d].saturated()) sgraph[newheadind].LD |= sgraph[*d].LD; 94 95 if(debug) sgraph.print_arc(stderr,*d,newheadind,r,0), sgraph.print_node_debug(stderr," U ",newheadind); 96 } 105 97 106 98 void connect_right(list<int>::iterator h, list<int>::iterator d, Role r) 107 99 { 108 NodeProp &oldheadprop = snodes[*h].prop; 109 NodeProp newheadprop; 110 bitset<MAXNODES> newheadLV; 111 bitset<MAXNODES> newheadLH; 112 bitset<MAXNODES> newheadLD; 100 NodeProp &oldheadprop = sgraph[*h].prop; 101 NodeProp newheadprop = compute_prop_right(oldheadprop,r); 113 102 int newheadind; 114 103 115 newheadprop = compute_prop_right(oldheadprop,r);116 104 if(oldheadprop==newheadprop) 117 105 newheadind = *h; 118 106 else 119 107 { 120 newheadLH = snodes[*h].LH;121 newheadLV = snodes[*h].LV;122 newheadLD = snodes[*h].LD;123 124 newheadind = get_node( *(snodes[*h].mnode), newheadprop, newheadLH, newheadLV);108 bitset<MAXNODES> newheadLH = sgraph[*h].LH; 109 bitset<MAXNODES> newheadLV = sgraph[*h].LV; 110 bitset<MAXNODES> newheadLD = sgraph[*h].LD; 111 112 newheadind = get_node(mgraph[sgraph[*h].mnode], newheadprop, newheadLH, newheadLV); 125 113 if( newheadind < 0 ) 126 114 { 127 115 newheadind = sgraph.clone(*h,newheadprop); 128 snodes[newheadind].LH=newheadLH;129 snodes[newheadind].in_LH=false;130 snodes[newheadind].LV=newheadLV;131 snodes[newheadind].LD=newheadLD;132 116 list<int>::iterator nextit=h; ++nextit; 133 117 nodelist.insert(nextit,newheadind); 118 sgraph[newheadind].LH=newheadLH; 119 sgraph[newheadind].LD=newheadLD; 120 sgraph[newheadind].in_LH=false; 121 sgraph[newheadind].LV=newheadLV; 134 122 135 123 if(debug) sgraph.print_node_debug(stderr," C ",newheadind); 136 124 } 137 125 else 138 s nodes[newheadind].LD |= newheadLD; // TYLKO DLA LD126 sgraph[newheadind].LD |= newheadLD; // TYLKO DLA LD 139 127 } 140 128 141 snodes[*d].heads.push_back(Arc(newheadind,r,*h)); 142 143 snodes[*d].LH.set(newheadind); 144 145 if(snodes[newheadind].saturated()) snodes[*d].LH |= snodes[newheadind].LH; 146 147 if(debug) 148 sgraph.print_arc(stderr,newheadind,*d,r,1), sgraph.print_node_debug(stderr," U ",*d); 129 sgraph[*d].heads.push_back(Arc(newheadind,r,*h)); 130 131 sgraph[*d].LH.set(newheadind); 132 133 if(sgraph[newheadind].saturated()) sgraph[*d].LH |= sgraph[newheadind].LH; 134 135 if(debug) sgraph.print_arc(stderr,newheadind,*d,r,1), sgraph.print_node_debug(stderr," U ",*d); 149 136 150 137 } … … 156 143 if(sgraph.visible(*i,*j) && sgraph.saturated(*i)) 157 144 { 158 Roles& ji_roles = grammar.connect [snodes[*j].mnode->cat][snodes[*i].mnode->cat];145 Roles& ji_roles = grammar.connectable( mgraph[sgraph[*j].mnode].cat, mgraph[sgraph[*i].mnode].cat ); 159 146 for(RolesIter r=ji_roles.begin(); r!=ji_roles.end();++r) 160 if(grammar.check_constr(s nodes[*j].prop,snodes[*i].prop,0,*r))147 if(grammar.check_constr(sgraph[*j].prop,sgraph[*i].prop,0,*r)) 161 148 connect_left(j,i,*r); 162 149 } … … 169 156 if(sgraph.visible(*i,*j)) 170 157 { 171 Roles& ij_roles = grammar.connect [snodes[*i].mnode->cat][snodes[*j].mnode->cat];158 Roles& ij_roles = grammar.connectable( mgraph[sgraph[*i].mnode].cat, mgraph[sgraph[*j].mnode].cat ); 172 159 for(RolesIter r=ij_roles.begin(); r!=ij_roles.end();++r) 173 if(grammar.check_constr(s nodes[*i].prop,snodes[*j].prop,1,*r))160 if(grammar.check_constr(sgraph[*i].prop,sgraph[*j].prop,1,*r)) 174 161 connect_right(i,j,*r); 175 162 } … … 182 169 for(++i; i!=nodelist.end(); ++i) 183 170 { 184 for(vector<Arc>::iterator da=sgraph .nodes[*i].deps.begin()--; da!=sgraph.nodes[*i].deps.end(); ++da)185 sgraph .nodes[da->dst].heads.push_back(Arc(*i,da->role,da->anc));186 for(vector<Arc>::iterator ha=sgraph .nodes[*i].heads.begin(); ha!=sgraph.nodes[*i].heads.end(); ++ha)187 sgraph .nodes[ha->dst].deps.push_back(Arc(*i,ha->role,ha->anc));171 for(vector<Arc>::iterator da=sgraph[*i].deps.begin()--; da!=sgraph[*i].deps.end(); ++da) 172 sgraph[da->dst].heads.push_back(Arc(*i,da->role,da->anc)); 173 for(vector<Arc>::iterator ha=sgraph[*i].heads.begin(); ha!=sgraph[*i].heads.end(); ++ha) 174 sgraph[ha->dst].deps.push_back(Arc(*i,ha->role,ha->anc)); 188 175 } 189 176 } … … 192 179 void dgp0() 193 180 { 194 snodes=sgraph.nodes;195 181 196 182 nodelist.clear(); … … 198 184 processed=nodelist.begin(); 199 185 200 for(int m=0; m<mgraph. n; ++m)186 for(int m=0; m<mgraph.size() ; ++m) 201 187 { 202 int basenode = sgraph.add_base_snode(mgraph.nodes+m); // ma zwracaæ SNode* 188 int basenode = sgraph.add_base_snode(m); // ma zwracaæ SNode* 189 203 190 set_initial_constraints(basenode); 204 191 nodelist.push_back(basenode); … … 213 200 processed=cursor; 214 201 } 202 215 203 } 216 204 reverse_links();
Note: See TracChangeset
for help on using the changeset viewer.