Add derive2
This commit is contained in:
parent
b046152a4c
commit
f0d7ee2d5e
|
@ -95,6 +95,29 @@ def derive(clauses: Sequence[Clause]) -> Sequence[Clause]:
|
||||||
for clause in merge_clauses(c1, c2)
|
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__':
|
if __name__ == '__main__':
|
||||||
import doctest
|
import doctest
|
||||||
doctest.testmod()
|
doctest.testmod()
|
Loading…
Reference in a new issue