12
12
13
13
def find_symbols_in_kb (knowledge_base : list [str ]) -> dict :
14
14
'''
15
- Find all unique symbols in the Knowledge_base
15
+ Find all unique symbols in the Knowledge_base.
16
16
:param knowledge_base: a list of string of definite clauses
17
17
:returns: a dictionary with symbols as the keys their values are False
18
18
'''
@@ -31,9 +31,9 @@ def find_symbols_in_kb(knowledge_base: list[str]) -> dict:
31
31
def number_of_symbols_in_premise (knowledge_base : list [str ]) -> dict :
32
32
33
33
'''
34
- Count the number of prposiotion symbols in each premise of KB clause
34
+ Count the number of prposiotion symbols in each premise of KB clause.
35
35
:param knowledge_base: a list of string of definite clauses
36
- :returns: a dictionary with key as the premise of KB clause and value of count of symbols in the premise
36
+ :returns: a dict with keys as the premise and value is count of symbols in premise
37
37
'''
38
38
39
39
count = {}
@@ -49,7 +49,7 @@ def number_of_symbols_in_premise(knowledge_base: list[str]) -> dict:
49
49
50
50
def get_known_facts (knowledge_base : list [str ]) -> list [str ]:
51
51
'''
52
- Get the known facts in KB
52
+ Get the known facts in KB.
53
53
:param knowledge_base: a list of string of definite clauses
54
54
:returns: list of facts
55
55
@@ -66,13 +66,17 @@ def get_known_facts(knowledge_base: list[str]) -> list[str]:
66
66
67
67
68
68
def forward_chaining (knowledge_base : list [str ], query :str ) -> bool :
69
- ''' Forward chaining on Knowledge Base(KB) of definite clauses
69
+ ''' Forward chaining on Knowledge Base(KB) of definite clauses.
70
70
:param knowledge_base: a list of string of definite clauses
71
- :param query: a single proposition symbol that you are checking if it is entailed by the KB
71
+ :param query: a single proposition symbol
72
72
:returns: If the query entailed by the KB or not?
73
- >>> forward_chaining([ "P => Q", "L & M => P", "B&L=> M", "A&P=>L", "A&B=>L", "A", "B" ], "Q")
73
+ >>> input_kb = [ "P => Q", "L & M => P",
74
+ ... "B&L=> M", "A&P=>L", "A&B=>L", "A", "B" ]
75
+ >>> forward_chaining(input_kb, "Q")
74
76
True
75
- >>> forward_chaining([ "P => Q", "L & M => P", "B&L=> M", "A&P=>L", "A&B=>L", "A", "B" ], "C")
77
+ >>> input_kb = [ "P => Q", "L & M => P",
78
+ ... "B&L=> M", "A&P=>L", "A&B=>L", "A", "B" ]
79
+ >>> forward_chaining(input_kb, "C")
76
80
False
77
81
78
82
'''
@@ -110,15 +114,14 @@ def forward_chaining(knowledge_base: list[str], query:str) -> bool:
110
114
111
115
'''
112
116
1)- KB must be written in horn form.
113
- 2)- It must be written as an implcaion whose
114
117
2)- It must be written as an implcaion whose
115
- its premise(head) must be conjunction of positive literals and its conclusion(body)
116
- 3)- It must contains facts about the world which are written as a single proposition symbol
118
+ its premise(head) must be conjunction of positive literals and its conclusion(body).
119
+ 3)- Contains facts about the world as single proposition symbol.
117
120
'''
118
121
QUERY = "Q"
119
122
120
123
'''
121
- Query is a signe proposition symbol that you check if it is entailed by the KB
124
+ Query is a signe proposition symbol that you check if it is entailed by the KB.
122
125
123
126
'''
124
127
0 commit comments