Changeset e7de6cc for src/dgp/sgraph.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/sgraph.cc
r5f4d9c3 re7de6cc 1 1 #include "global.hh" 2 2 #include "sgraph.hh" 3 #include "mgraph.hh"4 3 #include "grammar.hh" 5 4 #include "const.hh" 6 #include <stdio.h> 5 #include <cstdio> 6 #include <sstream> 7 7 8 extern MGraph mgraph; 8 9 9 int SGraph::add_base_snode(MNode* mn) 10 //==================================================================================================== 11 12 int SGraph::add_base_snode(int mnodeind) 10 13 { 11 int nodeind=n; 12 SNode &node=nodes[n]; 14 SNode& newnode = makenewnode(); 13 15 14 n ode.clear();16 newnode.mnode=mnodeind; 15 17 16 node.mnode=mn; 17 18 for(vector<MNode*>::iterator pm=node.mnode->pred.begin(); pm!=node.mnode->pred.end(); ++pm) 19 for(vector<int>::iterator ps=(*pm)->snodes.begin(); ps!=(*pm)->snodes.end(); ++ps) 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 20 if(nodes[*ps].in_LH) 21 21 { 22 n ode.LV.set(*ps);23 if(nodes[*ps].saturated()) n ode.LV |= nodes[*ps].LH;22 newnode.LV.set(*ps); 23 if(nodes[*ps].saturated()) newnode.LV |= nodes[*ps].LH; 24 24 } 25 25 26 mn->snodes.push_back(nodeind); 27 ++n; 26 mgraph[newnode.mnode].snodes.push_back(lastnodeind()); 28 27 29 n ode.in_LH=true;28 newnode.in_LH=true; 30 29 31 return nodeind;30 return lastnodeind(); 32 31 } 33 32 33 //==================================================================================================== 34 34 35 35 void SGraph::update_left(int headind, int depind) … … 37 37 SNode &head=nodes[headind], &dep=nodes[depind]; 38 38 39 if(dep.saturated()) head.LV |= dep.LV,head.LD |= dep.LD;39 if(dep.saturated()) head.LV |= dep.LV, head.LD |= dep.LD; 40 40 } 41 41 … … 46 46 47 47 dep.LH.set(headind); 48 if(head.saturated()) 49 dep.LH |= head.LH; 50 } 48 if(head.saturated()) dep.LH |= head.LH; 49 } 51 50 51 //==================================================================================================== 52 52 53 53 int SGraph::clone(int ancind, NodeProp newprop) 54 54 { 55 int newind = n++; 56 SNode &newnode=nodes[newind]; 55 SNode &newnode=makenewnode(); 57 56 SNode &ancnode = nodes[ancind]; 58 57 59 newnode.clear(); 58 59 60 60 newnode.prop=newprop; 61 61 newnode.mnode=ancnode.mnode; 62 newnode.mnode->snodes.push_back(newind); 63 return newind; 62 mgraph[newnode.mnode].snodes.push_back(lastnodeind()); 63 64 return lastnodeind(); 64 65 } 65 66 66 67 //------------------------------------------------------------------------- 68 //------------------------------------------------------------------------- 69 67 //==================================================================================================== 70 68 71 69 int SGraph::print_node(FILE* f, int n, unsigned int info) 72 70 { 73 char buf[ 1000];74 sprint_node(buf,n, info);71 char buf[50000]; 72 sprint_node(buf,n,-1,info); 75 73 fputs(buf,f); 76 74 } 77 75 78 int SGraph::sprint_node(char* buf, int nodeind, unsigned int info) 76 //---------------------------------------------------------------------------------------------------- 77 78 int SGraph::print_node_debug(FILE* f, const char* pref, int n, int anc) 79 { 80 char buf[50000]; 81 sprint_node_debug(buf,pref,n,anc); 82 fputs(buf,f); 83 } 84 85 //---------------------------------------------------------------------------------------------------- 86 87 void SGraph::print_arc(FILE* f, int head, int dep, Role role, int dir) // 0 - left, 1 - right 88 { 89 if(dir==0) 90 fprintf(f,"#A %s:%d <-- %d\n", role.str(), dep, head); 91 else 92 fprintf(f,"#A %s:%d --> %d\n", role.str(), head, dep); 93 } 94 95 //==================================================================================================== 96 97 int SGraph::sprint_node(char* buf, int nodeind, int anc, unsigned int info) 79 98 { 80 99 char* buf0=buf; 81 char descr[256];82 char nodeinfo[16];83 100 84 101 SNode &node=nodes[nodeind]; 85 102 86 103 buf+=sprintf(buf," dgp:%d",nodeind); 104 if(anc>=0) buf+=sprintf(buf,"(%d)",anc); 87 105 buf+=sprintf(buf, saturated(nodeind) ? ";s" : ";u"); 88 106 107 if (info&HEADS || info&DEPS) 108 buf+=sprintf(buf,";"); 109 89 110 bool cont=false; 111 90 112 if (info&HEADS) 91 {92 buf+=sprintf(buf,";");93 113 for(vector<Arc>::iterator h=node.heads.begin(); h!=node.heads.end(); ++h) 94 114 { 95 115 if(cont) buf+=sprintf(buf,","); else cont=true; 96 buf+=sprintf(buf,"++%s-%d /%d",h->role.str(),h->dst,h->anc);116 buf+=sprintf(buf,"++%s-%d(%d~%d)",h->role.str(),h->dst,h->headanc,h->depanc); 97 117 } 98 } 99 118 100 119 if (info&DEPS) 101 {102 buf+=sprintf(buf,";");103 120 for(vector<Arc>::iterator d=node.deps.begin(); d!=node.deps.end(); ++d) 104 121 { 105 122 // if(! nodes[d->dst].saturated()) continue; // NIE DRUKUJ NIENASYCONYCH PODRZEDNIKOW 106 123 if(cont) buf+=sprintf(buf,","); else cont=true; 107 buf+=sprintf(buf,"--%s-%d /%d",d->role.str(),d->dst,d->anc);124 buf+=sprintf(buf,"--%s-%d(%d~%d)",d->role.str(),d->dst,d->headanc,d->depanc); 108 125 } 109 }110 126 111 127 if (info&SETS) … … 113 129 int ord=0; 114 130 buf+=sprintf(buf,";{"); 115 for(vector< MNode*>::iterator pm=node.mnode->pred.begin(); pm!=node.mnode->pred.end(); ++pm)116 for(vector<int>::iterator ps= (*pm)->snodes.begin(); ps!=(*pm)->snodes.end(); ++ps)131 for(vector<int>::iterator pm=mgraph[node.mnode].pred.begin(); pm!=mgraph[node.mnode].pred.end(); ++pm) 132 for(vector<int>::iterator ps=mgraph[*pm].snodes.begin(); ps!=mgraph[*pm].snodes.end(); ++ps) 117 133 buf+=sprintf(buf, ord++ ? ",%d" : "%d", *ps); 118 134 buf+=sprintf(buf,"};{"); 119 ord=0;for(int j=0; j< =n; ++j) if(node.LV[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j);135 ord=0;for(int j=0; j<size(); ++j) if(node.LV[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); 120 136 buf+=sprintf(buf,"};{"); 121 ord=0;for(int j=0; j< =n; ++j) if(node.LH[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j);137 ord=0;for(int j=0; j<size(); ++j) if(node.LH[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); 122 138 buf+=sprintf(buf,"};{"); 123 ord=0;for(int j=0; j< =n; ++j) if(node.LD[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j);139 ord=0;for(int j=0; j<size(); ++j) if(node.LD[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); 124 140 buf+=sprintf(buf,"}"); 125 141 } … … 133 149 for(Role i=1; i<=Role::count(); ++i) 134 150 if(node.prop.required[i]) buf+=sprintf(buf,"%s&%s",(cont++)?",":"",i.str()); 151 for(Role i=1; i<=Role::count(); ++i) 152 if(node.prop.attached[i]) buf+=sprintf(buf,"%s+%s",(cont++)?",":"",i.str()); 153 for(Flag i=1; i<=Flag::count(); ++i) 154 if(node.prop.flags [i]) buf+=sprintf(buf,"%s<%s>",(cont++)?",":"",i.str()); 155 if(node.prop.init_attached) 156 buf+=sprintf(buf,"<init>"); 157 if(node.prop.fin_attached) 158 buf+=sprintf(buf,"<fin>"); 159 160 stringstream oss; 161 for(list<Boubble*>::iterator b = node.prop.boubbles.begin(); b != node.prop.boubbles.end(); b++) 162 oss << (cont++ ? "," : "") << **b; 163 buf+=sprintf(buf,oss.str().c_str()); 135 164 } 136 165 … … 141 170 142 171 143 int SGraph::sprint_node_debug(char* buf, const char* pref, int n )172 int SGraph::sprint_node_debug(char* buf, const char* pref, int n, int anc) 144 173 { 145 174 char *buf0 = buf; 146 175 buf+=sprintf(buf,"#%s",pref); 147 buf+=sprint_node(buf,n,HEADS|DEPS|SETS|CONSTRAINTS); 176 177 buf+=sprintf(buf,"%-16s",form(n)); 178 179 buf+=sprint_node(buf,n,anc,HEADS|DEPS|SETS|CONSTRAINTS); 148 180 buf+=sprintf(buf,"\n"); 149 181 return buf-buf0; 150 182 } 151 183 152 int SGraph::print_node_debug(FILE* f, const char* pref, int n)153 {154 char buf[1000];155 sprint_node_debug(buf,pref,n);156 fputs(buf,f);157 }158 159 void SGraph::print_arc(FILE* f, int left, int right, Role role, int dir) // 0 - left, 1 - right160 {161 fprintf(f,"# %s:%s.%02d %s %s.%02d\n",162 role.str(),nodes[left].mnode->type,left,163 dir ? "-->" : "<--",164 nodes[right].mnode->type,right);165 }
Note: See TracChangeset
for help on using the changeset viewer.