has_head prop added, visible_as_neighbour moved to prop

This commit is contained in:
Tomasz Obrebski 2015-01-12 19:07:44 +01:00
parent acbabee742
commit 854bece668
3 changed files with 37 additions and 45 deletions

View File

@ -172,7 +172,10 @@ void connect_left(int h, int d, const Link& l, list<Boubble*>& new_head_boubbles
Edge new_dep_edge(sgraph[d].edge);
int newd = find_existing_node(sgraph[d].mnode, new_dep_prop, new_dep_edge);
if( newd < 0 )
{
newd = create_new_node(d,new_dep_prop,new_dep_edge);
sgraph[newd].prop.has_head = true;
}
Edge new_head_edge(sgraph[newd].edge,newd);
int newh = find_existing_node(sgraph[h].mnode, new_head_prop, new_head_edge);
@ -200,17 +203,21 @@ void connect_right(int h, int d, const Link& l, list<Boubble*>& new_head_boubble
NodeProp new_dep_prop = compute_dep_prop(old_dep_prop,l,new_dep_boubbles);
Edge new_head_edge(sgraph[h].edge);
int newh = find_existing_node(sgraph[h].mnode, new_head_prop, new_head_edge);
int newh = -1;
if(!new_head_prop.forbidden[l.role]) newh = find_existing_node(sgraph[h].mnode, new_head_prop, new_head_edge);
if( newh < 0 )
{
newh = create_new_node(h,new_head_prop,new_head_edge);
sgraph[newh].visible_as_neighbour = false;
sgraph[newh].prop.visible_as_neighbour = false;
}
Edge new_dep_edge;
int newd = find_existing_node(sgraph[d].mnode, new_dep_prop, new_dep_edge);
if( newd < 0)
int newd = d;
if( ! (new_dep_edge == sgraph[d].edge) || ! (old_dep_prop == new_dep_prop) )
{
newd = create_new_node(d,new_dep_prop,new_dep_edge);
sgraph[newd].prop.has_head = true;
}
sgraph[newd].heads.push_back(Arc(newh,l.role,h,d));
@ -298,7 +305,7 @@ void try_connect_dependents(int j)
LViterator lvi(sgraph,j);
int i;
while((i=lvi.next()) >= 0)
if(sgraph.saturated(i))
if(sgraph.saturated(i) && ! sgraph.has_head(i))
{
if(debug) {fprintf(stderr,"\t%d <-- %d",i,j); }

View File

@ -179,6 +179,7 @@ int SGraph::sprint_node_debug(char* buf, const char* pref, int n, int anc)
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<int>::iterator e = nodes[n].edge.others().begin(); e != nodes[n].edge.others().end(); e++ )

View File

@ -54,6 +54,8 @@ struct NodeProp
bool init_attached;
bool fin_attached;
bool visible_as_neighbour;
bool has_head;
FlagSet flags;
@ -71,6 +73,8 @@ bool NodeProp::operator==(const NodeProp& p)
if(flags != p.flags) return false;
if(init_attached != p.init_attached) return false;
if(fin_attached != p.fin_attached) return false;
if(visible_as_neighbour != p.visible_as_neighbour) return false;
if(has_head != p.has_head) return false;
list<Boubble*>::const_iterator b,b1;
for(b=boubbles.begin(), b1=p.boubbles.begin(); b != boubbles.end() && b1 != p.boubbles.end(); b++,b1++)
@ -111,6 +115,8 @@ void NodeProp::copy(const NodeProp& p)
flags = p.flags;
init_attached = p.init_attached;
fin_attached = p.fin_attached;
visible_as_neighbour = p.visible_as_neighbour;
has_head = p.has_head;
for(list<Boubble*>::const_iterator b = p.boubbles.begin(); b!=p.boubbles.end(); b++)
boubbles.push_back(new Boubble(**b));
}
@ -126,6 +132,8 @@ inline void NodeProp::clear()
attached.reset();
init_attached=false;
fin_attached=false;
visible_as_neighbour=true;
has_head=false;
clear_boubbles();
}
@ -160,15 +168,12 @@ private:
struct SNode
{
SNode() { visible_as_neighbour = true; }
SNode() { prop.clear(); }
int mnode;
NodeProp prop;
Edge edge;
bool visible_as_neighbour;
bitset<MAXNODES> LV;
bitset<MAXNODES> LH;
@ -178,8 +183,9 @@ struct SNode
vector<Arc> heads;
vector<Arc> deps;
void clear();
bool saturated();
void clear() { prop.clear(), LV.reset(), LD.reset(), LH.reset(), heads.clear(), deps.clear(); }
bool saturated() { return prop.required.none(); }
// void edge_clear() { edge.clear(); edge_contains_self=false;}
// void edge_set(int i) { edge.clear(); edge_contains_self=false; edge.push_back(i); }
@ -190,15 +196,6 @@ struct SNode
// void edge_add_self(bool b=true) { edge_contains_self=b; }
};
//----------------------------------------------------------------------------------------------------
inline
void SNode::clear()
{ prop.clear(), LV.reset(), LD.reset(), LH.reset(), heads.clear(), deps.clear(); }
//----------------------------------------------------------------------------------------------------
inline
bool SNode::saturated()
{ return prop.required.none(); }
//====================================================================================================
// SGraph CLASS
//====================================================================================================
@ -218,8 +215,9 @@ public:
int clone(int ancind, NodeProp newprop, Edge edge);
void update_left(int headind, int depind);
void update_right(int headind, int depind);
bool visible(int left, int right);
bool saturated(int node);
bool visible(int left, int right) { return nodes[right].LV[left]; }
bool saturated(int node) { return nodes[node].saturated(); }
bool has_head(int node) { return nodes[node].prop.has_head; }
Cat cat(int i) const { return mgraph[nodes[i].mnode].cat; }
char* form(int i) const { return mgraph[nodes[i].mnode].form; }
@ -251,20 +249,6 @@ private:
int sprint_node_debug(char* buf, const char* pref, int n, int anc);
};
//----------------------------------------------------------------------------------------------------
inline bool SGraph::visible(int left, int right)
{
return nodes[right].LV[left];
}
//----------------------------------------------------------------------------------------------------
inline bool SGraph::saturated(int node)
{
return nodes[node].saturated();
}
//----------------------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
@ -412,7 +396,7 @@ inline void LViterator::push_ln(int i)
{
vector<int>& spredecessors = mgraph[*mp].snodes;
for(vector<int>::iterator sp = spredecessors.begin(); sp != spredecessors.end(); ++sp )
if(sgraph[*sp].visible_as_neighbour || !strict)
if(sgraph[*sp].prop.visible_as_neighbour || !strict)
{
push(wayup,*sp);
if(debug) fprintf(stderr,"\t\tLViterator(%d)\tPUSH_LN wayup %d\n",snode, *sp);