Class KB
source code
A Knowledge base to which you can tell and ask sentences. To create a
KB, first subclass this class and implement tell, ask_generator, and
retract. Why ask_generator instead of ask? The book is a bit vague on
what ask means -- For a Propositional Logic KB, ask(P & Q) returns
True or False, but for an FOL KB, something like ask(Brother(x, y)) might
return many substitutions such as {x: Cain, y: Abel}, {x: Abel, y: Cain},
{x: George, y: Jeb}, etc. So ask_generator generates these one at a time,
and ask either returns the first one or returns False.
|
|
|
ask(self,
query)
Ask returns a substitution that makes the query true, or it returns
False. |
source code
|
|
|
ask_generator(self,
query)
Yield all the substitutions that make query true. |
source code
|
|
|
retract(self,
sentence)
Remove the sentence from the KB |
source code
|
|
|
tell(self,
sentence)
Add the sentence to the KB |
source code
|
|
Ask returns a substitution that makes the query true, or it returns
False. It is implemented in terms of ask_generator.
|