-
Notifications
You must be signed in to change notification settings - Fork 0
/
sconvert.py
68 lines (52 loc) · 1.93 KB
/
sconvert.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
###################################
# Written by Shirin Sohrabi #
# Edited by Daniel Kats #
# May 16, 2013 #
###################################
import sys
import os
def remove_existing_files(file_list):
'''Delete the existing files in the given list.'''
for item in file_list:
if os.path.exists(item):
os.remove(item)
def partition_translator_output(inputf):
'''Take the output of the transaltor and split it into 4 files.
Return the filenames as a dictionary:
{'axioms' : axiom_file,
'del_effects' : del_effects_file,
'add_effects' : add_effects_file,
'init_states : init_state_file
}
'''
infile = open(inputf, "r")
outfiles = {
"init_states" : inputf + "_initial_states",
"add_effects" : inputf + "_add_effects",
"del_effects" : inputf + "_del_effects",
"axioms" : inputf + "_axioms"
}
remove_existing_files(outfiles.values())
outfile = open(outfiles["init_states"], "w")
for line in infile:
org = line
line = line.strip()
if not line or line.startswith("Total No. of states"):
continue
if line.startswith(";;"):
outfile.close()
if line==";; initial state":
outfile = open(outfiles["init_states"], "a")
elif line==";; Add Effects":
outfile = open(outfiles["add_effects"], "a")
elif line==";; Delete Effects":
outfile = open(outfiles["del_effects"], "a")
else:
outfile = open(outfiles["axioms"], "a")
else:
outfile.write(org)
infile.close()
outfile.close()
return outfiles
if __name__ == "__main__":
partition_translator_output(sys.argv[1])