def save(self, folder):
"""Save object and return corresponding files."""
if not os.path.exists(folder):
os.makedirs(folder)
files = []
# annoy objects can't be pickled, so save these separately
for k, v in self._annoy_objects.items():
annoy_filepath = os.path.join(folder, '{}.ann'.format(k))
v._ann_obj.save(annoy_filepath)
files.append(annoy_filepath)
pickle_filepath = os.path.join(folder, 'object.pickle')
with open(pickle_filepath, 'wb') as handle:
dill.dump(self, handle)
files.append(pickle_filepath)
# write entity types
enttypes = self.get_entity_types()
info_file = os.path.join(folder, 'entity_info.json')
with open(info_file, 'w') as handle:
json.dump(enttypes, handle)
files.append(info_file)
return files
评论列表
文章目录