From 162b14c17f03c76ba3a1daae65b7cd70aa92ffd2 Mon Sep 17 00:00:00 2001 From: George Burton <8233643+gecBurton@users.noreply.github.com> Date: Sat, 30 Jan 2021 12:03:12 +0000 Subject: [PATCH] moved db construction to where it is used (#44) --- inference_logic/algorithms.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/inference_logic/algorithms.py b/inference_logic/algorithms.py index 89babcc..2dbbefd 100644 --- a/inference_logic/algorithms.py +++ b/inference_logic/algorithms.py @@ -16,7 +16,6 @@ def search(db: List, query: ImmutableDict) -> Iterator[Dict[Variable, Any]]: - db = [Rule(item) if not isinstance(item, Rule) else item for item in db] query = construct(query) i = 0 @@ -38,6 +37,8 @@ def search(db: List, query: ImmutableDict) -> Iterator[Dict[Variable, Any]]: pass else: for rule in db: + if not isinstance(rule, Rule): + rule = Rule(rule) i += 1 rule = new_frame(rule, i) @@ -54,8 +55,8 @@ def search(db: List, query: ImmutableDict) -> Iterator[Dict[Variable, Any]]: ), ) - for x in new_terms: - stack.append((Rule(*x), new_known)) + for terms in new_terms: + stack.append((Rule(*terms), new_known)) solutions = new_known.solutions(to_solve_for)