RJQ: use "with" on opened file
@@ -70,7 +70,7 @@ class CoNLL03Reader(PackReader):
return os.path.basename(collection)
def _parse_pack(self, collection: str) -> Iterator[DataPack]:
- doc = open(collection, "r", encoding="utf8")
+ with open(collection, "r", encoding="utf8") as doc:
pack_id: int = 0
pack: DataPack = DataPack()
@@ -101,7 +101,8 @@ class CoNLL03Reader(PackReader):
Sentence(pack, sentence_begin, offset - 1)
sentence_cnt += 1
- pack.set_text(text, replace_func=self.text_replace_operation)
+ pack.set_text(text,
+ replace_func=self.text_replace_operation)
Document(pack, 0, len(text))
pack.pack_name = collection + "_%d" % pack_id
pack_id += 1
@@ -197,4 +198,3 @@ class CoNLL03Reader(PackReader):
pack.pack_name = collection
yield pack
- doc.close()
