-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathediting_util.py
41 lines (30 loc) · 1.45 KB
/
editing_util.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
""" Utilities for microtext editing """
import json
from unit_checking import get_central_first_texts, get_central_last_texts
def editable_text(text_content):
text_units = text_content['units']
units_list = [f"{text_unit['edu_id']} {text_unit['adu_stance']} {text_unit['text']}" for text_unit in text_units]
out_text = "\n".join(units_list)
return out_text
def create_editing_files(text_database, sub_dir: str):
"""
Creates text files ready for editing from the passed text database in the passed subdirectory.
:param text_database: Dict database with texts and extracted information.
:param sub_dir: Subdirectory to save created files to.
:return: None, files written to disk.
"""
dir_path = f"editing/{sub_dir}/"
for text_id, content in text_database.items():
with open(f"{dir_path}{text_id}.txt", 'w', encoding='utf-8') as out_file:
out_file.write(f"Central claim unit: {content['central_adu']}\nOriginal order:\n")
out_file.write(editable_text(content))
if __name__ == "__main__":
# load database:
with open("extracted_db.json", 'r', encoding='utf-8') as db_file:
database: dict = json.load(db_file)
# show the editing file format:
edit_test = editable_text(database['b001'])
print(edit_test)
# create editing plain text files:
create_editing_files(get_central_first_texts(database), "JJ")
create_editing_files(get_central_last_texts(database), "JJ")