Demo: Relational Expressions -
11-09-2004
, 03:16 PM
www.xdb2.com/example/ex005.asp demonstrates how to create and find
things using relational expressions. The example creates john with
black skin and red-blue hair; and mary with smooth-white skin and red,
silky-smooth hair using the script shown below. When executing a
query, the appropriate nodes are highlighted successively.
// Create person, skin, hair, color and texture classes
CREATE2 *person.cls = thing;
CREATE2 *skin.cls = thing;
CREATE2 *hair.cls = thing;
CREATE2 *color.cls = thing;
CREATE2 *texture.cls = thing;
// Create black skin
CREATE2 *;
CREATE2 it.cls = skin;
CREATE2 it.color = +black;
// Create smooth-white skin
CREATE2 *;
CREATE2 it.cls = skin;
CREATE2 it.color = +white;
CREATE2 it.texture = +smooth;
// Create red-blue hair
CREATE2 *;
CREATE2 it.cls = hair;
CREATE2 it.color = +red;
CREATE2 it.color = +blue;
// Create red, silky-smooth hair
CREATE2 *;
CREATE2 it.cls = hair;
CREATE2 it.color = +red;
CREATE2 it.texture = +silky;
CREATE2 it.texture = +smooth;
// Create a person named john
// with black skin and red-blue hair
CREATE2 *john.cls = person;
CREATE2 john.skin = (%.cls=skin & %.color=black);
CREATE2 john.hair = (%.cls=hair & %.color=red & %.color=blue);
// Create a person named mary
// with smooth-white skin and red, silky-smooth hair
CREATE2 *mary.cls = person;
CREATE2 mary.skin = (%.cls=skin & %.color=white & %.texture=smooth);
CREATE2 mary.hair = (%.cls=hair & %.color=red & %.texture=silky &
%.texture=smooth);
// Queries that find john
SELECT2 %.cls=person & %.hair=(%.color=blue);
SELECT2 %.cls=person & %.hair=(%.color=red & %.color=blue);
SELECT2 %.cls=person & %.skin=(%.color=black);
SELECT2 %.cls=person & %.skin=(%.color=black) & %.hair=(%.color=red &
%.color=blue);
// Queries that that find mary:
SELECT2 %.cls=person & %.hair=(%.texture=silky);
SELECT2 %.cls=person & %.hair=(%.color=red & %.texture=silky);
SELECT2 %.cls=person & %.skin=(%.color=white & %.texture=smooth);
SELECT2 %.cls=person & %.hair=(%.color=red & %.texture=silky &
%.texture=smooth);
// Queries that that find john and mary:
SELECT2 %.cls=person; // Any person
SELECT2 %.skin; // Any thing with skin
SELECT2 %.hair; // Any thing with hair
SELECT2 %.hair=(%.color=red); // Any thing with red hair |