1.0.1 xwalk bug fix
Browse files- RuREBus.py +17 -3
- utils.py +17 -0
RuREBus.py
CHANGED
|
@@ -7,6 +7,14 @@ import zipfile
|
|
| 7 |
import os
|
| 8 |
import shutil
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
_NAME = 'RuREBus'
|
| 11 |
_CITATION = '''
|
| 12 |
@inproceedings{rurebus,
|
|
@@ -38,10 +46,12 @@ _VERSION = '1.0.0'
|
|
| 38 |
|
| 39 |
def extract(zip_file_path):
|
| 40 |
p = Path(zip_file_path)
|
|
|
|
|
|
|
| 41 |
dest_dir = str(p.parent / 'extracted' / p.stem)
|
| 42 |
os.makedirs(dest_dir, exist_ok=True)
|
| 43 |
with zipfile.ZipFile(zip_file_path) as archive:
|
| 44 |
-
for file_info in archive.infolist():
|
| 45 |
filename = file_info.filename.encode('cp437').decode('cp866')
|
| 46 |
target = os.path.join(dest_dir, *filename.split('/'))
|
| 47 |
os.makedirs(os.path.dirname(target), exist_ok=True)
|
|
@@ -115,8 +125,10 @@ class RuREBusBuilder(datasets.GeneratorBasedBuilder):
|
|
| 115 |
# folder = dl_manager.download_and_extract(self._RAW_TXT_URLS)['raw_txt']
|
| 116 |
# decode_file_names(folder)
|
| 117 |
zip_file = dl_manager.download(self._RAW_TXT_URLS)['raw_txt']
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
| 120 |
return [
|
| 121 |
datasets.SplitGenerator(
|
| 122 |
name='raw_txt',
|
|
@@ -131,6 +143,8 @@ class RuREBusBuilder(datasets.GeneratorBasedBuilder):
|
|
| 131 |
for i, line in enumerate(f):
|
| 132 |
yield i, json.loads(line)
|
| 133 |
else:
|
|
|
|
|
|
|
| 134 |
path = Path(filepath) / 'MED_txt/unparsed_txt'
|
| 135 |
i = 0
|
| 136 |
for root, dirs, files in os.walk(path):
|
|
|
|
| 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 = '''
|
| 20 |
@inproceedings{rurebus,
|
|
|
|
| 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)
|
|
|
|
| 125 |
# folder = dl_manager.download_and_extract(self._RAW_TXT_URLS)['raw_txt']
|
| 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 |
for i, line in enumerate(f):
|
| 144 |
yield i, json.loads(line)
|
| 145 |
else:
|
| 146 |
+
if filepath is None:
|
| 147 |
+
return
|
| 148 |
path = Path(filepath) / 'MED_txt/unparsed_txt'
|
| 149 |
i = 0
|
| 150 |
for root, dirs, files in os.walk(path):
|
utils.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|