* Bug fix: when non-monotonically correct a dependency, make sure to delete the old one from the child list

This commit is contained in:
Matthew Honnibal 2015-04-29 21:32:18 +02:00
parent a4e2af54f9
commit 53cf77e1c8
1 changed files with 25 additions and 4 deletions

View File

@ -10,6 +10,8 @@ DEF NON_MONOTONIC = True
cdef int add_dep(State *s, int head, int child, int label) except -1: cdef int add_dep(State *s, int head, int child, int label) except -1:
if has_head(&s.sent[child]):
del_dep(s, child + s.sent[child].head, child)
cdef int dist = head - child cdef int dist = head - child
s.sent[child].head = dist s.sent[child].head = dist
s.sent[child].dep = label s.sent[child].dep = label
@ -17,14 +19,33 @@ cdef int add_dep(State *s, int head, int child, int label) except -1:
# offset i from it, set that bit (tracking left and right separately) # offset i from it, set that bit (tracking left and right separately)
if child > head: if child > head:
s.sent[head].r_kids |= 1 << (-dist) s.sent[head].r_kids |= 1 << (-dist)
s.sent[head].r_edge = s.sent[child].r_edge s.sent[head].r_edge = child - head
# Walk up the tree, setting right edge # Walk up the tree, setting right edge
while s.sent[head].head < 0: while s.sent[head].head != 0:
head += s.sent[head].head head += s.sent[head].head
s.sent[head].r_edge = s.sent[child].r_edge s.sent[head].r_edge = child - head
else: else:
s.sent[head].l_kids |= 1 << dist s.sent[head].l_kids |= 1 << dist
s.sent[head].l_edge = s.sent[child].l_edge s.sent[head].l_edge = (child + s.sent[child].l_edge) - head
cdef int del_dep(State *s, int head, int child) except -1:
cdef const TokenC* next_child
cdef int dist = head - child
if child > head:
s.sent[head].r_kids &= ~(1 << (-dist))
next_child = get_right(s, &s.sent[head], 1)
if next_child == NULL:
s.sent[head].r_edge = 0
else:
s.sent[head].r_edge = next_child.r_edge
else:
s.sent[head].l_kids &= ~(1 << dist)
next_child = get_left(s, &s.sent[head], 1)
if next_child == NULL:
s.sent[head].l_edge = 0
else:
s.sent[head].l_edge = next_child.l_edge
cdef int pop_stack(State *s) except -1: cdef int pop_stack(State *s) except -1: