From f0d7ee2d5eb1cd579b8b27321fc86580294ce54a Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Mon, 6 Mar 2023 08:16:20 -0500 Subject: [PATCH] Add derive2 --- resolution.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/resolution.py b/resolution.py index c2f8dd6..7aea69e 100644 --- a/resolution.py +++ b/resolution.py @@ -95,6 +95,29 @@ def derive(clauses: Sequence[Clause]) -> Sequence[Clause]: for clause in merge_clauses(c1, c2) ] +def derive2(kb1: Sequence[Clause], kb2: Sequence[Clause]) -> Sequence[Clause]: + """ + All clauses which derive in one step from the combination of two knowledge bases + + Each resulting clause is the combination of one clause from the left knowledge base + with exactly one clause from the right knowledge base. Clauses from the same + knowledge base will not be combined. + + >>> derive2([ + ... [IRNeg(IRProp('animal', [IRProp('Kim')]))], + ... [IRNeg(IRProp('cat', [IRVar('x1')])), IRProp('animal', [IRVar('x1')])], + ... ], [ + ... [IRNeg(IRProp('dog', [IRVar('x0')])), IRProp('animal', [IRVar('x0')])], + ... [IRProp('dog', [IRProp('Kim')])], + ... ]) + [[¬dog(Kim())]] + """ + return [ + clause + for (c1, c2) in product(kb1, kb2) + for clause in merge_clauses(c1, c2) + ] + if __name__ == '__main__': import doctest doctest.testmod() \ No newline at end of file