Skip to content

Commit c25fc70

Browse files
articuno12norvig
authored andcommitted
Removed errors to make the build pass (aimacode#418)
* removed flake8 errors * fixed remaining flake8 errors * fixed loop * added space
1 parent 3e57e00 commit c25fc70

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

csp.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ def topological_sort(X, root):
339339
visited shows the state (visited - not visited) of nodes
340340
341341
"""
342-
nodes = X.variables
343342
neighbors = X.neighbors
344343

345344
visited = defaultdict(lambda: False)

logic.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,24 @@ def subst(s, x):
845845
return Expr(x.op, *[subst(s, arg) for arg in x.args])
846846

847847

848-
def fol_fc_ask(KB, alpha): # TODO
849-
raise NotImplementedError
848+
def fol_fc_ask(KB, alpha):
849+
"""A simple forward-chaining algorithm. [Figure 9.3]"""
850+
new = []
851+
while new is not None:
852+
for rule in KB.clauses:
853+
p, q = parse_definite_clause(standardize_variables(rule))
854+
for p_ in KB.clauses:
855+
if p != p_:
856+
for theta in KB.clauses:
857+
if subst(theta, p) == subst(theta, p_):
858+
q_ = subst(theta, q)
859+
if not unify(q_, KB.sentence in KB) or not unify(q_, new):
860+
new.append(q_)
861+
phi = unify(q_, alpha)
862+
if phi is not None:
863+
return phi
864+
KB.tell(new)
865+
return None
850866

851867

852868
def standardize_variables(sentence, dic=None):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy