Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Finding Brothers & Sisters (with dbd)

 
   Database Forums (Home) -> Object-Oriented RSS
Next:  Bi-Directional Transitive Closure (with dbd)  
Author Message
neo55592

External


Since: Dec 06, 2004
Posts: 480



(Msg. 1) Posted: Mon Dec 04, 2006 9:14 am
Post subject: Finding Brothers & Sisters (with dbd)
Archived from groups: comp>databases>object (more info?)

The following dbd example models Adam who has children named
John(male), Jack(male) and Mary(female). Queries find John's siblings,
brothers and sisters.

(new 'male 'gender)
(new 'female 'gender)

(new 'adam 'person)

(new 'john 'person)
(set john gender male)

(new 'jack 'person)
(set jack gender male)

(new 'mary 'person)
(set mary gender female)

(new 'child 'verb)
(set adam child john)
(set adam child jack)
(set adam child mary)

(; Get john's siblings
by getting persons
who is a child of john's father
and that person is not himself)
(; Gets jack and mary)
(!= (and (get person instance *)
(get (get * child john) child *))
john)

(; Get john's brothers
by getting persons
whose gender is male
and is child of john's father
and that person is not himself)
(; Gets jack)
(!= (and (get person instance *)
(get * gender male)
(get (get * child john) child *))
john)

(; Get john's sisters
by getting persons
whose gender is female
and is child of john's father
and that person is not himself)
(; Gets mary)
(!= (and (get person instance *)
(get * gender female)
(get (get * child john) child *))
john)

For more examples, see www.dbfordummies.com

 >> Stay informed about: Finding Brothers & Sisters (with dbd) 
Back to top
Login to vote
neo55592

External


Since: Dec 06, 2004
Posts: 480



(Msg. 2) Posted: Fri Dec 22, 2006 9:09 am
Post subject: Re: Finding Brothers & Sisters (with dbd) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

A slight various on the original example. Here we find John's sibling
of opposite gender. Note that the query does not refer to John's father
(Adam) or John's gender (male) directly.

(new 'male 'gender)
(new 'female 'gender)

(new 'opposite 'verb)
(set male opposite female)
(set female opposite male)

(new 'adam 'person)

(new 'john 'person)
(set john gender male)

(new 'jack 'person)
(set jack gender male)

(new 'mary 'person)
(set mary gender female)

(set adam child john)
(set adam child jack)
(set adam child mary)

(; Get john's sibling of opposite gender
by getting persons
whose gender is opposite
and is child of john's parent
and that person is not himself)
(; Gets mary)
(!= (and (get person instance *)
(get * gender (get (get john gender *) opposite *))
(get (get * child john) child *))
john)

 >> Stay informed about: Finding Brothers & Sisters (with dbd) 
Back to top
Login to vote
neo55592

External


Since: Dec 06, 2004
Posts: 480



(Msg. 3) Posted: Sat Dec 23, 2006 11:48 am
Post subject: Re: Finding Brothers & Sisters (with dbd) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Networks are the most general form of data structures. Networks include
lists, hierarchies, tables, graphs, etc. The data in the following
example forms a type of network that is managed systematically by true
network databases but is impossible to manage systematical in RM/RMDBs
(note that one requirement for being systematic in RM/RMDBs means
complying with the Information Principle).

Suppose Adam has children named John(male), Mary(female), Bob(male) and
Francis(bisexual). And John likes Mary and Francis, but hates Bob.
Genders male/female are opposites. Feelings like/hate are opposites.

Based on the above, we want to find the following, without referring to
John's parent (Adam) or John's gender (male) directly:
1) John's siblings.
2) John's brothers.
3) John's sisters.
4) John's sibling of opposite gender.

Also we want to find:
1) with whom is John's relationship opposite that with Mary.
2) With whom is John's relationship opposite that with Bob.
3) Whom does John not have a feeling for.

Below dbd script implements the above example.

(new 'male 'gender)
(new 'female 'gender)
(new 'bisexual 'gender)

(new 'opposite)
(set male opposite female)
(set female opposite male)

(new 'adam 'person)

(new 'john 'person)
(set john gender male)

(new 'mary 'person)
(set mary gender female)

(new 'bob 'person)
(set bob gender male)

(new 'francis 'person)
(set francis gender bisexual)

(set adam child john)
(set adam child mary)
(set adam child bob)
(set adam child francis)

(new 'like 'feeling)
(new 'hate 'feeling)
(set like opposite hate)
(set hate opposite like)

(set john like mary)
(set john like francis)
(set john hate bob)


(; Get john's siblings
by getting persons
and are children of john's parent
and are not himself)
(; Gets mary, bob and francis)
(!= (and (get person instance *)
(get (get * child john) child *))
john)

(; Get john's brothers
by getting persons
whose gender is male
and are children of john's parent
and are not himself)
(; Gets bob)
(!= (and (get person instance *)
(get * gender male)
(get (get * child john) child *))
john)

(; Get john's sisters
by getting persons
whose gender is female
and are children of john's parent
and are not himself)
(; Gets mary)
(!= (and (get person instance *)
(get * gender female)
(get (get * child john) child *))
john)

(; Get john's sibling of opposite gender
by getting persons
whose gender is opposite of john's gender
and are children of john's parent)
(; Gets mary)
(and (get person instance *)
(get * gender (get (get john gender *) opposite *))
(get (get * child john) child *))

(; Get persons with whom
john's relationship is opposite that with mary)
(; Gets bob)
(get john (get (get john * mary) opposite *) *)

(; Get persons with whom
john's relationship is opposite that with bob)
(; Gets mary and francis)
(get john (get (get john * bob) opposite *) *)

(; Get persons for whom john has no feeling)
(; Gets adam)
(!= (and (get person instance *)
(not (get john (get feeling instance *) *)))
john)
 >> Stay informed about: Finding Brothers & Sisters (with dbd) 
Back to top
Login to vote
Display posts from previous:   
   Database Forums (Home) -> Object-Oriented All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]