Datasets:
guilhermelmello
commited on
Commit
•
7ea460a
1
Parent(s):
2772f07
Fix streaming support.
Browse files- 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
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
|
|
|
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()
|