forked from tpsilva/TextExpansion
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
49 lines (36 loc) · 1.21 KB
/
main.py
File metadata and controls
49 lines (36 loc) · 1.21 KB
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
import ui.window
import sys
from expansion import expansion
def read_samples(dataset_path):
input_file = open(dataset_path)
samples = [l.strip("\n") for l in input_file.readlines()]
input_file.close()
return samples
def command_line():
(lingo, original, concepts, disambiguation) = [d.upper() == "Y" for d in sys.argv[1]]
use_wordnet = sys.argv[2] == "-wn"
use_wikipedia = sys.argv[2] == "-wiki"
dataset_index = 0
if not use_wordnet and not use_wikipedia:
use_wordnet = use_wikipedia = True
dataset_index = 2
else:
dataset_index = 3
dataset_path = sys.argv[dataset_index]
samples = read_samples(dataset_path)
custom_dictionaries = sys.argv[dataset_index + 1:]
expanded_samples = expansion.expand(samples,
(lingo, original, concepts, disambiguation),
(use_wordnet, use_wikipedia),
*custom_dictionaries)
output_file = open(dataset_path + "_expanded.txt", "w")
output_file.write("\n".join(expanded_samples))
output_file.close()
def main():
if len(sys.argv) == 1:
window = ui.window.MainWindow()
window.run()
else:
command_line()
if __name__ == "__main__":
main()