Beispiel #1
0
 def save_as_compressed_file(self, data: Any) -> None:
     if self.path.endswith('.json.gz'):
         save_json_gz(data, self.path)
     elif self.path.endswith('.jsonl.gz'):
         save_jsonl_gz(data, self.path)
     elif self.path.endswith('.pkl.gz'):
         with gzip.GzipFile(self.path, 'wb') as outfile:
             pickle.dump(data, outfile)
     else:
         raise ValueError('File suffix must be .json.gz or .pkl.gz: %s' % self.path)
Beispiel #2
0
 def save_as_compressed_file(self, data: Any) -> None:
     if self.path.endswith('.json.gz'):
         save_json_gz(data, self.path)
     elif self.path.endswith('.jsonl.gz'):
         save_jsonl_gz(data, self.path)
     elif self.path.endswith('.pkl.gz'):
         with gzip.GzipFile(self.path, 'wb') as outfile:
             pickle.dump(data, outfile)
     elif self.path.endswith('.msgpack.gz'):
         with gzip.GzipFile(self.path, 'wb') as outfile:
             msgpack.dump(data, outfile)
     elif self.path.endswith('.msgpack.l.gz'):
         with gzip.GzipFile(self.path, "wb") as out_file:
             packer = msgpack.Packer(use_bin_type=True)
             for element in data:
                 out_file.write(packer.pack(element))
     else:
         raise ValueError(
             'File suffix must be `.json.gz`, `.pkl.gz`, `.msgpack.gz`, or `.msgpack.l.gz`. It was `%s`'
             % self.path)
Beispiel #3
0
 def save_as_json(self, filename: str) -> None:
     data = dict(types=self._elements,
                 outgoingEdges=[list(p) for p in self._parent_relations])
     save_json_gz(data, filename)