v1.0.0 streaming bug fix
Browse files- RuREBus.py +4 -53
- utils.py +0 -17
RuREBus.py
CHANGED
|
@@ -3,17 +3,7 @@ import json
|
|
| 3 |
import requests
|
| 4 |
from urllib.parse import urlencode
|
| 5 |
from pathlib import Path
|
| 6 |
-
import zipfile
|
| 7 |
import os
|
| 8 |
-
import shutil
|
| 9 |
-
|
| 10 |
-
from .utils import is_notebook
|
| 11 |
-
|
| 12 |
-
if is_notebook:
|
| 13 |
-
from tqdm.notebook import tqdm
|
| 14 |
-
else:
|
| 15 |
-
from tqdm import tqdm
|
| 16 |
-
|
| 17 |
|
| 18 |
_NAME = 'RuREBus'
|
| 19 |
_CITATION = '''
|
|
@@ -30,37 +20,6 @@ _HOMEPAGE = 'https://github.com/dialogue-evaluation/RuREBus'
|
|
| 30 |
_VERSION = '1.0.0'
|
| 31 |
|
| 32 |
|
| 33 |
-
# def decode_file_names(folder):
|
| 34 |
-
# for root, dirs, files in os.walk(folder, topdown=False):
|
| 35 |
-
# root = Path(root)
|
| 36 |
-
# for file in files:
|
| 37 |
-
# old_name = root / Path(file)
|
| 38 |
-
# new_name = root / Path(
|
| 39 |
-
# file.encode('cp437').decode('cp866'))
|
| 40 |
-
# old_name.rename(new_name)
|
| 41 |
-
# for dir in dirs:
|
| 42 |
-
# old_name = root / Path(dir)
|
| 43 |
-
# new_name = root / Path(dir.encode('cp437').decode('cp866'))
|
| 44 |
-
# old_name.rename(new_name)
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
def extract(zip_file_path):
|
| 48 |
-
p = Path(zip_file_path)
|
| 49 |
-
if not p.exists():
|
| 50 |
-
raise FileNotFoundError
|
| 51 |
-
dest_dir = str(p.parent / 'extracted' / p.stem)
|
| 52 |
-
os.makedirs(dest_dir, exist_ok=True)
|
| 53 |
-
with zipfile.ZipFile(zip_file_path) as archive:
|
| 54 |
-
for file_info in tqdm(archive.infolist(), desc='Extracting'):
|
| 55 |
-
filename = file_info.filename.encode('cp437').decode('cp866')
|
| 56 |
-
target = os.path.join(dest_dir, *filename.split('/'))
|
| 57 |
-
os.makedirs(os.path.dirname(target), exist_ok=True)
|
| 58 |
-
if not file_info.is_dir():
|
| 59 |
-
with archive.open(file_info) as source, open(target, 'wb') as dest:
|
| 60 |
-
shutil.copyfileobj(source, dest)
|
| 61 |
-
return dest_dir
|
| 62 |
-
|
| 63 |
-
|
| 64 |
class RuREBusBuilder(datasets.GeneratorBasedBuilder):
|
| 65 |
base_url = 'https://cloud-api.yandex.net/v1/disk/public/resources/download?'
|
| 66 |
public_key = 'https://disk.yandex.ru/d/t1WakmYXlL6jBw'
|
|
@@ -122,13 +81,7 @@ class RuREBusBuilder(datasets.GeneratorBasedBuilder):
|
|
| 122 |
),
|
| 123 |
]
|
| 124 |
else:
|
| 125 |
-
|
| 126 |
-
# decode_file_names(folder)
|
| 127 |
-
zip_file = dl_manager.download(self._RAW_TXT_URLS)['raw_txt']
|
| 128 |
-
try:
|
| 129 |
-
folder = extract(zip_file)
|
| 130 |
-
except FileNotFoundError:
|
| 131 |
-
folder = None
|
| 132 |
return [
|
| 133 |
datasets.SplitGenerator(
|
| 134 |
name='raw_txt',
|
|
@@ -143,15 +96,13 @@ class RuREBusBuilder(datasets.GeneratorBasedBuilder):
|
|
| 143 |
for i, line in enumerate(f):
|
| 144 |
yield i, json.loads(line)
|
| 145 |
else:
|
| 146 |
-
|
| 147 |
-
return
|
| 148 |
-
path = Path(filepath) / 'MED_txt/unparsed_txt'
|
| 149 |
i = 0
|
| 150 |
for root, dirs, files in os.walk(path):
|
| 151 |
if files:
|
| 152 |
root = Path(root)
|
| 153 |
-
region = root.parent.name
|
| 154 |
-
district = root.name
|
| 155 |
titles = {}
|
| 156 |
with open(root / 'name_dict.txt', encoding='utf-8') as f_titles:
|
| 157 |
for line in f_titles:
|
|
|
|
| 3 |
import requests
|
| 4 |
from urllib.parse import urlencode
|
| 5 |
from pathlib import Path
|
|
|
|
| 6 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
_NAME = 'RuREBus'
|
| 9 |
_CITATION = '''
|
|
|
|
| 20 |
_VERSION = '1.0.0'
|
| 21 |
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
class RuREBusBuilder(datasets.GeneratorBasedBuilder):
|
| 24 |
base_url = 'https://cloud-api.yandex.net/v1/disk/public/resources/download?'
|
| 25 |
public_key = 'https://disk.yandex.ru/d/t1WakmYXlL6jBw'
|
|
|
|
| 81 |
),
|
| 82 |
]
|
| 83 |
else:
|
| 84 |
+
folder = dl_manager.download_and_extract(self._RAW_TXT_URLS)['raw_txt']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
return [
|
| 86 |
datasets.SplitGenerator(
|
| 87 |
name='raw_txt',
|
|
|
|
| 96 |
for i, line in enumerate(f):
|
| 97 |
yield i, json.loads(line)
|
| 98 |
else:
|
| 99 |
+
path = os.path.join(filepath, 'MED_txt/unparsed_txt')
|
|
|
|
|
|
|
| 100 |
i = 0
|
| 101 |
for root, dirs, files in os.walk(path):
|
| 102 |
if files:
|
| 103 |
root = Path(root)
|
| 104 |
+
region = root.parent.name.encode('cp437').decode('cp866')
|
| 105 |
+
district = root.name.encode('cp437').decode('cp866')
|
| 106 |
titles = {}
|
| 107 |
with open(root / 'name_dict.txt', encoding='utf-8') as f_titles:
|
| 108 |
for line in f_titles:
|
utils.py
DELETED
|
@@ -1,17 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
class IsNotebook:
|
| 3 |
-
def __init__(self):
|
| 4 |
-
try:
|
| 5 |
-
shell = get_ipython().__class__.__name__
|
| 6 |
-
if shell == 'ZMQInteractiveShell':
|
| 7 |
-
self._is_notebook = True
|
| 8 |
-
else:
|
| 9 |
-
self._is_notebook = False
|
| 10 |
-
except NameError:
|
| 11 |
-
self._is_notebook = False
|
| 12 |
-
|
| 13 |
-
def __call__(self, *args, **kwargs):
|
| 14 |
-
return self._is_notebook
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
is_notebook = IsNotebook()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|