source: src/dgp/sgraph.cc

Last change on this file was 854bece, checked in by Tomasz Obrebski <obrebski@…>, 9 years ago

has_head prop added, visible_as_neighbour moved to prop

  • Property mode set to 100644
File size: 5.6 KB
RevLine 
[5f4d9c3]1#include "sgraph.hh"
2#include "grammar.hh"
3#include "const.hh"
[e7de6cc]4#include <cstdio>
5#include <sstream>
[5f4d9c3]6
[e7de6cc]7extern MGraph mgraph;
[5f4d9c3]8
[e7de6cc]9//====================================================================================================
[5f4d9c3]10
[e7de6cc]11int SGraph::add_base_snode(int mnodeind)
12{
13  SNode& newnode =  makenewnode(); 
[5f4d9c3]14
[e7de6cc]15  newnode.mnode=mnodeind;
[5f4d9c3]16
[acbabee]17  // for(vector<int>::iterator pm=mgraph[newnode.mnode].pred.begin(); pm!=mgraph[newnode.mnode].pred.end(); ++pm)
18  //   for(vector<int>::iterator ps=mgraph[*pm].snodes.begin(); ps!=mgraph[*pm].snodes.end(); ++ps)
19  //     if(nodes[*ps].in_LH)
20  //     {
21  //       newnode.LV.set(*ps);
22  //       if(nodes[*ps].saturated()) newnode.LV |= nodes[*ps].LH;
23  //     }
[5f4d9c3]24
[e7de6cc]25  mgraph[newnode.mnode].snodes.push_back(lastnodeind());
[5f4d9c3]26
[acbabee]27  // newnode.in_LH=true;
[5f4d9c3]28
[acbabee]29  // newnode.edge.push_back(lastnodeind());
[3b02b04]30
[acbabee]31  newnode.edge.insert_self();
[519eaf5]32
[e7de6cc]33  return lastnodeind();
[5f4d9c3]34}
35
[e7de6cc]36//====================================================================================================
[5f4d9c3]37
38void SGraph::update_left(int headind, int depind)
39{
40  SNode &head=nodes[headind], &dep=nodes[depind];
41
[e7de6cc]42  if(dep.saturated())  head.LV |= dep.LV,  head.LD |= dep.LD;
[5f4d9c3]43}
44
45
46void SGraph::update_right(int headind, int depind)
47{
48  SNode &head=nodes[headind], &dep=nodes[depind];
49
50  dep.LH.set(headind);
[e7de6cc]51  if(head.saturated())  dep.LH |= head.LH;
52} 
[5f4d9c3]53
[e7de6cc]54//====================================================================================================
[5f4d9c3]55
[acbabee]56int SGraph::clone(int ancind, NodeProp newprop, Edge edge)
[5f4d9c3]57{
[e7de6cc]58  SNode &newnode=makenewnode();
[5f4d9c3]59  SNode &ancnode = nodes[ancind];
60
[acbabee]61  newnode.prop = newprop;
62  newnode.edge = edge;
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]71int 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]80int 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]89void 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)
[acbabee]92    fprintf(f,"%s\t%d <-- %d\t%s\n", msg, dep, head, role.str());
[e7de6cc]93  else
[acbabee]94    fprintf(f,"%s\t%d --> %d\t%s\n", msg, head, dep, role.str());
[e7de6cc]95}
96
97//====================================================================================================
98
99int 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]171int SGraph::sprint_node_debug(char* buf, const char* pref, int n, int anc)
[5f4d9c3]172{
173  char *buf0 = buf;
[acbabee]174  buf+=sprintf(buf,"%-8s",pref);
[519eaf5]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," ");
[acbabee]179  buf+=sprint_node(buf,n,anc,HEADS|DEPS|CONSTRAINTS);
[3b02b04]180 
[d484a32]181  buf+=sprintf(buf,"/");
[854bece]182  buf+=sprintf(buf,nodes[n].prop.visible_as_neighbour ? "o" : "x");
[acbabee]183  if(nodes[n].edge.self())
184    buf += sprintf(buf,"* ");
185  for(list<int>::iterator e = nodes[n].edge.others().begin(); e != nodes[n].edge.others().end(); e++ )
[d484a32]186    buf += sprintf(buf,"%d ", *e);
[3b02b04]187
[5f4d9c3]188  buf+=sprintf(buf,"\n");
189  return buf-buf0;
190}
191
Note: See TracBrowser for help on using the repository browser.