source: src/dgp/sgraph.cc @ d484a32

Last change on this file since d484a32 was d484a32, checked in by Tomasz Obrebski <obrebski@…>, 10 years ago

some unnecessary variables/functions deleted

  • Property mode set to 100644
File size: 5.5 KB
Line 
1#include "global.hh"
2#include "sgraph.hh"
3#include "grammar.hh"
4#include "const.hh"
5#include <cstdio>
6#include <sstream>
7
8extern MGraph mgraph;
9
10//====================================================================================================
11
12int SGraph::add_base_snode(int mnodeind)
13{
14  SNode& newnode =  makenewnode(); 
15
16  newnode.mnode=mnodeind;
17
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      if(nodes[*ps].in_LH)
21      {
22        newnode.LV.set(*ps);
23        if(nodes[*ps].saturated()) newnode.LV |= nodes[*ps].LH;
24      }
25
26  mgraph[newnode.mnode].snodes.push_back(lastnodeind());
27
28  newnode.in_LH=true;
29
30  newnode.edge.push_back(lastnodeind());
31
32  newnode.edge_contains_self = true ;
33
34  return lastnodeind();
35}
36
37//====================================================================================================
38
39void SGraph::update_left(int headind, int depind)
40{
41  SNode &head=nodes[headind], &dep=nodes[depind];
42
43  if(dep.saturated())  head.LV |= dep.LV,  head.LD |= dep.LD;
44}
45
46
47void SGraph::update_right(int headind, int depind)
48{
49  SNode &head=nodes[headind], &dep=nodes[depind];
50
51  dep.LH.set(headind);
52  if(head.saturated())  dep.LH |= head.LH;
53} 
54
55//====================================================================================================
56
57int SGraph::clone(int ancind, NodeProp newprop)
58{
59  SNode &newnode=makenewnode();
60  SNode &ancnode = nodes[ancind];
61
62  newnode.prop=newprop;
63  newnode.mnode=ancnode.mnode;
64  mgraph[newnode.mnode].snodes.push_back(lastnodeind());
65
66  return lastnodeind();
67}
68
69//====================================================================================================
70
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}
77
78//----------------------------------------------------------------------------------------------------
79
80int SGraph::print_node_debug(FILE* f, const char* pref, int n, int anc)
81{
82  char buf[50000];
83  sprint_node_debug(buf,pref,n,anc);
84  fputs(buf,f);
85}
86
87//----------------------------------------------------------------------------------------------------
88
89void SGraph::print_arc(FILE* f, const char* msg, int head, int dep, Role role, int dir) // 0 - left, 1 - right
90{
91  if(dir==0)
92    fprintf(f,"%s  %s:%d <-- %d\n", msg, role.str(), dep, head);
93  else
94    fprintf(f,"%s  %s:%d --> %d\n", msg, role.str(), head, dep);
95}
96
97//====================================================================================================
98
99int SGraph::sprint_node(char* buf, int nodeind, int anc, unsigned int info)
100{
101  char* buf0=buf;
102
103  SNode &node=nodes[nodeind];
104
105  buf+=sprintf(buf," dgp:%d",nodeind);
106  if(anc>=0) buf+=sprintf(buf,"(%d)",anc);
107  buf+=sprintf(buf, saturated(nodeind) ? ";s" : ";u");
108
109  if (info&HEADS || info&DEPS)
110    buf+=sprintf(buf,";");
111
112  bool cont=false;
113
114  if (info&HEADS)
115    for(vector<Arc>::iterator h=node.heads.begin(); h!=node.heads.end(); ++h)
116    {
117      buf+=sprintf(buf,"(++%s:%d)",h->role.str(),h->dst);
118    }
119
120  if (info&DEPS)
121    for(vector<Arc>::iterator d=node.deps.begin(); d!=node.deps.end(); ++d)
122    {
123      buf+=sprintf(buf,"(--%s:%d)",d->role.str(),d->dst);
124    }
125 
126  if (info&SETS)
127  {
128    int ord=0;
129    buf+=sprintf(buf,";{");
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)
132        buf+=sprintf(buf, ord++ ? ",%d" : "%d", *ps);
133    buf+=sprintf(buf,"};{");
134    ord=0;for(int j=0; j<size(); ++j) if(node.LV[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j);
135    buf+=sprintf(buf,"};{");
136    ord=0;for(int j=0; j<size(); ++j) if(node.LH[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j);
137    buf+=sprintf(buf,"};{");
138    ord=0;for(int j=0; j<size(); ++j) if(node.LD[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j);
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)
149      if(node.prop.required[i]) buf+=sprintf(buf,"%s-%s",(cont++)?",":"",i.str());
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());
163  }
164 
165//   buf+=sprintf(buf,"\n");
166 
167  return buf-buf0;
168}
169
170
171int SGraph::sprint_node_debug(char* buf, const char* pref, int n, int anc)
172{
173  char *buf0 = buf;
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," ");
179  buf+=sprint_node(buf,n,anc,HEADS|DEPS|SETS|CONSTRAINTS);
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
185  buf+=sprintf(buf,"\n");
186  return buf-buf0;
187}
188
Note: See TracBrowser for help on using the repository browser.