[5f4d9c3] | 1 | #include "global.hh" |
---|
| 2 | #include "sgraph.hh" |
---|
| 3 | #include "grammar.hh" |
---|
| 4 | #include "const.hh" |
---|
[e7de6cc] | 5 | #include <cstdio> |
---|
| 6 | #include <sstream> |
---|
[5f4d9c3] | 7 | |
---|
[e7de6cc] | 8 | extern MGraph mgraph; |
---|
[5f4d9c3] | 9 | |
---|
[e7de6cc] | 10 | //==================================================================================================== |
---|
[5f4d9c3] | 11 | |
---|
[e7de6cc] | 12 | int SGraph::add_base_snode(int mnodeind) |
---|
| 13 | { |
---|
| 14 | SNode& newnode = makenewnode(); |
---|
[5f4d9c3] | 15 | |
---|
[e7de6cc] | 16 | newnode.mnode=mnodeind; |
---|
[5f4d9c3] | 17 | |
---|
[e7de6cc] | 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) |
---|
[5f4d9c3] | 20 | if(nodes[*ps].in_LH) |
---|
| 21 | { |
---|
[e7de6cc] | 22 | newnode.LV.set(*ps); |
---|
| 23 | if(nodes[*ps].saturated()) newnode.LV |= nodes[*ps].LH; |
---|
[5f4d9c3] | 24 | } |
---|
| 25 | |
---|
[e7de6cc] | 26 | mgraph[newnode.mnode].snodes.push_back(lastnodeind()); |
---|
[5f4d9c3] | 27 | |
---|
[e7de6cc] | 28 | newnode.in_LH=true; |
---|
[5f4d9c3] | 29 | |
---|
[3b02b04] | 30 | newnode.edge.push_back(lastnodeind()); |
---|
| 31 | |
---|
[e7de6cc] | 32 | return lastnodeind(); |
---|
[5f4d9c3] | 33 | } |
---|
| 34 | |
---|
[e7de6cc] | 35 | //==================================================================================================== |
---|
[5f4d9c3] | 36 | |
---|
| 37 | void SGraph::update_left(int headind, int depind) |
---|
| 38 | { |
---|
| 39 | SNode &head=nodes[headind], &dep=nodes[depind]; |
---|
| 40 | |
---|
[e7de6cc] | 41 | if(dep.saturated()) head.LV |= dep.LV, head.LD |= dep.LD; |
---|
[5f4d9c3] | 42 | } |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | void SGraph::update_right(int headind, int depind) |
---|
| 46 | { |
---|
| 47 | SNode &head=nodes[headind], &dep=nodes[depind]; |
---|
| 48 | |
---|
| 49 | dep.LH.set(headind); |
---|
[e7de6cc] | 50 | if(head.saturated()) dep.LH |= head.LH; |
---|
| 51 | } |
---|
[5f4d9c3] | 52 | |
---|
[e7de6cc] | 53 | //==================================================================================================== |
---|
[5f4d9c3] | 54 | |
---|
| 55 | int SGraph::clone(int ancind, NodeProp newprop) |
---|
| 56 | { |
---|
[e7de6cc] | 57 | SNode &newnode=makenewnode(); |
---|
[5f4d9c3] | 58 | SNode &ancnode = nodes[ancind]; |
---|
| 59 | |
---|
| 60 | newnode.prop=newprop; |
---|
| 61 | newnode.mnode=ancnode.mnode; |
---|
[e7de6cc] | 62 | mgraph[newnode.mnode].snodes.push_back(lastnodeind()); |
---|
| 63 | |
---|
| 64 | return lastnodeind(); |
---|
[5f4d9c3] | 65 | } |
---|
| 66 | |
---|
[e7de6cc] | 67 | //==================================================================================================== |
---|
[5f4d9c3] | 68 | |
---|
[e7de6cc] | 69 | int SGraph::print_node(FILE* f, int n, unsigned int info) |
---|
| 70 | { |
---|
| 71 | char buf[50000]; |
---|
| 72 | sprint_node(buf,n,-1,info); |
---|
| 73 | fputs(buf,f); |
---|
| 74 | } |
---|
[5f4d9c3] | 75 | |
---|
[e7de6cc] | 76 | //---------------------------------------------------------------------------------------------------- |
---|
[5f4d9c3] | 77 | |
---|
[e7de6cc] | 78 | int SGraph::print_node_debug(FILE* f, const char* pref, int n, int anc) |
---|
[5f4d9c3] | 79 | { |
---|
[e7de6cc] | 80 | char buf[50000]; |
---|
| 81 | sprint_node_debug(buf,pref,n,anc); |
---|
[5f4d9c3] | 82 | fputs(buf,f); |
---|
| 83 | } |
---|
| 84 | |
---|
[e7de6cc] | 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) |
---|
[5f4d9c3] | 98 | { |
---|
| 99 | char* buf0=buf; |
---|
| 100 | |
---|
| 101 | SNode &node=nodes[nodeind]; |
---|
| 102 | |
---|
| 103 | buf+=sprintf(buf," dgp:%d",nodeind); |
---|
[e7de6cc] | 104 | if(anc>=0) buf+=sprintf(buf,"(%d)",anc); |
---|
[5f4d9c3] | 105 | buf+=sprintf(buf, saturated(nodeind) ? ";s" : ";u"); |
---|
| 106 | |
---|
[e7de6cc] | 107 | if (info&HEADS || info&DEPS) |
---|
| 108 | buf+=sprintf(buf,";"); |
---|
| 109 | |
---|
[5f4d9c3] | 110 | bool cont=false; |
---|
[e7de6cc] | 111 | |
---|
[5f4d9c3] | 112 | if (info&HEADS) |
---|
| 113 | for(vector<Arc>::iterator h=node.heads.begin(); h!=node.heads.end(); ++h) |
---|
| 114 | { |
---|
| 115 | if(cont) buf+=sprintf(buf,","); else cont=true; |
---|
[e7de6cc] | 116 | buf+=sprintf(buf,"++%s-%d(%d~%d)",h->role.str(),h->dst,h->headanc,h->depanc); |
---|
[5f4d9c3] | 117 | } |
---|
[e7de6cc] | 118 | |
---|
[5f4d9c3] | 119 | if (info&DEPS) |
---|
| 120 | for(vector<Arc>::iterator d=node.deps.begin(); d!=node.deps.end(); ++d) |
---|
| 121 | { |
---|
| 122 | // if(! nodes[d->dst].saturated()) continue; // NIE DRUKUJ NIENASYCONYCH PODRZEDNIKOW |
---|
| 123 | if(cont) buf+=sprintf(buf,","); else cont=true; |
---|
[e7de6cc] | 124 | buf+=sprintf(buf,"--%s-%d(%d~%d)",d->role.str(),d->dst,d->headanc,d->depanc); |
---|
[5f4d9c3] | 125 | } |
---|
| 126 | |
---|
| 127 | if (info&SETS) |
---|
| 128 | { |
---|
| 129 | int ord=0; |
---|
| 130 | buf+=sprintf(buf,";{"); |
---|
[e7de6cc] | 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) |
---|
[5f4d9c3] | 133 | buf+=sprintf(buf, ord++ ? ",%d" : "%d", *ps); |
---|
| 134 | buf+=sprintf(buf,"};{"); |
---|
[e7de6cc] | 135 | ord=0;for(int j=0; j<size(); ++j) if(node.LV[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); |
---|
[5f4d9c3] | 136 | buf+=sprintf(buf,"};{"); |
---|
[e7de6cc] | 137 | ord=0;for(int j=0; j<size(); ++j) if(node.LH[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); |
---|
[5f4d9c3] | 138 | buf+=sprintf(buf,"};{"); |
---|
[e7de6cc] | 139 | ord=0;for(int j=0; j<size(); ++j) if(node.LD[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); |
---|
[5f4d9c3] | 140 | buf+=sprintf(buf,"}"); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | if (info&CONSTRAINTS)// buf+=sprint_node_constraints(buf,n); |
---|
| 144 | { |
---|
| 145 | buf+=sprintf(buf,";"); |
---|
| 146 | int cont=0; |
---|
| 147 | for(Role i=1; i<=Role::count(); ++i) |
---|
| 148 | if(node.prop.forbidden[i]) buf+=sprintf(buf,"%s!%s",(cont++)?",":"",i.str()); |
---|
| 149 | for(Role i=1; i<=Role::count(); ++i) |
---|
[a15e59b] | 150 | if(node.prop.required[i]) buf+=sprintf(buf,"%s-%s",(cont++)?",":"",i.str()); |
---|
[e7de6cc] | 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()); |
---|
[5f4d9c3] | 164 | } |
---|
| 165 | |
---|
| 166 | // buf+=sprintf(buf,"\n"); |
---|
| 167 | |
---|
| 168 | return buf-buf0; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | |
---|
[e7de6cc] | 172 | int SGraph::sprint_node_debug(char* buf, const char* pref, int n, int anc) |
---|
[5f4d9c3] | 173 | { |
---|
| 174 | char *buf0 = buf; |
---|
| 175 | buf+=sprintf(buf,"#%s",pref); |
---|
[e7de6cc] | 176 | |
---|
| 177 | buf+=sprintf(buf,"%-16s",form(n)); |
---|
| 178 | |
---|
| 179 | buf+=sprint_node(buf,n,anc,HEADS|DEPS|SETS|CONSTRAINTS); |
---|
[3b02b04] | 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 | |
---|
[5f4d9c3] | 185 | buf+=sprintf(buf,"\n"); |
---|
| 186 | return buf-buf0; |
---|
| 187 | } |
---|
| 188 | |
---|