iluvvatar commited on
Commit
dce6180
·
1 Parent(s): bb65fe2

1.0.0 further bug investigations

Browse files
Files changed (2) hide show
  1. RuREBus.py +3 -6
  2. utils.py +13 -0
RuREBus.py CHANGED
@@ -7,7 +7,7 @@ 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
@@ -46,8 +46,6 @@ _VERSION = '1.0.0'
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:
@@ -125,10 +123,9 @@ class RuREBusBuilder(datasets.GeneratorBasedBuilder):
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
- raise ValueError(zip_file)
129
- try:
130
  folder = extract(zip_file)
131
- except FileNotFoundError:
132
  folder = None
133
  return [
134
  datasets.SplitGenerator(
 
7
  import os
8
  import shutil
9
 
10
+ from .utils import is_notebook, is_url
11
 
12
  if is_notebook:
13
  from tqdm.notebook import tqdm
 
46
 
47
  def extract(zip_file_path):
48
  p = Path(zip_file_path)
 
 
49
  dest_dir = str(p.parent / 'extracted' / p.stem)
50
  os.makedirs(dest_dir, exist_ok=True)
51
  with zipfile.ZipFile(zip_file_path) as archive:
 
123
  # folder = dl_manager.download_and_extract(self._RAW_TXT_URLS)['raw_txt']
124
  # decode_file_names(folder)
125
  zip_file = dl_manager.download(self._RAW_TXT_URLS)['raw_txt']
126
+ if not is_url(zip_file):
 
127
  folder = extract(zip_file)
128
+ else:
129
  folder = None
130
  return [
131
  datasets.SplitGenerator(
utils.py CHANGED
@@ -1,3 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
  class IsNotebook:
3
  def __init__(self):
 
1
+ import re
2
+
3
+
4
+ def is_url(s: str):
5
+ regex = re.compile(
6
+ r'^(?:http|ftp)s?://' # http:// or https://
7
+ r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...
8
+ r'localhost|' #localhost...
9
+ r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
10
+ r'(?::\d+)?' # optional port
11
+ r'(?:/?|[/?]\S+)$', re.IGNORECASE)
12
+ return re.match(regex, s) is not None
13
+
14
 
15
  class IsNotebook:
16
  def __init__(self):