|
import json |
|
import re |
|
|
|
def Clean_output_file(input_file_path, output_file_path): |
|
with open(input_file_path, 'r') as input_file, open(output_file_path, 'w') as output_file: |
|
for line in input_file: |
|
|
|
item = json.loads(line) |
|
|
|
|
|
if 'text' in item: |
|
patterns_to_remove = [ |
|
r'Author:.*?\n', |
|
r'\+ More articles by.*?\n', |
|
r'- Hide list.*?\n', |
|
r'Rating:.*?\n', |
|
r'\n\uf129\n.*?\n', |
|
] |
|
|
|
|
|
for pattern in patterns_to_remove: |
|
item['text'] = re.sub(pattern, '', item['text'], flags=re.DOTALL) |
|
|
|
item['text'] = item['text'].replace('\u00a0', ' ') |
|
item['text'] = item['text'].replace('\u2008', ' ') |
|
item['text'] = item['text'].replace('\u2019', '\'') |
|
|
|
|
|
item['text'] = re.sub(r'\n\s*\n', '\n\n', item['text']) |
|
|
|
|
|
if ("This page doesn" in item['text'] or |
|
"+ Show component code" in item['text'] or |
|
"position: relative" in item['text'] or |
|
"Don't forget to fill out this" in item['text']or |
|
"Table of Contents" in item['text'] or |
|
"Tales by SCP Series" in item['text']) : |
|
continue |
|
|
|
|
|
item['text'] = re.sub(r'rating: \+.*?\n', '', item['text'], flags=re.DOTALL) |
|
|
|
|
|
json.dump(item, output_file) |
|
output_file.write('\n') |
|
|
|
|
|
|
|
for num in range(1,9): |
|
input_file_path = f'scp_stories{num}.jsonl' |
|
output_file_path = f'stories{num}.jsonl' |
|
Clean_output_file(input_file_path, output_file_path) |
|
|
|
|
|
input_file_path = f'scp_tales.jsonl' |
|
output_file_path = f'scp_tales_cleaned.jsonl' |
|
Clean_output_file(input_file_path, output_file_path) |
|
|
|
|
|
input_file_path = f'scp_jokes.jsonl' |
|
output_file_path = f'jokes-cleaned.jsonl' |
|
Clean_output_file(input_file_path, output_file_path) |