-
Notifications
You must be signed in to change notification settings - Fork 0
/
doesEnd.py
82 lines (61 loc) · 2.19 KB
/
doesEnd.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
76
77
78
79
80
81
82
import re
actionRe = r"""
action\(\n\s+(?P<name>[a-zA-Z_\(\),\s]+),\s*\n
\s+\[(?P<preT>[,\sa-zA-Z_\(\)]+)\],\s*\n
\s+\[(?P<preF>[,\sa-zA-Z_\(\)]*)\],\s*\n
\s+\[(?P<finT>[,\sa-zA-Z_\(\)]*)\],\s*\n
\s+\[(?P<kb>[,\sa-zA-Z_\(\)]*)\],\s*\n
\s+\[(?P<eff>[\s\n,a-zA-Z_\(\)]+)\]\n\)\.""".replace(" ","").replace("\n","")
addEffRe = r'add\((?P<pred>[a-zA-Z\(\)_]+)\)'
delEffRe = r'del\((?P<pred>[a-zA-Z\(\)_]+)\)'
actions = []
class Action:
def __init__(self, name_, preT_, preF_, finT_, kb_, eff_):
self.name = name_
self.preT = preT_
self.preF = preF_
self.finT = finT_
self.kb = kb_
self.eff = eff_
def applyNegEff(self, predicates):
for negPred in re.finditer(delEffRe, self.eff):
if negPred:
try:
predicates.remove(negPred["pred"])
except Exception as E:
pass
def applyPosEff(self, predicates):
for posPred in re.finditer(addEffRe, self.eff):
if posPred:
predicates.append(posPred["pred"])
def __str__(self):
return "action(\n\t{}\n\t[{}]\n\t[{}]\n\t[{}]\n\t[{}]\n\t[{}])".format(
self.name, self.preT, self.preF, self.finT, self.kb, self.eff
)
def main():
global actions
predicates = []
with open("examples/medical/actions.pl", "r") as file:
data = file.read()
for actionText in re.finditer(actionRe, data):
if actionText:
actions.append(Action(
actionText.groupdict()["name"],
actionText.groupdict()["preT"],
actionText.groupdict()["preF"],
actionText.groupdict()["finT"],
actionText.groupdict()["kb"],
actionText.groupdict()["eff"]
))
print(len(actions))
for action in actions:
action.applyPosEff(predicates)
for pred in predicates:
print(pred)
for action in actions:
action.applyNegEff(predicates)
print("\nRemaining:")
for pred in predicates:
print(pred)
if __name__ == "__main__":
main()