source: src/dgp/sgraph.cc @ abd28d1

Last change on this file since abd28d1 was e7de6cc, checked in by Tomasz Obrebski <to@…>, 12 years ago

new version of dgp
added dgc, tre and compdic components
compiledic renamed to compdic_utf8
./configure updated

  • Property mode set to 100644
File size: 5.4 KB
RevLine 
[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]8extern MGraph mgraph;
[5f4d9c3]9
[e7de6cc]10//====================================================================================================
[5f4d9c3]11
[e7de6cc]12int 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
[e7de6cc]30  return lastnodeind();
[5f4d9c3]31}
32
[e7de6cc]33//====================================================================================================
[5f4d9c3]34
35void SGraph::update_left(int headind, int depind)
36{
37  SNode &head=nodes[headind], &dep=nodes[depind];
38
[e7de6cc]39  if(dep.saturated())  head.LV |= dep.LV,  head.LD |= dep.LD;
[5f4d9c3]40}
41
42
43void SGraph::update_right(int headind, int depind)
44{
45  SNode &head=nodes[headind], &dep=nodes[depind];
46
47  dep.LH.set(headind);
[e7de6cc]48  if(head.saturated())  dep.LH |= head.LH;
49} 
[5f4d9c3]50
[e7de6cc]51//====================================================================================================
[5f4d9c3]52
53int SGraph::clone(int ancind, NodeProp newprop)
54{
[e7de6cc]55  SNode &newnode=makenewnode();
[5f4d9c3]56  SNode &ancnode = nodes[ancind];
57
[e7de6cc]58
59
[5f4d9c3]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]69int 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]78int 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
87void 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
97int 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)
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]172int 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);
[5f4d9c3]180  buf+=sprintf(buf,"\n");
181  return buf-buf0;
182}
183
Note: See TracBrowser for help on using the repository browser.