init
Browse files
kowiki.py
CHANGED
@@ -2,7 +2,7 @@ import datasets
|
|
2 |
import xml.etree.ElementTree as ET
|
3 |
import re
|
4 |
import requests
|
5 |
-
|
6 |
|
7 |
FILES = [
|
8 |
'kowiki-20230420-pages-articles.xml',
|
@@ -144,23 +144,22 @@ class KoWiki(datasets.GeneratorBasedBuilder):
|
|
144 |
|
145 |
def _generate_examples(self, data_file):
|
146 |
n = 0
|
147 |
-
output, text =
|
148 |
if data_file.startswith(("https://", "http://")):
|
149 |
data_file = requests.get(data_file, stream=True).raw
|
150 |
|
151 |
for event, node in ET.iterparse(data_file):
|
152 |
if node.tag.endswith("base"):
|
153 |
-
output["url"]
|
154 |
elif node.tag.endswith("title"):
|
155 |
-
output["title"]
|
156 |
elif node.tag.endswith("text"):
|
157 |
-
output["text"]
|
158 |
-
output["id"]
|
159 |
-
|
160 |
-
if len(output) == 4:
|
161 |
yield n, output
|
162 |
-
|
163 |
-
|
164 |
|
165 |
|
166 |
|
|
|
2 |
import xml.etree.ElementTree as ET
|
3 |
import re
|
4 |
import requests
|
5 |
+
from collections import defaultdict
|
6 |
|
7 |
FILES = [
|
8 |
'kowiki-20230420-pages-articles.xml',
|
|
|
144 |
|
145 |
def _generate_examples(self, data_file):
|
146 |
n = 0
|
147 |
+
output, text = defaultdict(list), ""
|
148 |
if data_file.startswith(("https://", "http://")):
|
149 |
data_file = requests.get(data_file, stream=True).raw
|
150 |
|
151 |
for event, node in ET.iterparse(data_file):
|
152 |
if node.tag.endswith("base"):
|
153 |
+
output["url"].append(node.text)
|
154 |
elif node.tag.endswith("title"):
|
155 |
+
output["title"].append(node.text)
|
156 |
elif node.tag.endswith("text"):
|
157 |
+
output["text"].append(process_text(text))
|
158 |
+
output["id"].append(f"{n:08d}")
|
159 |
+
if node.tag.endswith("sha1"):
|
|
|
160 |
yield n, output
|
161 |
+
|
162 |
+
|
163 |
|
164 |
|
165 |
|