some general people rules
OK. Now we have |_self>, general rules, and stored rules, we can give this example.
Basically a set of rules that apply to all people. I was going to put it in the George example post, but I think it deserves its own post.
-- some general rules that apply to all people:
siblings |person: *> #=> brothers |_self> + sisters |_self>
children |person: *> #=> sons |_self> + daughters |_self>
parents |person: *> #=> mother |_self> + father |_self>
uncles |person: *> #=> brothers parents |_self>
aunts |person: *> #=> sisters parents |_self>
aunts-and-uncles |person: *> #=> siblings parents |_self>
cousins |person: *> #=> children siblings parents |_self>
grand-fathers |person: *> #=> father parents |_self>
grand-mothers |person: *> #=> mother parents |_self>
grand-parents |person: *> #=> parents parents |_self>
grand-children |person: *> #=> children children |_self>
great-grand-parents |person: *> #=> parents parents parents |_self>
great-grand-children |person: *> #=> children children children |_self>
immediate-family |person: *> #=> siblings |_self> + parents |_self> + children |_self>
friends-and-family |person: *> #=> friends |_self> + family |_self>
Let's call the above "general-people-rules.sw" and load it in the console:
(note that we haven't defined context, so it happily loads into your current context -- this is often a useful trick)
sa: load general-people-rules.sw
-- now, let's define some knowledge about Fred:
sa: mother |person: Fred> => |person: Judith>
sa: father |person: Fred> => |person: Frank>
sa: sisters |person: Fred> => |person: Liz> + |person: Emma> + |person: Jane>
OK. So what?
Well, using the general rules, we can now answer who Fred's parents and siblings are:
(without having to specify them manually. mother/father/sisters/brothers is sufficient)
sa: parents |person: Fred>
|person: Judith> + |person: Frank>
sa: siblings |person: Fred>
|person: Liz> + |person: Emma> + |person: Jane>
-- OK. Learn Fred has a brother Jack:
sa: brothers |person: Fred> => |person: Jack>
-- now we know that, ask again who Fred's siblings are:
sa: siblings |person: Fred>
|person: Jack> + |person: Liz> + |person: Emma> + |person: Jane>
-- now, how about Fred's immediate-family?
sa: immediate-family |person: Fred>
|person: Jack> + |person: Liz> + |person: Emma> + |person: Jane> + |person: Judith> + |person: Frank>
Also, a LOL. The console spat out a page of debugging info just to provide that last example. So what I haven't told you is that currently the console is very noisy, and I have been chomping out the debugging info by hand. Eventually when I'm 100% happy with everything I guess I will switch off debugging. Probably also a hint that my code is far more inefficient than it needs to be!
So there you have it!
The self ket, "person: *" general rules, and stored rules, all in one example.
And the "person: *" thing is one reason why categories/data-types are often useful to use. We can define general rules that apply to a category of objects, rather than to all objects.
Also, I guess in other projects, the above might be called "an inference engine". I mean, yeah, sort of. But BKO is in some sense more direct, while most inference engines try to use chains of logic.
More to come!
previous: a fictional george in sw format
next: the methanol molecule in sw format
by Garry Morrison
email: garry -at- semantic-db.org