dbTalk Databases Forums  

Finding Brothers & Sisters (with dbd)

comp.databases.object comp.databases.object


Discuss Finding Brothers & Sisters (with dbd) in the comp.databases.object forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Neo
 
Posts: n/a

Default Finding Brothers & Sisters (with dbd) - 12-04-2006 , 11:14 AM






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


Reply With Quote
  #2  
Old   
Neo
 
Posts: n/a

Default Re: Finding Brothers & Sisters (with dbd) - 12-22-2006 , 11:09 AM






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)


Reply With Quote
  #3  
Old   
Neo
 
Posts: n/a

Default Re: Finding Brothers & Sisters (with dbd) - 12-23-2006 , 01:48 PM



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)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.