-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
97 lines (88 loc) · 4.14 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import os
from sympy import SympifyError
from src.AGMPostulates import display_agm_postulates
from src.Agent import Agent
from src.BeliefBase import BeliefBase
belief_base = BeliefBase()
god = Agent(belief_base)
def main_menu():
choice = 0
while True:
res = input("Select option to continue...").strip()
if not res.isdigit():
print("Invalid input. Please enter a number.")
print_help()
continue
if int(res) == 1:
# We need error handling around these
try:
query = input("§ Enter discovery to expand -> ").strip()
god.expansion(query)
print(f"\t<> Belief base expanded with {query}")
except SympifyError as e:
print(f"Invalid input: {e}. Operation failed, returning to main menu...")
elif int(res) == 2:
try:
query = input("§ Enter statement to remove -> ").strip()
god.contraction(query)
print(f"\t<> Belief base contracted with {query}")
except SympifyError as e:
print(f"Invalid input: {e}. Operation failed, returning to main menu...")
elif int(res) == 3:
try:
query = input("§ Enter reliable statement to revise -> ").strip()
god.revision(query)
print(f"\t<> Belief base revised with {query}")
except SympifyError as e:
print(f"Invalid input: {e}. Operation failed, returning to main menu...")
elif int(res) == 4:
try:
query = input("§ Enter statement to check entailment -> ").strip()
print("# Checking entailment by belief base...")
if god.check_entailment(query):
print(f"\t<> The statement {query} is entailed (implied)")
else:
print(f"\t<> The statement {query} is not entailed (free or contradicted)")
print("# Checking consistency (lack of contradiction) with belief base...")
if god.check_consistent(query):
print(f"\t<> The statement {query} is consistent")
else:
print(f"\t<> The statement {query} is inconsistent (contradicted)")
except SympifyError as e:
print(f"Invalid input: {e}. Operation failed, returning to main menu...")
elif int(res) == 5:
try:
phi = input("§ Enter φ -> ").strip()
if phi == "":
print("Empty input for φ. Operation failed, returning to main menu...")
continue
psi = input("§ Enter optional ψ (for extensionality) -> ").strip()
psi = psi if psi else None
print("# Testing the AGM Postulates...")
display_agm_postulates(god.get_belief_base(), phi, psi)
except SympifyError as e:
print(f"Invalid input: {e}. Operation failed, returning to main menu...")
elif int(res) == 6:
print(god.get_belief_base())
else:
print("Exiting... Thank you for using the agent!")
break
def print_help():
print("_______________________________________________________")
print("The following operations are supported by the agent:")
print("1. Add a new discovery to the belief base - expansion BB + φ")
print("2. Remove a statement from the belief base - contraction BB ÷ φ")
print("3. Update the belief base with a reliable statement - revision BB * φ")
print("4. Check if a statement is consistent with the belief base - entailment BB ⊨ φ")
print("5. Run the AGM postulates")
print("6. Query the state of the belief base BB")
print("7. Exit the agent")
print("_______________________________________________________")
print("Propositional logic supports the following operators: &, |, ~, >>, <<")
# Project entrypoint
if __name__ == "__main__":
os.system('cls' if os.name == 'nt' else 'clear')
print("~~~ Welcome to our Belief Revision Agent! ~~>\n")
print_help()
# Involve query caller
main_menu()