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); Edge new_dep_edge(sgraph[d].edge);
int newd = find_existing_node(sgraph[d].mnode, new_dep_prop, new_dep_edge); int newd = find_existing_node(sgraph[d].mnode, new_dep_prop, new_dep_edge);
if( newd < 0 ) if( newd < 0 )
{
newd = create_new_node(d,new_dep_prop,new_dep_edge); 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); Edge new_head_edge(sgraph[newd].edge,newd);
int newh = find_existing_node(sgraph[h].mnode, new_head_prop, new_head_edge); 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); NodeProp new_dep_prop = compute_dep_prop(old_dep_prop,l,new_dep_boubbles);
Edge new_head_edge(sgraph[h].edge); 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 ) if( newh < 0 )
{ {
newh = create_new_node(h,new_head_prop,new_head_edge); 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; Edge new_dep_edge;
int newd = find_existing_node(sgraph[d].mnode, new_dep_prop, new_dep_edge); int newd = d;
if( newd < 0) if( ! (new_dep_edge == sgraph[d].edge) || ! (old_dep_prop == new_dep_prop) )
{
newd = create_new_node(d,new_dep_prop,new_dep_edge); 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)); 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); LViterator lvi(sgraph,j);
int i; int i;
while((i=lvi.next()) >= 0) 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); } 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+=sprint_node(buf,n,anc,HEADS|DEPS|CONSTRAINTS);
buf+=sprintf(buf,"/"); buf+=sprintf(buf,"/");
buf+=sprintf(buf,nodes[n].prop.visible_as_neighbour ? "o" : "x");
if(nodes[n].edge.self()) if(nodes[n].edge.self())
buf += sprintf(buf,"* "); buf += sprintf(buf,"* ");
for(list<int>::iterator e = nodes[n].edge.others().begin(); e != nodes[n].edge.others().end(); e++ ) 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 init_attached;
bool fin_attached; bool fin_attached;
bool visible_as_neighbour;
bool has_head;
FlagSet flags; FlagSet flags;
@ -71,6 +73,8 @@ bool NodeProp::operator==(const NodeProp& p)
if(flags != p.flags) return false; if(flags != p.flags) return false;
if(init_attached != p.init_attached) return false; if(init_attached != p.init_attached) return false;
if(fin_attached != p.fin_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; list<Boubble*>::const_iterator b,b1;
for(b=boubbles.begin(), b1=p.boubbles.begin(); b != boubbles.end() && b1 != p.boubbles.end(); 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; flags = p.flags;
init_attached = p.init_attached; init_attached = p.init_attached;
fin_attached = p.fin_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++) for(list<Boubble*>::const_iterator b = p.boubbles.begin(); b!=p.boubbles.end(); b++)
boubbles.push_back(new Boubble(**b)); boubbles.push_back(new Boubble(**b));
} }
@ -126,6 +132,8 @@ inline void NodeProp::clear()
attached.reset(); attached.reset();
init_attached=false; init_attached=false;
fin_attached=false; fin_attached=false;
visible_as_neighbour=true;
has_head=false;
clear_boubbles(); clear_boubbles();
} }
@ -160,15 +168,12 @@ private:
struct SNode struct SNode
{ {
SNode() { prop.clear(); }
SNode() { visible_as_neighbour = true; }
int mnode; int mnode;
NodeProp prop; NodeProp prop;
Edge edge; Edge edge;
bool visible_as_neighbour;
bitset<MAXNODES> LV; bitset<MAXNODES> LV;
bitset<MAXNODES> LH; bitset<MAXNODES> LH;
@ -178,8 +183,9 @@ struct SNode
vector<Arc> heads; vector<Arc> heads;
vector<Arc> deps; vector<Arc> deps;
void clear(); void clear() { prop.clear(), LV.reset(), LD.reset(), LH.reset(), heads.clear(), deps.clear(); }
bool saturated(); bool saturated() { return prop.required.none(); }
// void edge_clear() { edge.clear(); edge_contains_self=false;} // void edge_clear() { edge.clear(); edge_contains_self=false;}
// void edge_set(int i) { edge.clear(); edge_contains_self=false; edge.push_back(i); } // 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; } // 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 // SGraph CLASS
//==================================================================================================== //====================================================================================================
@ -218,8 +215,9 @@ public:
int clone(int ancind, NodeProp newprop, Edge edge); int clone(int ancind, NodeProp newprop, Edge edge);
void update_left(int headind, int depind); void update_left(int headind, int depind);
void update_right(int headind, int depind); void update_right(int headind, int depind);
bool visible(int left, int right); bool visible(int left, int right) { return nodes[right].LV[left]; }
bool saturated(int node); 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; } Cat cat(int i) const { return mgraph[nodes[i].mnode].cat; }
char* form(int i) const { return mgraph[nodes[i].mnode].form; } 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); 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; vector<int>& spredecessors = mgraph[*mp].snodes;
for(vector<int>::iterator sp = spredecessors.begin(); sp != spredecessors.end(); ++sp ) 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); push(wayup,*sp);
if(debug) fprintf(stderr,"\t\tLViterator(%d)\tPUSH_LN wayup %d\n",snode, *sp); if(debug) fprintf(stderr,"\t\tLViterator(%d)\tPUSH_LN wayup %d\n",snode, *sp);