Demo: Things in Hierarchies (w/o RM/SQL)

From: Neo <neo55592_at_hotmail.com>
Date: 1 Nov 2004 20:22:21 -0800
Message-ID: <4b45d3ad.0411012022.1754aa2a_at_posting.google.com>



Below XDb2 script creates/queries things that represent john and mary in two hierarchies. In the first hierarchy, john and mary have parents adam and eve and their parent is god. In the second hierarchy, john and mary are part of mars and venus respectively, which are part of the universe.

// Create god and persons

CREATE2 *god.cls = thing;
CREATE2 *person.cls = thing;
CREATE2 *adam.cls = person;
CREATE2 *eve.cls = person;
CREATE2 *john.cls = person;
CREATE2 *mary.cls = person;

// Create god's children hierarchy

CREATE2 god.child = adam;
CREATE2 god.child = eve;
CREATE2 adam.child = john;
CREATE2 adam.child = mary;
CREATE2 eve.child = john;
CREATE2 eve.child = mary;

// Create universe and planets

CREATE2 *universe.cls = thing;
CREATE2 *planet.cls = thing;
CREATE2 *mars.cls = planet;
CREATE2 *venus.cls = planet;

// Create universe's part hierarchy

CREATE2 universe.part = mars;
CREATE2 universe.part = venus;
CREATE2 mars.part = john;
CREATE2 venus.part = mary;

// Traverse god's children recursively

SELECTR god.child;

// Traverse god's distinct children recursively
SELECTRD god.child;

// Traverse universe's parts recursively
SELECTR universe.part;

// Find persons whose parent is adam and is part of mars.
// Finds john

SELECT2 %.cls=person & %.parent=adam & mars.part=%;

// Find persons whose parent is eve and is part of a planet.
// Finds john and mary

SELECT2 %.cls=person & %.parent=eve & (planet.inst=%).part=%;
SELECT2 %.cls=person & %.parent=eve & (%.cls=planet).part=%;
SELECT2 %.cls=person & %.parent=eve & %.asm=(%.cls=planet);

// Find john and mary with various queries
SELECT2 %.cls=person & eve.child=%;
SELECT2 eve.child=% & %.cls=person;
SELECT2 %.cls=person & %.parent=eve;
SELECT2 %.parent=eve;
SELECT2 eve.child=%;

// Find persons whose parent's parent is god
// and the person is part of any planet
SELECT2 %.cls=person & %.parent=(%.parent=god) & (%.cls=planet).part=%;

Note: cls/inst are abbreviations for class/instance. asm/part are abbreviations for assembly/part. Received on Tue Nov 02 2004 - 05:22:21 CET

Original text of this message