Changes to transition systems for new StringStore scheme

This commit is contained in:
Matthew Honnibal 2016-09-30 19:58:51 +02:00
parent 22d4752d64
commit 0442e0ab1e
2 changed files with 5 additions and 5 deletions

View File

@ -76,7 +76,7 @@ cdef class BiluoPushDown(TransitionSystem):
elif move == 'MISSING': elif move == 'MISSING':
return 'M' return 'M'
else: else:
return MOVE_NAMES[move] + '-' + self.strings[label] return MOVE_NAMES[move] + '-' + self.strings.decode_int(label)
cdef int preprocess_gold(self, GoldParse gold) except -1: cdef int preprocess_gold(self, GoldParse gold) except -1:
for i in range(gold.length): for i in range(gold.length):
@ -101,7 +101,7 @@ cdef class BiluoPushDown(TransitionSystem):
label = 0 label = 0
elif '-' in name: elif '-' in name:
move_str, label_str = name.split('-', 1) move_str, label_str = name.split('-', 1)
label = self.strings[label_str] label = self.strings.intern(label_str)
else: else:
move_str = name move_str = name
label = 0 label = 0

View File

@ -27,7 +27,7 @@ cdef class TransitionSystem:
for label_str in sorted(label_strs): for label_str in sorted(label_strs):
self.add_action(int(action), label_str) self.add_action(int(action), label_str)
self.root_label = self.strings['ROOT'] self.root_label = self.strings.intern('ROOT')
self.freqs = {} if _freqs is None else _freqs self.freqs = {} if _freqs is None else _freqs
for attr in (TAG, HEAD, DEP, ENT_TYPE, ENT_IOB): for attr in (TAG, HEAD, DEP, ENT_TYPE, ENT_IOB):
self.freqs[attr] = defaultdict(int) self.freqs[attr] = defaultdict(int)
@ -41,7 +41,7 @@ cdef class TransitionSystem:
labels_by_action = {} labels_by_action = {}
cdef Transition t cdef Transition t
for trans in self.c[:self.n_moves]: for trans in self.c[:self.n_moves]:
label_str = self.strings[trans.label] label_str = self.strings.decode_int(trans.label)
labels_by_action.setdefault(trans.move, []).append(label_str) labels_by_action.setdefault(trans.move, []).append(label_str)
return (self.__class__, return (self.__class__,
(self.strings, labels_by_action, self.freqs), (self.strings, labels_by_action, self.freqs),
@ -86,7 +86,7 @@ cdef class TransitionSystem:
def add_action(self, int action, label): def add_action(self, int action, label):
if not isinstance(label, int): if not isinstance(label, int):
label = self.strings[label] label = self.strings.intern(label)
# Check we're not creating a move we already have, so that this is # Check we're not creating a move we already have, so that this is
# idempotent # idempotent
for trans in self.c[:self.n_moves]: for trans in self.c[:self.n_moves]: