Re: Storing data and code in a Db with LISP-like interface

From: Neo <neo55592_at_hotmail.com>
Date: 26 Apr 2006 20:19:41 -0700
Message-ID: <1146107981.719540.254830_at_g10g2000cwb.googlegroups.com>


> Don't say flexible data, 'cause that's machine code.

And I didn't :) Having a data model that provides a systematic/general/flexible method of representing things is different than the flexibililty afforded by machine code. If anyone would like to represent the data in the next Food Judge Example with machine code, I will take a serious look at it.

> but I'm nervous about [dbd's] applicability to these groups.

Representing things is the foundation for all computing including RMDBs, LISP, Prolog and OOP. Any limitations at this foundation eventually limits the full potential of tools built on top of it. One cannot faithfully process that which it can't represent.

> Perhaps I'm one still plugged into the Matrix, > Neo show me the truth what exactly are you trying to solve?

To find the most general/flexible/systematic method of representing things. Since you (and LISP users) have experienced freedom that is difficult to achieve via RM or OOP, you are already nearly out of the Matrix :)

> I'm not saying go away, the world is not mine to dictate > but can you give us some OO connection to work with?

The OO connection comes later which is to a great extent dependent on processing of data. Currently I am not focused on data processing. I want to first make sure I have the flexibility to represent anything in a systematic manner.

> YES Prolog can do pretty well everything you've asked of it > but we're only repeating ourselves now.

While there were a few minor issues, overall Prolog was able to represent most things in the dbd's Food Judge Example B. So now we extend to Example C.

// Food Judge Example C

// Similar to Judge Example B with following extenstions:
// 1) Makes verbs like and likedBy reciprocals.
// 2) Adds various textures and flavors to the entries.
// 3) Adds johnathan as a second name for judge john.
// 4) Adds contestant named john (aka johnny) who likes various
entries.
// 5) Adds spectator without a name who is age 28 and likes various entries.
// 6) Adds judge john likes contestant john.
// 7) Adds a few more queries.
// Notes for Example B:
// Function createWRR creates specified and reciprocal relationship.
// Function verifyRel verifies transitive relationships.

// Create a thing named person.
(createWRR thing instance (new))
(createWRR (it) name (findElseAdd word instance 'person'))

// Create a thing named judge.
(createWRR thing instance (new))
(createWRR (it) name (findElseAdd word instance 'judge'))

// Create a person/judge named john/johnathan.
(createWRR person instance (new))
(createWRR judge instance (it))
(createWRR (it) name (findElseAdd word instance 'john'))
(createWRR (it) name (findElseAdd word instance 'johnathan'))

// Create a thing named contestant.
(createWRR thing instance (new))
(createWRR (it) name (findElseAdd word instance 'contestant'))

// Create a person/contestant named john/johnny.
(createWRR person instance (new))
(createWRR contestant instance (it))
(createWRR (it) name (findElseAdd word instance 'john'))
(createWRR (it) name (findElseAdd word instance 'johnny'))

// Create a thing named spectator.
(createWRR thing instance (new))
(createWRR (it) name (findElseAdd word instance 'spectator'))

// Create a thing named age.
(createWRR thing instance (new))
(createWRR (it) name (findElseAdd word instance 'age'))

// Create a person/spectator without a name who is age 28.
(createWRR person instance (new))
(createWRR spectator instance (it))
(createWRR (it) age (findElseAdd age instance '28'))

// Create a verb named like.
(createWRR verb instance (new))
(createWRR (it) name (findElseAdd word instance 'like'))

// Create a verb named likedBy.
(createWRR verb instance (new))
(createWRR (it) name (findElseAdd word instance 'likedBy'))

// Relate verbs like and likedBy as reciprocals.
// This data allows createWRR to create the reciprocal
// relationships when either verb is specified.

(create like reciprocal likedBy)
(create likedBy reciprocal like)

// Create a thing named texture
(createWRR thing instance (new))
(createWRR (it) name (findElseAdd word instance 'texture'))

// Create textures: soft and crunchy.
(createWRR texture instance (new))
(createWRR (it) name (findElseAdd word instance 'soft'))
(createWRR texture instance (new))
(createWRR (it) name (findElseAdd word instance 'crunchy'))

// Create a thing named flavor.
(createWRR thing instance (new))
(createWRR (it) name (findElseAdd word instance 'flavor'))

// Create flavors: sweet, sour and spicy.
(createWRR flavor instance (new))
(createWRR (it) name (findElseAdd word instance 'sweet'))
(createWRR flavor instance (new))
(createWRR (it) name (findElseAdd word instance 'sour'))
(createWRR flavor instance (new))
(createWRR (it) name (findElseAdd word instance 'spicy'))

// Create a thing named entry (as in food entry).
(createWRR thing instance (new))
(createWRR (it) name (findElseAdd word instance 'entry'))

// Create an entry named leftOver1 that is soft and spicy.
(createWRR entry instance (new))
(createWRR (it) name (findElseAdd word instance 'leftOver1'))
(createWRR (it) texture soft)
(createWRR (it) flavor spicy)

// Create a thing named fruit.
(createWRR thing instance (new))
(createWRR (it) name (findElseAdd word instance 'fruit'))

// Create a fruit/entry named apple1 that is crunchy and sweet.
(createWRR fruit instance (new))
(createWRR entry instance (it))
(createWRR (it) name (findElseAdd word instance 'apple1'))
(createWRR (it) texture crunchy)
(createWRR (it) flavor sweet)

