1 | #include "global.hh" |
---|
2 | #include "sgraph.hh" |
---|
3 | #include "mgraph.hh" |
---|
4 | #include "grammar.hh" |
---|
5 | #include "const.hh" |
---|
6 | #include <stdio.h> |
---|
7 | |
---|
8 | |
---|
9 | int SGraph::add_base_snode(MNode* mn) |
---|
10 | { |
---|
11 | int nodeind=n; |
---|
12 | SNode &node=nodes[n]; |
---|
13 | |
---|
14 | node.clear(); |
---|
15 | |
---|
16 | node.mnode=mn; |
---|
17 | |
---|
18 | for(vector<MNode*>::iterator pm=node.mnode->pred.begin(); pm!=node.mnode->pred.end(); ++pm) |
---|
19 | for(vector<int>::iterator ps=(*pm)->snodes.begin(); ps!=(*pm)->snodes.end(); ++ps) |
---|
20 | if(nodes[*ps].in_LH) |
---|
21 | { |
---|
22 | node.LV.set(*ps); |
---|
23 | if(nodes[*ps].saturated()) node.LV |= nodes[*ps].LH; |
---|
24 | } |
---|
25 | |
---|
26 | mn->snodes.push_back(nodeind); |
---|
27 | ++n; |
---|
28 | |
---|
29 | node.in_LH=true; |
---|
30 | |
---|
31 | return nodeind; |
---|
32 | } |
---|
33 | |
---|
34 | |
---|
35 | void SGraph::update_left(int headind, int depind) |
---|
36 | { |
---|
37 | SNode &head=nodes[headind], &dep=nodes[depind]; |
---|
38 | |
---|
39 | if(dep.saturated()) head.LV |= dep.LV, head.LD |= dep.LD; |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | void SGraph::update_right(int headind, int depind) |
---|
44 | { |
---|
45 | SNode &head=nodes[headind], &dep=nodes[depind]; |
---|
46 | |
---|
47 | dep.LH.set(headind); |
---|
48 | if(head.saturated()) |
---|
49 | dep.LH |= head.LH; |
---|
50 | } |
---|
51 | |
---|
52 | |
---|
53 | int SGraph::clone(int ancind, NodeProp newprop) |
---|
54 | { |
---|
55 | int newind = n++; |
---|
56 | SNode &newnode=nodes[newind]; |
---|
57 | SNode &ancnode = nodes[ancind]; |
---|
58 | |
---|
59 | newnode.clear(); |
---|
60 | newnode.prop=newprop; |
---|
61 | newnode.mnode=ancnode.mnode; |
---|
62 | newnode.mnode->snodes.push_back(newind); |
---|
63 | return newind; |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | //------------------------------------------------------------------------- |
---|
68 | //------------------------------------------------------------------------- |
---|
69 | |
---|
70 | |
---|
71 | int SGraph::print_node(FILE* f, int n, unsigned int info) |
---|
72 | { |
---|
73 | char buf[1000]; |
---|
74 | sprint_node(buf,n,info); |
---|
75 | fputs(buf,f); |
---|
76 | } |
---|
77 | |
---|
78 | int SGraph::sprint_node(char* buf, int nodeind, unsigned int info) |
---|
79 | { |
---|
80 | char* buf0=buf; |
---|
81 | char descr[256]; |
---|
82 | char nodeinfo[16]; |
---|
83 | |
---|
84 | SNode &node=nodes[nodeind]; |
---|
85 | |
---|
86 | buf+=sprintf(buf," dgp:%d",nodeind); |
---|
87 | buf+=sprintf(buf, saturated(nodeind) ? ";s" : ";u"); |
---|
88 | |
---|
89 | bool cont=false; |
---|
90 | if (info&HEADS) |
---|
91 | { |
---|
92 | buf+=sprintf(buf,";"); |
---|
93 | for(vector<Arc>::iterator h=node.heads.begin(); h!=node.heads.end(); ++h) |
---|
94 | { |
---|
95 | if(cont) buf+=sprintf(buf,","); else cont=true; |
---|
96 | buf+=sprintf(buf,"++%s-%d/%d",h->role.str(),h->dst,h->anc); |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | if (info&DEPS) |
---|
101 | { |
---|
102 | buf+=sprintf(buf,";"); |
---|
103 | for(vector<Arc>::iterator d=node.deps.begin(); d!=node.deps.end(); ++d) |
---|
104 | { |
---|
105 | // if(! nodes[d->dst].saturated()) continue; // NIE DRUKUJ NIENASYCONYCH PODRZEDNIKOW |
---|
106 | if(cont) buf+=sprintf(buf,","); else cont=true; |
---|
107 | buf+=sprintf(buf,"--%s-%d/%d",d->role.str(),d->dst,d->anc); |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | if (info&SETS) |
---|
112 | { |
---|
113 | int ord=0; |
---|
114 | buf+=sprintf(buf,";{"); |
---|
115 | for(vector<MNode*>::iterator pm=node.mnode->pred.begin(); pm!=node.mnode->pred.end(); ++pm) |
---|
116 | for(vector<int>::iterator ps=(*pm)->snodes.begin(); ps!=(*pm)->snodes.end(); ++ps) |
---|
117 | buf+=sprintf(buf, ord++ ? ",%d" : "%d", *ps); |
---|
118 | buf+=sprintf(buf,"};{"); |
---|
119 | ord=0;for(int j=0; j<=n; ++j) if(node.LV[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); |
---|
120 | buf+=sprintf(buf,"};{"); |
---|
121 | ord=0;for(int j=0; j<=n; ++j) if(node.LH[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); |
---|
122 | buf+=sprintf(buf,"};{"); |
---|
123 | ord=0;for(int j=0; j<=n; ++j) if(node.LD[j]) buf+=sprintf(buf, ord++ ? ",%d" : "%d", j); |
---|
124 | buf+=sprintf(buf,"}"); |
---|
125 | } |
---|
126 | |
---|
127 | if (info&CONSTRAINTS)// buf+=sprint_node_constraints(buf,n); |
---|
128 | { |
---|
129 | buf+=sprintf(buf,";"); |
---|
130 | for(Role i=1; i<=Role::count(); ++i) |
---|
131 | if(node.prop.forbidden[i]) buf+=sprintf(buf,"!%s",i.str()); |
---|
132 | for(Role i=1; i<=Role::count(); ++i) |
---|
133 | if(node.prop.required[i]) buf+=sprintf(buf,"&%s",i.str()); |
---|
134 | } |
---|
135 | |
---|
136 | // buf+=sprintf(buf,"\n"); |
---|
137 | |
---|
138 | return buf-buf0; |
---|
139 | } |
---|
140 | |
---|
141 | |
---|
142 | int SGraph::sprint_node_debug(char* buf, char* pref, int n) |
---|
143 | { |
---|
144 | char *buf0 = buf; |
---|
145 | buf+=sprintf(buf,"#%s",pref); |
---|
146 | buf+=sprint_node(buf,n,HEADS|DEPS|SETS|CONSTRAINTS); |
---|
147 | buf+=sprintf(buf,"\n"); |
---|
148 | return buf-buf0; |
---|
149 | } |
---|
150 | |
---|
151 | int SGraph::print_node_debug(FILE* f, char* pref, int n) |
---|
152 | { |
---|
153 | char buf[1000]; |
---|
154 | sprint_node_debug(buf,pref,n); |
---|
155 | fputs(buf,f); |
---|
156 | } |
---|
157 | |
---|
158 | void SGraph::print_arc(FILE* f, int left, int right, Role role, int dir) // 0 - left, 1 - right |
---|
159 | { |
---|
160 | fprintf(f,"# %s:%s.%02d %s %s.%02d\n", |
---|
161 | role.str(),nodes[left].mnode->type,left, |
---|
162 | dir ? "-->" : "<--", |
---|
163 | nodes[right].mnode->type,right); |
---|
164 | } |
---|