From 854bece668ae247836fe18dce65f8ea7cf674700 Mon Sep 17 00:00:00 2001 From: Tomasz Obrebski Date: Mon, 12 Jan 2015 19:07:44 +0100 Subject: [PATCH] has_head prop added, visible_as_neighbour moved to prop --- src/dgp/dgp1.cc | 21 +++++++++++------ src/dgp/sgraph.cc | 1 + src/dgp/sgraph.hh | 60 +++++++++++++++++------------------------------ 3 files changed, 37 insertions(+), 45 deletions(-) diff --git a/src/dgp/dgp1.cc b/src/dgp/dgp1.cc index 5f184f8..d4068b1 100644 --- a/src/dgp/dgp1.cc +++ b/src/dgp/dgp1.cc @@ -172,7 +172,10 @@ void connect_left(int h, int d, const Link& l, list& 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); + { + 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& 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) - newd = create_new_node(d,new_dep_prop,new_dep_edge); + 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); } diff --git a/src/dgp/sgraph.cc b/src/dgp/sgraph.cc index 742e87d..f9de71c 100644 --- a/src/dgp/sgraph.cc +++ b/src/dgp/sgraph.cc @@ -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::iterator e = nodes[n].edge.others().begin(); e != nodes[n].edge.others().end(); e++ ) diff --git a/src/dgp/sgraph.hh b/src/dgp/sgraph.hh index ee3e362..58cdf64 100644 --- a/src/dgp/sgraph.hh +++ b/src/dgp/sgraph.hh @@ -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::const_iterator b,b1; for(b=boubbles.begin(), b1=p.boubbles.begin(); b != boubbles.end() && b1 != p.boubbles.end(); b++,b1++) @@ -105,12 +109,14 @@ void NodeProp::merge_boubbles(list new_boubbles) inline void NodeProp::copy(const NodeProp& p) { - required=p.required; - forbidden=p.forbidden; - attached=p.attached; - flags=p.flags; - init_attached=p.init_attached; - fin_attached=p.fin_attached; + required = p.required; + forbidden = p.forbidden; + attached = p.attached; + 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::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 LV; bitset LH; @@ -178,8 +183,9 @@ struct SNode vector heads; vector 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& spredecessors = mgraph[*mp].snodes; for(vector::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);