Re: context/world and asserting in multiple contexts
Thomas Russ <[email protected]> Wed, 22 Nov 2006 10:09:51 -0800
| Newsgroups | gmane.comp.ai.powerloom |
|---|---|
| Message-ID | <[email protected]> |
On Nov 22, 2006, at 5:42 AM, Kambiz Darabi wrote:
>> If they are arranged hierarchically, then you can just make
>> the assertion in the higher level module and have it then
>> be visible (via inheritance) in the lower level modules.
>> This applies for assertions made at any time.
>
> Thank you for the hint.
>
> In defmodule, can one use :includes with multiple other modules?
> IOW have modules a single inheritance hierarchy? The manual entry
> for defmodule seem to suggest that.
Modules can have multiple parents. That's why the argument to
:includes is a list.
=============================================================
(defmodule top :includes ("PL-KERNEL-KB"))
(defmodule mid-1 :includes ("TOP"))
(defmodule mid-2 :includes ("TOP"))
(defmodule bottom :includes ("MID-1" "MID-2"))
(in-module "TOP")
(defrelation r (?x ?y))
(assert (thing test)) ; To create instance here to share.
(in-module "MID-1")
(assert (r test mid-1-value))
(in-module "MID-2")
(assert (r test mid-2-value))
(in-module "BOTTOM")
(retrieve all (r ?x ?y))
There are 2 solutions:
#1: ?X=TEST, ?Y=MID-2-VALUE
#2: ?X=TEST, ?Y=MID-1-VALUE
=============================================================
One important consideration, though is that if you introduce
individuals in sibling modules, then you will get different
individuals. For example:
=============================================================
(in-module "MID-1")
(assert (r fred bill))
(in-module "MID-2")
(assert (r fred john))
(in-module "BOTTOM")
(retrieve all (r ?x ?y))
There are 4 solutions:
#1: ?X=/PL-KERNEL-KB/TOP/MID-2/FRED, ?Y=JOHN
#2: ?X=FRED, ?Y=BILL
#3: ?X=TEST, ?Y=MID-2-VALUE
#4: ?X=TEST, ?Y=MID-1-VALUE
(retrieve all (r fred ?y))
There is 1 solution:
#1: ?Y=BILL
(retrieve all (r mid-1/fred ?y))
There is 1 solution:
#1: ?Y=BILL
(retrieve all (r mid-2/fred ?y))
There is 1 solution:
#1: ?Y=JOHN
(ask (= mid-1/fred mid-2/fred))
FALSE
>
> But when I tried, it looked like a module had only one parent. Or
> maybe I made a mistake while declaring the modules.
I'm not sure I understand what you mean about it looking like a
module had only one parent. The printed representation of a module
name will always show only the first of the included modules as
part of the pathname. If you mean something else, send an example
and I'll try to explain what's going on.
For example, the bottom module prints like:
|MDL|/PL-KERNEL-KB/TOP/MID-1/BOTTOM
The printed form is just to give a unique path to the module, not
provide complete information. Right now information about parent
and child modules is not exposed via meta relations in the built-in
knowledge base, but there isn't any reason they couldn't be added
if someone needed to reason about it.