Tomer Sagi
commited on
Commit
•
b908117
1
Parent(s):
3b71369
working on #12
Browse files- scrape_script.py +13 -3
scrape_script.py
CHANGED
@@ -43,11 +43,21 @@ def append_to_parquet(content, file_path, lang, top_level_directory):
|
|
43 |
else:
|
44 |
return
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
49 |
return
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
# Apply cleaning rules
|
52 |
content = re.sub(r'<span[^>]*>|</span>', '', content) # Remove HTML spans
|
53 |
|
|
|
43 |
else:
|
44 |
return
|
45 |
|
46 |
+
|
47 |
+
# Check if file_path ends with the pattern [xx].txt
|
48 |
+
file_pattern = re.search(r'\[[a-zA-Z]{2}\]\.txt$', file_path)
|
49 |
+
if file_pattern:
|
50 |
+
print(f"Warning: File '{file_path}' was skipped due to the detected pattern.")
|
51 |
return
|
52 |
|
53 |
+
# Check if the content is in English when lang is "en"
|
54 |
+
if lang == "en":
|
55 |
+
sample_text = content[:500] if len(content) > 500 else content
|
56 |
+
detected_lang = detect(sample_text)
|
57 |
+
if detected_lang != 'en':
|
58 |
+
print(f"Warning: Non-English content detected in file '{file_path}'. Detected language: {detected_lang}")
|
59 |
+
return
|
60 |
+
|
61 |
# Apply cleaning rules
|
62 |
content = re.sub(r'<span[^>]*>|</span>', '', content) # Remove HTML spans
|
63 |
|