-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
75 lines (64 loc) · 2.79 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import subprocess
import argparse
from Convert_And_Extract import main as convert_and_extract
from Preprocess import main as preprocess
from NER import main as ner
from Cooccurrence import main as cooccurrence
from Relationship import main as relation
from Graph import main as generate_graphs
from Get_Timeline import main as get_timeline
def main():
print("Check tools and environments")
check_tools_and_environemnts()
print("All tools requirements satisfied")
main_process()
def main_process():
print("Convert and extracting")
convert_and_extract()
print("Preprocessing")
preprocess()
print("NERing")
ner()
print("Relation Analyzing")
relation()
print("Counting cooccurrence")
cooccurrence()
print("Generating graphs")
generate_graphs()
print("Generating timeline")
get_timeline()
def check_tools_and_environemnts():
print("Checking output directories exist")
makedirs_if_not_exist('./DataBase/tmp')
makedirs_if_not_exist('./DataBase/raw_txt')
makedirs_if_not_exist('./DataBase/mature_txt')
makedirs_if_not_exist('./DataBase/ner_result')
makedirs_if_not_exist('./DataBase/relation')
makedirs_if_not_exist('./DataBase/cooccurrence')
makedirs_if_not_exist('./DataBase/timeline')
print("Checking python packages")
subprocess.run("pip3 install --require ./requirements.txt".split())
print("Checking supplement files")
if not os.path.isfile('./Tools/Appendix-Names.dict.txt'):
raise ToolsError("No Appendix-Names.dict.txt, goto Get-Tools and execute Get_Appendix_Names.py")
if not os.path.isfile('./DataBase/tmp/Japanese-Surnames.json'):
raise ToolsError("No Japanese-Surnames.json, goto Get-Tools and execute Japanese_Surname_Crowler.py")
if not os.path.isfile('./Tools/Japanese-Surnames-in-zhTW.json'):
raise ToolsError("No Japanese-Surnames-in-zhTW.json, goto Get-Tools and execute Translate_Word_Jp2zhTW_Crowler.py. !! ABOUT SIX HOURS NEEDED !!")
if not os.path.isfile('./Tools/Mainland-Place-Names.json'):
raise ToolsError("No Mainland-Place-Names.json, goto Get-Tools and execute Mainland-Placename-Crowler.py")
print("Checking stanford tool")
if not os.path.isdir('./Tools/stanford-corenlp-full-2018-02-27'):
raise ToolsError("No corenlp, Download corenlp and unzip under Tools.")
if not os.path.isfile('./Tools/stanford-corenlp-full-2018-02-27/stanford-chinese-corenlp-2018-02-27-models.jar'):
raise ToolsError("No corenlp-chinese-model, Download it and place under stanford directory")
if __name__ == '__main__':
main()
class ToolsError(Exception):
def __init__(self, message):
super().__init__(message)
def makedirs_if_not_exist(path):
try:
os.makedirs(path)
except FileExistsError:
pass