Add a derive method
This commit is contained in:
parent
122b810b73
commit
b046152a4c
|
@ -1,6 +1,6 @@
|
|||
from emis_funky_funktions import *
|
||||
|
||||
from itertools import product
|
||||
from itertools import combinations, product
|
||||
|
||||
from ir import Clause, IRNeg, IRProp, IRTerm, IRVar, Substitutions, sub_all, unify, unify_clauses
|
||||
|
||||
|
@ -75,6 +75,26 @@ def merge_clauses(c1: Clause, c2: Clause) -> Sequence[Clause]:
|
|||
for (subs, i1, i2) in valid_substitutions
|
||||
]
|
||||
|
||||
def derive(clauses: Sequence[Clause]) -> Sequence[Clause]:
|
||||
"""
|
||||
All possible clauses which derive in one step of resolution from a knowledge base
|
||||
|
||||
Attempts to merge every possible combination of clauses, in the knowledge base.
|
||||
|
||||
>>> derive([
|
||||
... [IRNeg(IRProp('animal', [IRProp('Kim')]))],
|
||||
... [IRNeg(IRProp('dog', [IRVar('x0')])), IRProp('animal', [IRVar('x0')])],
|
||||
... [IRNeg(IRProp('cat', [IRVar('x1')])), IRProp('animal', [IRVar('x1')])],
|
||||
... [IRProp('dog', [IRProp('Kim')])],
|
||||
... ])
|
||||
[[¬dog(Kim())], [¬cat(Kim())], [animal(Kim())]]
|
||||
"""
|
||||
return [
|
||||
clause
|
||||
for (c1, c2) in combinations(clauses, 2)
|
||||
for clause in merge_clauses(c1, c2)
|
||||
]
|
||||
|
||||
if __name__ == '__main__':
|
||||
import doctest
|
||||
doctest.testmod()
|
Loading…
Reference in a new issue