#include "sgraph.hh" #include "grammar.hh" #include "const.hh" #include #include extern MGraph mgraph; //==================================================================================================== int SGraph::add_base_snode(int mnodeind) { SNode& newnode = makenewnode(); newnode.mnode=mnodeind; // for(vector::iterator pm=mgraph[newnode.mnode].pred.begin(); pm!=mgraph[newnode.mnode].pred.end(); ++pm) // for(vector::iterator ps=mgraph[*pm].snodes.begin(); ps!=mgraph[*pm].snodes.end(); ++ps) // if(nodes[*ps].in_LH) // { // newnode.LV.set(*ps); // if(nodes[*ps].saturated()) newnode.LV |= nodes[*ps].LH; // } mgraph[newnode.mnode].snodes.push_back(lastnodeind()); // newnode.in_LH=true; // newnode.edge.push_back(lastnodeind()); newnode.edge.insert_self(); return lastnodeind(); } //==================================================================================================== void SGraph::update_left(int headind, int depind) { SNode &head=nodes[headind], &dep=nodes[depind]; if(dep.saturated()) head.LV |= dep.LV, head.LD |= dep.LD; } void SGraph::update_right(int headind, int depind) { SNode &head=nodes[headind], &dep=nodes[depind]; dep.LH.set(headind); if(head.saturated()) dep.LH |= head.LH; } //==================================================================================================== int SGraph::clone(int ancind, NodeProp newprop, Edge edge) { SNode &newnode=makenewnode(); SNode &ancnode = nodes[ancind]; newnode.prop = newprop; newnode.edge = edge; newnode.mnode = ancnode.mnode; mgraph[newnode.mnode].snodes.push_back(lastnodeind()); return lastnodeind(); } //==================================================================================================== int SGraph::print_node(FILE* f, int n, unsigned int info) { char buf[50000]; sprint_node(buf,n,-1,info); fputs(buf,f); } //---------------------------------------------------------------------------------------------------- int SGraph::print_node_debug(FILE* f, const char* pref, int n, int anc) { char buf[50000]; sprint_node_debug(buf,pref,n,anc); fputs(buf,f); } //---------------------------------------------------------------------------------------------------- void SGraph::print_arc(FILE* f, const char* msg, int head, int dep, Role role, int dir) // 0 - left, 1 - right { if(dir==0) fprintf(f,"%s\t%d <-- %d\t%s\n", msg, dep, head, role.str()); else fprintf(f,"%s\t%d --> %d\t%s\n", msg, head, dep, role.str()); } //==================================================================================================== int SGraph::sprint_node(char* buf, int nodeind, int anc, unsigned int info) { char* buf0=buf; SNode &node=nodes[nodeind]; buf+=sprintf(buf," dgp:%d",nodeind); if(anc>=0) buf+=sprintf(buf,"(%d)",anc); buf+=sprintf(buf, saturated(nodeind) ? ";s" : ";u"); if (info&HEADS || info&DEPS) buf+=sprintf(buf,";"); bool cont=false; if (info&HEADS) for(vector::iterator h=node.heads.begin(); h!=node.heads.end(); ++h) { buf+=sprintf(buf,"(++%s:%d)",h->role.str(),h->dst); } if (info&DEPS) for(vector::iterator d=node.deps.begin(); d!=node.deps.end(); ++d) { buf+=sprintf(buf,"(--%s:%d)",d->role.str(),d->dst); } if (info&SETS) { int ord=0; buf+=sprintf(buf,";{"); for(vector::iterator pm=mgraph[node.mnode].pred.begin(); pm!=mgraph[node.mnode].pred.end(); ++pm) for(vector::iterator ps=mgraph[*pm].snodes.begin(); ps!=mgraph[*pm].snodes.end(); ++ps) buf+=sprintf(buf, ord++ ? ",%d" : "%d", *ps); buf+=sprintf(buf,"};{"); ord=0;for(int j=0; j",(cont++)?",":"",i.str()); if(node.prop.init_attached) buf+=sprintf(buf,""); if(node.prop.fin_attached) buf+=sprintf(buf,""); stringstream oss; for(list::iterator b = node.prop.boubbles.begin(); b != node.prop.boubbles.end(); b++) oss << (cont++ ? "," : "") << **b; buf+=sprintf(buf,oss.str().c_str()); } // buf+=sprintf(buf,"\n"); return buf-buf0; } int SGraph::sprint_node_debug(char* buf, const char* pref, int n, int anc) { char *buf0 = buf; buf+=sprintf(buf,"%-8s",pref); buf+=sprintf(buf,"%d.%s",n,form(n)); buf+=sprintf(buf,";"); buf+=sprintf(buf,"%s ",cat(n).str()); while(buf-buf0<40) buf+=sprintf(buf," "); buf+=sprint_node(buf,n,anc,HEADS|DEPS|CONSTRAINTS); buf+=sprintf(buf,"/"); buf+=sprintf(buf,nodes[n].prop.visible_as_neighbour ? "o" : "x"); if(nodes[n].edge.self()) buf += sprintf(buf,"* "); for(list::iterator e = nodes[n].edge.others().begin(); e != nodes[n].edge.others().end(); e++ ) buf += sprintf(buf,"%d ", *e); buf+=sprintf(buf,"\n"); return buf-buf0; }