Tomer Sagi commited on
Commit
3b71369
1 Parent(s): 61dedb7

adding language checks and cleaning rules

Browse files
Files changed (2) hide show
  1. requirements.txt +1 -0
  2. scrape_script.py +18 -3
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ langdetect
scrape_script.py CHANGED
@@ -4,7 +4,8 @@ import pandas as pd
4
  import pyarrow as pa
5
  import pyarrow.parquet as pq
6
  import json
7
-
 
8
 
9
  def traverse_directory(root_path, callback):
10
  for dirpath, _, filenames in os.walk(root_path):
@@ -36,12 +37,26 @@ def append_to_parquet(content, file_path, lang, top_level_directory):
36
  os.makedirs(data_dir)
37
 
38
  if lang == "en":
39
- parquet_file = os.path.join(data_dir, f"{top_level_directory}_english.parquet")
40
  elif lang == "he":
41
- parquet_file = os.path.join(data_dir, f"{top_level_directory}_hebrew.parquet")
42
  else:
43
  return
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  metadata = {"file": file_path}
46
  meta_json = json.dumps(metadata)
47
 
 
4
  import pyarrow as pa
5
  import pyarrow.parquet as pq
6
  import json
7
+ import re
8
+ from langdetect import detect
9
 
10
  def traverse_directory(root_path, callback):
11
  for dirpath, _, filenames in os.walk(root_path):
 
37
  os.makedirs(data_dir)
38
 
39
  if lang == "en":
40
+ parquet_file = os.path.join(data_dir, f"train_{top_level_directory}_english.parquet")
41
  elif lang == "he":
42
+ parquet_file = os.path.join(data_dir, f"train_{top_level_directory}_hebrew.parquet")
43
  else:
44
  return
45
 
46
+ # Check if the content is in French or Spanish
47
+ detected_lang = detect(content)
48
+ if detected_lang == 'fr' or detected_lang == 'es':
49
+ return
50
+
51
+ # Apply cleaning rules
52
+ content = re.sub(r'<span[^>]*>|</span>', '', content) # Remove HTML spans
53
+
54
+ # Remove chapter markers
55
+ chapter_markers = ['Chapter', 'Halakhah']
56
+ for marker in chapter_markers:
57
+ content = re.sub(rf'^{marker} \d+$', '', content, flags=re.MULTILINE)
58
+
59
+
60
  metadata = {"file": file_path}
61
  meta_json = json.dumps(metadata)
62