2014-11-10 05:28:56 +00:00
|
|
|
from .moves cimport BEGIN, UNIT
|
|
|
|
|
|
|
|
|
|
|
|
cdef int begin_entity(State* s, label) except -1:
|
2014-11-10 06:39:23 +00:00
|
|
|
s.curr.start = s.i
|
|
|
|
s.curr.label = label
|
2014-11-10 05:28:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
cdef int end_entity(State* s) except -1:
|
2014-11-10 06:39:23 +00:00
|
|
|
s.curr.end = s.i + 1
|
2014-11-10 11:14:36 +00:00
|
|
|
s.ents[s.j] = s.curr
|
|
|
|
s.j += 1
|
2014-11-10 06:39:23 +00:00
|
|
|
s.curr.start = 0
|
|
|
|
s.curr.label = -1
|
|
|
|
s.curr.end = 0
|
2014-11-10 05:28:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
cdef State* init_state(Pool mem, int sent_length) except NULL:
|
|
|
|
s = <State*>mem.alloc(1, sizeof(State))
|
2014-11-10 11:14:36 +00:00
|
|
|
s.j = 0
|
2014-11-10 05:28:56 +00:00
|
|
|
s.ents = <Entity*>mem.alloc(sent_length, sizeof(Entity))
|
|
|
|
for i in range(sent_length):
|
|
|
|
s.ents[i].label = -1
|
2014-11-10 06:39:23 +00:00
|
|
|
s.curr.label = -1
|
2014-11-10 05:28:56 +00:00
|
|
|
s.tags = <int*>mem.alloc(sent_length, sizeof(int))
|
|
|
|
s.length = sent_length
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
|
|
cdef bint entity_is_open(State *s) except -1:
|
2014-11-10 06:39:23 +00:00
|
|
|
return s.curr.label != -1
|
2014-11-10 05:28:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
cdef bint entity_is_sunk(State *s, Move* golds) except -1:
|
|
|
|
if not entity_is_open(s):
|
|
|
|
return False
|
|
|
|
|
2014-11-10 06:39:23 +00:00
|
|
|
cdef Move* gold = &golds[s.curr.start]
|
2014-11-10 05:28:56 +00:00
|
|
|
if gold.action != BEGIN and gold.action != UNIT:
|
|
|
|
return True
|
2014-11-10 06:39:23 +00:00
|
|
|
elif gold.label != s.curr.label:
|
2014-11-10 05:28:56 +00:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|