guilhermelmello commited on
Commit
7ea460a
1 Parent(s): 2772f07

Fix streaming support.

Browse files
Files changed (1) hide show
  1. corpus-carolina.py +23 -19
corpus-carolina.py CHANGED
@@ -21,6 +21,9 @@ import datasets
21
  import gzip
22
 
23
 
 
 
 
24
  _HOMEPAGE = "https://sites.usp.br/corpuscarolina/"
25
 
26
 
@@ -188,22 +191,23 @@ class Carolina(datasets.GeneratorBasedBuilder):
188
  )
189
 
190
  _key = 0
191
- for path in filepaths:
192
- gzip_file = gzip.GzipFile(path, "rb")
193
- for _, tei in etree.iterparse(gzip_file, **parser_params):
194
- header = tei.find(f"{TEI_NS}teiHeader")
195
-
196
- meta = etree.tostring(
197
- header, encoding="utf-8").decode("utf-8")
198
- text = ' '.join([e.text
199
- for e in tei.findall(f".//{TEI_NS}body/{TEI_NS}p")
200
- if e.text is not None
201
- ])
202
-
203
- yield _key, {
204
- "meta": meta,
205
- "text": text
206
- }
207
- _key += 1
208
-
209
- gzip_file.close()
 
 
21
  import gzip
22
 
23
 
24
+ logger = datasets.logging.get_logger(__name__)
25
+
26
+
27
  _HOMEPAGE = "https://sites.usp.br/corpuscarolina/"
28
 
29
 
 
191
  )
192
 
193
  _key = 0
194
+ for doc_path in filepaths:
195
+ logger.info("generating examples from = %s", doc_path)
196
+ with gzip.open(open(doc_path, "rb"), "rb") as gzip_file:
197
+ for _, tei in etree.iterparse(gzip_file, **parser_params):
198
+ header = tei.find(f"{TEI_NS}teiHeader")
199
+
200
+ meta = etree.tostring(
201
+ header, encoding="utf-8").decode("utf-8")
202
+ text = ' '.join([e.text
203
+ for e in tei.findall(f".//{TEI_NS}body/{TEI_NS}p")
204
+ if e.text is not None
205
+ ])
206
+
207
+ yield _key, {
208
+ "meta": meta,
209
+ "text": text
210
+ }
211
+ _key += 1
212
+
213
+ gzip_file.close()