-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepare_time_dataset.py
56 lines (46 loc) · 2.08 KB
/
prepare_time_dataset.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import sys
import os
import zipfile
import tarfile
import shutil
from urllib.request import urlretrieve
from anafora import copy_text
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
def prepare_practice(target_path):
time_path = os.path.join(target_path, "time")
if os.path.exists(time_path):
raise Exception("%s already exists!" % time_path)
download_path = os.path.join(target_path, "download")
os.makedirs(download_path, exist_ok=True)
with open("practice_time_documents.txt") as list_file:
practice_document_list = list_file.read().strip().split("\n")
practice_document_list = list(map(os.path.normpath, practice_document_list))
print("Downloading tbaq-2013-03.zip...", end=" ", flush=True)
zip_path = os.path.join(download_path, "tbaq-2013-03.zip")
urlretrieve("https://www.cs.york.ac.uk/semeval-2013/task1/data/uploads/datasets/tbaq-2013-03.zip", zip_path)
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
zip_ref.extractall(download_path)
tbaq_path = os.path.join(download_path, "TBAQ-cleaned")
print("Done.")
print("Downloading te3-platinumstandard.tar.gz...", end=" ", flush=True)
tar_path = os.path.join(download_path, "te3-platinumstandard.tar.gz")
urlretrieve("https://www.cs.york.ac.uk/semeval-2013/task1/data/uploads/datasets/te3-platinumstandard.tar.gz", tar_path)
tar = tarfile.open(tar_path)
tar.extractall(tbaq_path)
tar.close()
print("Done.")
print("Copying text...", end=" ", flush=True)
os.makedirs(time_path, exist_ok=True)
copy_text.copy_timeml_text(tbaq_path, time_path, "", False)
print("Done.")
print("Cleaning directory...", end=" ", flush=True)
for root, _, files in os.walk(time_path):
if files:
document_rel_path = os.path.relpath(root, time_path)
if document_rel_path not in practice_document_list:
shutil.rmtree(root)
shutil.rmtree(download_path)
print("Done.")
if __name__ == "__main__":
prepare_practice(sys.argv[1])