[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 | |
---|
[519eaf5] | 32 | newnode.edge_contains_self = true ; |
---|
| 33 | |
---|
[e7de6cc] | 34 | return lastnodeind(); |
---|
[5f4d9c3] | 35 | } |
---|
| 36 | |
---|
[e7de6cc] | 37 | //==================================================================================================== |
---|
[5f4d9c3] | 38 | |
---|
| 39 | void SGraph::update_left(int headind, int depind) |
---|
| 40 | { |
---|
| 41 | SNode &head=nodes[headind], &dep=nodes[depind]; |
---|
| 42 | |
---|
[e7de6cc] | 43 | if(dep.saturated()) head.LV |= dep.LV, head.LD |= dep.LD; |
---|
[5f4d9c3] | 44 | } |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | void SGraph::update_right(int headind, int depind) |
---|
| 48 | { |
---|
| 49 | SNode &head=nodes[headind], &dep=nodes[depind]; |
---|
| 50 | |
---|
| 51 | dep.LH.set(headind); |
---|
[e7de6cc] | 52 | if(head.saturated()) dep.LH |= head.LH; |
---|
| 53 | } |
---|
[5f4d9c3] | 54 | |
---|
[e7de6cc] | 55 | //==================================================================================================== |
---|
[5f4d9c3] | 56 | |
---|
| 57 | int SGraph::clone(int ancind, NodeProp newprop) |
---|
| 58 | { |
---|
[e7de6cc] | 59 | SNode &newnode=makenewnode(); |
---|
[5f4d9c3] | 60 | SNode &ancnode = nodes[ancind]; |
---|
| 61 | |
---|
| 62 | newnode.prop=newprop; |
---|
| 63 | newnode.mnode=ancnode.mnode; |
---|
[e7de6cc] | 64 | mgraph[newnode.mnode].snodes.push_back(lastnodeind()); |
---|
| 65 | |
---|
| 66 | return lastnodeind(); |
---|
[5f4d9c3] | 67 | } |
---|
| 68 | |
---|
[e7de6cc] | 69 | //==================================================================================================== |
---|
[5f4d9c3] | 70 | |
---|
[e7de6cc] | 71 | int SGraph::print_node(FILE* f, int n, unsigned int info) |
---|
| 72 | { |
---|
| 73 | char buf[50000]; |
---|
| 74 | sprint_node(buf,n,-1,info); |
---|
| 75 | fputs(buf,f); |
---|
| 76 | } |
---|
[5f4d9c3] | 77 | |
---|
[e7de6cc] | 78 | //---------------------------------------------------------------------------------------------------- |
---|
[5f4d9c3] | 79 | |
---|
[e7de6cc] | 80 | int SGraph::print_node_debug(FILE* f, const char* pref, int n, int anc) |
---|
[5f4d9c3] | 81 | { |
---|
[e7de6cc] | 82 | char buf[50000]; |
---|
| 83 | sprint_node_debug(buf,pref,n,anc); |
---|
[5f4d9c3] | 84 | fputs(buf,f); |
---|
| 85 | } |
---|
| 86 | |
---|
[e7de6cc] | 87 | //---------------------------------------------------------------------------------------------------- |
---|
| 88 | |
---|
[519eaf5] | 89 | void SGraph::print_arc(FILE* f, const char* msg, int head, int dep, Role role, int dir) // 0 - left, 1 - right |
---|
[e7de6cc] | 90 | { |
---|
| 91 | if(dir==0) |
---|
[519eaf5] | 92 | fprintf(f,"%s %s:%d <-- %d\n", msg, role.str(), dep, head); |
---|
[e7de6cc] | 93 | else |
---|
[519eaf5] | 94 | fprintf(f,"%s %s:%d --> %d\n", msg, role.str(), head, dep); |
---|
[e7de6cc] | 95 | } |
---|
| 96 | |
---|
| 97 | //==================================================================================================== |
---|
| 98 | |
---|
| 99 | int SGraph::sprint_node(char* buf, int nodeind, int anc, unsigned int info) |
---|
[5f4d9c3] | 100 | { |
---|
| 101 | char* buf0=buf; |
---|
| 102 | |
---|
| 103 | SNode &node=nodes[nodeind]; |
---|
| 104 | |
---|
| 105 | buf+=sprintf(buf," dgp:%d",nodeind); |
---|
[e7de6cc] | 106 | if(anc>=0) buf+=sprintf(buf,"(%d)",anc); |
---|
[5f4d9c3] | 107 | buf+=sprintf(buf, saturated(nodeind) ? ";s" : ";u"); |
---|
| 108 | |
---|
[e7de6cc] | 109 | if (info&HEADS || info&DEPS) |
---|
| 110 | buf+=sprintf(buf,";"); |
---|
| 111 | |
---|
[5f4d9c3] | 112 | bool cont=false; |
---|
[e7de6cc] | 113 | |
---|
[5f4d9c3] | 114 | if (info&HEADS) |
---|
| 115 | for(vector<Arc>::iterator h=node.heads.begin(); h!=node.heads.end(); ++h) |
---|
| 116 | { |
---|
[b97a556] | 117 | buf+=sprintf(buf,"(++%s:%d)",h->role.str(),h->dst); |
---|
[5f4d9c3] | 118 | } |
---|
[e7de6cc] | 119 | |
---|
[5f4d9c3] | 120 | if (info&DEPS) |
---|
| 121 | for(vector<Arc>::iterator d=node.deps.begin(); d!=node.deps.end(); ++d) |
---|
| 122 | { |
---|
[b97a556] | 123 | buf+=sprintf(buf,"(--%s:%d)",d->role.str(),d->dst); |
---|
[5f4d9c3] | 124 | } |
---|
| 125 | |
---|
| 126 | if (info&SETS) |
---|
| 127 | { |
---|
| 128 | int ord=0; |
---|
| 129 | buf+=sprintf(buf,";{"); |
---|
[e7de6cc] | 130 | for(vector<int>::iterator pm=mgraph[node.mnode].pred.begin(); pm!=mgraph[node.mnode].pred.end(); ++pm) |
---|
| 131 | for(vector<int>::iterator ps=mgraph[*pm].snodes.begin(); ps!=mgraph[*pm].snodes.end(); ++ps) |
---|
[5f4d9c3] | 132 | buf+=sprintf(buf, ord++ ? ",%d" : "%d", *ps); |
---|
| 133 | buf+=sprintf(buf,"};{"); |
---|
[e7de6cc] | 134 | ord=0;for(int j=0; j<size(); ++j) if(node.LV[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); |
---|
[5f4d9c3] | 135 | buf+=sprintf(buf,"};{"); |
---|
[e7de6cc] | 136 | ord=0;for(int j=0; j<size(); ++j) if(node.LH[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); |
---|
[5f4d9c3] | 137 | buf+=sprintf(buf,"};{"); |
---|
[e7de6cc] | 138 | ord=0;for(int j=0; j<size(); ++j) if(node.LD[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); |
---|
[5f4d9c3] | 139 | buf+=sprintf(buf,"}"); |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | if (info&CONSTRAINTS)// buf+=sprint_node_constraints(buf,n); |
---|
| 143 | { |
---|
| 144 | buf+=sprintf(buf,";"); |
---|
| 145 | int cont=0; |
---|
| 146 | for(Role i=1; i<=Role::count(); ++i) |
---|
| 147 | if(node.prop.forbidden[i]) buf+=sprintf(buf,"%s!%s",(cont++)?",":"",i.str()); |
---|
| 148 | for(Role i=1; i<=Role::count(); ++i) |
---|
[a15e59b] | 149 | if(node.prop.required[i]) buf+=sprintf(buf,"%s-%s",(cont++)?",":"",i.str()); |
---|
[e7de6cc] | 150 | for(Role i=1; i<=Role::count(); ++i) |
---|
| 151 | if(node.prop.attached[i]) buf+=sprintf(buf,"%s+%s",(cont++)?",":"",i.str()); |
---|
| 152 | for(Flag i=1; i<=Flag::count(); ++i) |
---|
| 153 | if(node.prop.flags [i]) buf+=sprintf(buf,"%s<%s>",(cont++)?",":"",i.str()); |
---|
| 154 | if(node.prop.init_attached) |
---|
| 155 | buf+=sprintf(buf,"<init>"); |
---|
| 156 | if(node.prop.fin_attached) |
---|
| 157 | buf+=sprintf(buf,"<fin>"); |
---|
| 158 | |
---|
| 159 | stringstream oss; |
---|
| 160 | for(list<Boubble*>::iterator b = node.prop.boubbles.begin(); b != node.prop.boubbles.end(); b++) |
---|
| 161 | oss << (cont++ ? "," : "") << **b; |
---|
| 162 | buf+=sprintf(buf,oss.str().c_str()); |
---|
[5f4d9c3] | 163 | } |
---|
| 164 | |
---|
| 165 | // buf+=sprintf(buf,"\n"); |
---|
| 166 | |
---|
| 167 | return buf-buf0; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | |
---|
[e7de6cc] | 171 | int SGraph::sprint_node_debug(char* buf, const char* pref, int n, int anc) |
---|
[5f4d9c3] | 172 | { |
---|
| 173 | char *buf0 = buf; |
---|
[519eaf5] | 174 | buf+=sprintf(buf,"%-10s",pref); |
---|
| 175 | buf+=sprintf(buf,"%d.%s",n,form(n)); |
---|
| 176 | buf+=sprintf(buf,";"); |
---|
| 177 | buf+=sprintf(buf,"%s ",cat(n).str()); |
---|
| 178 | while(buf-buf0<40) buf+=sprintf(buf," "); |
---|
[e7de6cc] | 179 | buf+=sprint_node(buf,n,anc,HEADS|DEPS|SETS|CONSTRAINTS); |
---|
[3b02b04] | 180 | |
---|
[519eaf5] | 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); |
---|
[3b02b04] | 184 | |
---|
[5f4d9c3] | 185 | buf+=sprintf(buf,"\n"); |
---|
| 186 | return buf-buf0; |
---|
| 187 | } |
---|
| 188 | |
---|