-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforward_chaining.py
More file actions
63 lines (47 loc) · 2.1 KB
/
forward_chaining.py
File metadata and controls
63 lines (47 loc) · 2.1 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from basegraph import graph as grafo
def check_if_is_spouse(person1, person2):
return person2 in grafo[person1]["spouse"]
def check_if_has_relationship(person1, person2):
return person2 in grafo[person1]["relationships"]
def check_if_is_child(person, parent):
return person in grafo[parent]["parent"]
def check_if_is_bastard_kid(person1, person2):
clause_is_child_of_spouse = False
for spouse in grafo[person2]["spouse"]:
try:
clause_is_child_of_spouse = check_if_is_child(person1, spouse)
if(clause_is_child_of_spouse == True):
break;
except KeyError:
continue
clause_is_child = check_if_is_child(person1, person2)
#print(clause_is_child_of_spouse)
print("Bastard: ",clause_is_child and not clause_is_child_of_spouse)
return clause_is_child and not clause_is_child_of_spouse
def check_if_is_lover_of_henryVIII(person):
clause_has_relationship = check_if_has_relationship("henryVIII", person)
clause_is_spouse = check_if_is_spouse("henryVIII", person)
print("Lover: ",clause_has_relationship and not clause_is_spouse)
return clause_has_relationship and not clause_is_spouse
def check_if_is_is_granchild_of_henryVII(person):
for child in grafo["henryVII"]["parent"]:
if check_if_is_child(person, child):
print("Grandchild: ",True)
return True
print("Grandchild: ",False)
def check_if_can_claim_throne(person):
if not check_if_is_child(person, "henryVIII"):
print(False)
return False
clause_is_legit_child = not check_if_is_bastard_kid(person, "henryVIII")
clause_is_male = False
if (grafo[person]["sex"] == 'male'):
clause_is_male = True
#print("H: ",grafo[person]["sex"])
print("Can claim throne: ",clause_is_legit_child and clause_is_male)
return clause_is_legit_child and clause_is_male
relations = {"bastard": check_if_is_bastard_kid,
"lover": check_if_is_lover_of_henryVIII,
"granchild": check_if_is_is_granchild_of_henryVII,
"claim": check_if_can_claim_throne
}