From 097ab9c6e4a8258cb6141bfa24344d42ab674e9d Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Wed, 31 May 2017 13:44:00 +0200 Subject: [PATCH] Fix transition system to/from disk --- spacy/syntax/transition_system.pyx | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/spacy/syntax/transition_system.pyx b/spacy/syntax/transition_system.pyx index 42ec7318b..e33a29ac2 100644 --- a/spacy/syntax/transition_system.pyx +++ b/spacy/syntax/transition_system.pyx @@ -157,22 +157,13 @@ cdef class TransitionSystem: return 1 def to_disk(self, path, **exclude): - actions = list(self.move_names) - deserializers = { - 'actions': lambda p: ujson.dump(p.open('w'), actions), - 'strings': lambda p: self.strings.to_disk(p) - } - util.to_disk(path, deserializers, exclude) + with path.open('wb') as file_: + file_.write(self.to_bytes(**exclude)) def from_disk(self, path, **exclude): - actions = [] - deserializers = { - 'strings': lambda p: self.strings.from_disk(p), - 'actions': lambda p: actions.extend(ujson.load(p.open())) - } - util.from_disk(path, deserializers, exclude) - for move, label in actions: - self.add_action(move, label) + with path.open('rb') as file_: + byte_data = file_.read() + self.from_bytes(byte_data, **exclude) return self def to_bytes(self, **exclude):