mirror of
https://github.com/explosion/spaCy.git
synced 2025-03-03 19:08:06 +03:00
Fix transition system to/from disk
This commit is contained in:
parent
b1469d3360
commit
097ab9c6e4
|
@ -157,22 +157,13 @@ cdef class TransitionSystem:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
def to_disk(self, path, **exclude):
|
def to_disk(self, path, **exclude):
|
||||||
actions = list(self.move_names)
|
with path.open('wb') as file_:
|
||||||
deserializers = {
|
file_.write(self.to_bytes(**exclude))
|
||||||
'actions': lambda p: ujson.dump(p.open('w'), actions),
|
|
||||||
'strings': lambda p: self.strings.to_disk(p)
|
|
||||||
}
|
|
||||||
util.to_disk(path, deserializers, exclude)
|
|
||||||
|
|
||||||
def from_disk(self, path, **exclude):
|
def from_disk(self, path, **exclude):
|
||||||
actions = []
|
with path.open('rb') as file_:
|
||||||
deserializers = {
|
byte_data = file_.read()
|
||||||
'strings': lambda p: self.strings.from_disk(p),
|
self.from_bytes(byte_data, **exclude)
|
||||||
'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)
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def to_bytes(self, **exclude):
|
def to_bytes(self, **exclude):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user