// Create a thing named vegetable.
(createWRR thing instance (new))
(createWRR (it) name (findElseAdd word instance 'vegetable'))

// Create a vegetable/entry named broccoli1 that is crunchy.
(createWRR vegetable instance (new))
(createWRR entry instance (it))
(createWRR (it) name (findElseAdd word instance 'broccoli1'))
(createWRR (it) texture crunchy)

// Create a fruit/vegetable/entry named tomato1 that is soft and sweet/sour.
(createWRR fruit instance (new))
(createWRR vegetable instance (it))
(createWRR entry instance (it))
(createWRR (it) name (findElseAdd word instance 'tomato1'))
(createWRR (it) texture soft)
(createWRR (it) flavor sweet)
(createWRR (it) flavor sour)

// Create judge john (aka johnathan)
// likes leftOver1 and tomato1.
(createWRR johnathan like leftOver1)

or
(createWRR (and (select judge instance *)

                          (select * name (word1st 'john'))
                   )
                   like
                   tomato1)


// Create contestant john (aka johnny)
// likes apple1 and tomato1.
(createWRR johnny like apple1)
(createWRR johnny like tomato1)

// Create unnamed spectator likes broccoli1 and tomato1.
(createWRR (and (select spectator instance *)

                          (select * age 28))
                   like
                   broccoli1)

(createWRR (and (select spectator instance *)
(select * age 28)) like tomato1)

// Create judge john likes contestant john. // Several methods shown.
(createWRR johnathan like johnny)

or
(createWRR johnny likedBy johnathan)

or
(createWRR johnathan

                  like
                  (and (select judge instance *)
                         (select * name (word1st 'john'))))


// What entries does judge john (aka johnathan) like?
// Either of the below expressions

// displays leftOver1 and tomato1
// in 2 consecutive dialog boxes.
(msgbox (and (select johnathan like *)
                     (select entry instance *)))

// Which fruit entries does contestant john (aka johnny) like? // Displays apple1 and tomato1.
(msgbox (and (select johnny like *)

                     (select fruit instance *)))

// Which vegetable entries does spectator (of age 28) like? // Displays broccoli1 and tomato1.
(msgbox (and (select (and (select spectator instance *)

                                       (select * age 28))
                                like
                                *)
                     (select vegetable instance *)))

// Find which fruit/vegetable entries does johnathan likes.
// What does johnathan like which is a fruit and also a vegetable. // Displays tomato1.
(msgbox (and (select johnathan like *)
                     (select fruit instance *)
                     (select vegetable instance *)))


// Find things tomato1 is liked by.
// Displays john/johnathan, john/johnny and person/spectator/28.
(msgbox (select tomato1 likedBy *))

// Find persons who likes cruchy vegetables.
// Note spectator like broccoli which is crunchy.
// Displays person/spectator/28

(msgbox

   (and (select person instance *)

          (select * like (and (select vegetable instance *)
                                    (select * texture crunchy)))))


// Which person likes something that is both a fruit and vegetable? // Displays john/johnathan, john/johnny and person/spectator/28.
(msgbox

   (and (select person instance *)

        (select * like (and (select vegetable instance *)
                            (select fruit instance *)))))

// Which entry do judges, contestants and spectators like? // Displays tomato1.
(msgbox (and (select entry instance *)

                     (select (select judge instance *) like *)
                     (select (select contestant instance *) like *)
                     (select (select spectator instance *) like *)))

// Which person likes another person who likes a fruit/vegetable entry?
// Note that johnathan likes johnny who likes tomato1. // Displays john/johnnathan.
(msgbox

   (and

      (select person instance *)
      (select *
                 like
                 (and (select person instance *)
                        (select *
                                   like
                                   (and (select vegetable instance *)
                                      (select fruit instance *)))))))

// Which person likes something which likes something that is soft, sweet/sour?
// Note that johnathan likes johnny who likes tomato1 which is soft. // Displays john/johnnathan.
(msgbox

   (and (select person instance *)

          (select *
                     like
                     (select *
                                like
                                (and (select * texture soft)
                                       (select * flavor sweet)
                                       (select * flavor sour))))))


// Verify Transitive Relationships:

// Is person is a thing?
// Displays true.
(msgbox (verifyRel person class thing))

// Is vegetable is a thing?
// Displays true.
(msgbox (verifyRel vegetable class thing))

// Is tomato1 is a vegetable?
// Displays true.
(msgbox (verifyRel tomato1 class vegetable))

// Is tomato1 is a fruit?
// Displays true.
(msgbox (verifyRel tomato1 class fruit))

// Is tomato1 is a thing?
// Displays true.
(msgbox (verifyRel tomato1 class thing))

// Is tomato1 is a person?
// Displays false.
(msgbox (verifyRel tomato1 class person))

// Is judge is an instance of thing?
// Displays true.
(msgbox (verifyRel thing instance judge))

// Is fruit is an instance of thing?
// Displays true.
(msgbox (verifyRel thing instance fruit))

// Is tomato1 is an instance of vegetable? // Displays true.
(msgbox (verifyRel vegetable instance tomato1))

// Is tomato1 is an instance of fruit?
// Displays true.
(msgbox (verifyRel fruit instance tomato1))

// Is tomato1 is an instance of thing?
// Displays true.
(msgbox (verifyRel thing instance tomato1))

// Is tomato1 is an instance of person?
// Displays false.
(msgbox (verifyRel person instance tomato1))

All these things/relationships are much easier to see, comprehend as a whole and navigate when viewed in dbd's tree view. Received on Thu Apr 27 2006 - 05:19:41 CEST

Original text of this message