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

From: Neo <neo55592_at_hotmail.com>
Date: 27 Apr 2006 22:10:24 -0700
Message-ID: <1146201024.081600.171810_at_v46g2000cwv.googlegroups.com>


> > Currently the RM schema at
> > http://www.c2.com/cgi/wiki?CourtRoomSchemaExample cannot store data to
> > represent the things in the Court Judge Example. If you believe
> > otherwise, please provide the script to populate with data and we can
> > perform some queries to verify if the RM solution is equivalent.
>
> I assume you mean something like all the different things that a Judge
> can possess. Actually a similar situation comes with fix-assets or
> inventory tracking. Remember that a warehouse can also be an "owner" of
> a thing.

No I mean the example with data that I posted in original thread titled "Data Model" on Mar 30, then reposted earlier in this segment of the thread on Apr 18. I am reposting it again below:

> Abbreviated description of problem posed by OP of thread titled "Data Model".
> There are many Judges.
> There are many Buildings.
> There are many Locations inside buildings (such as floors).
> Each judge must reside at exactly one location.
> A staff member has a name, phone number, and email.
> Each judge has [5] staff members, one of each type:
> Clerk, Assistant Clerk, Coordinator, Bailiff and Court Reporter.

The script [much later below] populates [the] exp db with the following

persons: Judge Judy (phone# 333-5555, email j..._at_aol.com & judgeJ..._at_law.com) who has following staff members: Clerk Clark (who has Assistant Ashley), Coordinator Colby, Bailiff Brandy and Court-Reporter Courtney each with various properties. Building CourtHouse1 has two floors. The first floor has room1. The second floor

has room1 and room2. Various persons are placed in different parts of CourtHouse1. The sample query (near end of script, [bottom of this post]) finds a staff member of a judge whose assistant has a certain phone#. Data can be easily navigated when viewed in a tree just by clicking nodes (even though the underlying data doesn't necessarily have a tree structure); where as in RM, it will require one to join multiple tables. If requested, I can email the populated db/exe (188 kb

zip file) so one can see for themselves. Note, it is a prototype so other features may not work. Note, I did not make bi-directional relationships (ie j..._at_aol.com emailOf judy) to keep the example simple. One effect of creating bi-directional relationships would have been to allow user to effectively "walk up" any [heirarchy] while expanding tree nodes [in down direction]. Note, script expressions become more elaborate when dealing with multiple things with the same name.

Unlike RMDBs, where one must first design a schema/structure to hold anticipated data, no schema is required before entering data in the experimental db. The reason is, it already starts with a very general schema that is capable of modelling most anything in a normalized manner. This is partially why unanticipated types of data can be added on the fly during execution without a design/compile phase. Db automatically normalizes data and maintains referential integrity. Other constraints, such as each person must have a phone number or 6 staff members, need to be implemented at code level [currently and for a while] where as RMDBs can implement such basic constriants at db level.

Because the script [much later below is foreign looking], I will [first] show how [some of] the data appears when viewed in the db's grid and tree views. The grid view below only shows instances of person. The tree view below, on the other hand, shows most of the relevant things... In essence, the tree nodes display sentences in Subject-verb-Object format. In order to describe the tree view [in Google vs the actual db exe], I have adopted some conventions. Tree nodes representing subjects and objects are capitalized where as verbs are not. [Verbs are prefixed and suffixed by a dash]. Also the object of the initial sentence becomes the subject of the subsequent sentence and so on. For example, the sentences "Building instance CourtHouse1" and "CourtHouse1 has Floor1" is displayed as the following sequence of nodes: Building, -instance-, CourtHouse1, -has-, Floor1, etc. Also a "+" symbol after a node indicates that it can be expanded to that shown

else where in the tree. [While the tree view displays thing redundantly, the underlying data is not, and one way of verifying this is by displaying each nodes ID]. Thus the user (even a child) can easily navigate to all the details of various things no matter what tree path is taken, without anybody having to join tables (and there will eventually be many). All this is much easier to see, just by clicking around in the small db/exe which fits on a floppy.

[Below is the] Grid View of Person Instances. Note, grid only shows first value of an attribute. [Switch to fixed fonts for columns to line

up]

ID name phone# email staffMember

-- --------- --------  -------------  -----------
#  judy      333-5555  j..._at_aol.com   clark
#  clark     737-5588
#  ashley    737-5588
#  colby               c..._at_msn.com

# brandy 919-9945
# courtney 203-9898 c..._at_gov.org

[Below is the] Tree View of Relevant Things: Notice that the tree can show multiple values of an attribute. Notice that a person can be located in a building, on a floor or in a room. Ask the RMDB experts how they would achieve this in a normalized, NULL-less manner.

Dir
 |-item-

    |-Building
    |  |-instance-
    |     |-CourtHouse1
    |        |-has-
    |           |-Floor1+
    |           |-Floor2+
    |           |-Courtney+
    |
    |-Floor
    |  |-instance-
    |     |-Floor1
    |     |  |-has-
    |     |     |-Room1+
    |     |     |-Ashley+
    |     |
    |     |-Floor2
    |        |-has-
    |           |-Room1+
    |           |-Room2+
    |
    |-Room
    |  |-instance-
    |     |-Room1 (of Floor1)
    |     |  |-has-
    |     |     |-Clark+
    |     |
    |     |-Room1 (of Floor2)
    |     |
    |     |-Room2 (of Floor2)
    |        |-has-
    |           |-Judy+
    |
    |-Person
    |  |-instance-
    |     |-Judy
    |     |   |-phone#-
    |     |   |  |-333-5555
    |     |   |  |-JDG-JUDY
    |     |   |
    |     |   |-email-
    |     |   |  |-J _at_aol.com
    |     |   |  |-Judy _at_law.com
    |     |   |
    |     |   |-staffMember-
    |     |      |-Clark+
    |     |      |-Ashley+
    |     |      |-Colby+
    |     |      |-Brandy+
    |     |      |-Courtney+
    |     |
    |     |-Clark
    |     |   |-phone#-
    |     |   |  |-737-5588
    |     |   |
    |     |   |-assistant-
    |     |      |-Ashley+
    |     |
    |     |-Ashley
    |     |   |-phone#-
    |     |      |-737-5588
    |     |
    |     |-Colby
    |     |   |-email-
    |     |      |-Colby _at_msn.com
    |     |
    |     |-Brandy
    |     |   |-phone#-
    |     |      |-919-9945
    |     |
    |     |-Courtney
    |         |-phone#-
    |         |  |-203-9898
    |         |
    |         |-email-
    |            |-C _at_gov.org
    |
    |-Judge
    |  |-instance-
    |     |-Judy+
    |
    |-StaffMember
    |  |-instance-
    |     |-Clark+
    |     |-Ashley+
    |     |-Colby+
    |     |-Brandy+
    |     |-Courtney+
    |
    |-Clerk
    |  |-instance-
    |     |-Clark+
    |     |-Ashley+
    |
    |-Assistant
    |  |-instance-
    |     |-Ashley+
    |
    |-Coordinator
    |  |-instance-
    |     |-Colby+
    |
    |-Bailiff
    |  |-instance-
    |     |-Brandy+
    |
    |-CourtReporter
    |  |-instance-
    |     |-Courtney+
    |
    |-Phone#
    |  |-instance-
    |     |-333-5555
    |     |-JDG-JUDY
    |     |-737-5588
    |     |-919-9945
    |     |-203-9898
    |
    |-Email
    |  |-instance-
    |     |-J _at_aol.com
    |     |-Judy _at_law.com
    |     |-Colby _at_msn.com
    |     |-C _at_gov.org
    |
    |-Type
       |-instance-
          |-Name
          |  |-instance-
          |    |-Building
          |    |-Floor
          |    |-Room
          |    |-Person
          |    |-Judge
          |    |-StaffMember
          |    |-Clerk
          |    |-Assistant
          |    |-Coordinator
          |    |-Bailiff
          |    |-CourtReporter
          |    |-Phone#
          |    |-Email
          |    |-Has
          |    |-Judy
          |    |-333-5555
          |    |-JDG-JUDY
          |    |-J _at_aol.com
          |    |-Judy _at_law.com
          |    |-Clark
          |    |-737-5588
          |    |-Ashley
          |    |-Colby
          |    |-Colby _at_msn.com
          |    |-Brandy
          |    |-919-9945
          |    |-Courtney
          |    |-203-9898
          |    |-C _at_gov.org
          |    |-CourtHouse1
          |    |-Floor1
          |    |-Room1
          |    |-Floor2
          |    |-Room2
          |
          |-Verb
          |  |-instance-
          |     |-Has
          |
          |-Etc...


// **** START OF LISP-LIKE SCRIPT TO CREATE DB **** // Create a type named building.

(create type instance (new))
(create (it) name (findElseAdd name instance 'building'))
(create dir item (it))

// Create a type named floor.

(create type instance (new))
(create (it) name (findElseAdd name instance 'floor'))
(create dir item (it))

// Create a type named room.

(create type instance (new))
(create (it) name (findElseAdd name instance 'room'))
(create dir item (it))

// Create a type named person.

(create type instance (new))
(create (it) name (findElseAdd name instance 'person'))
(create dir item (it))

// Create a type named judge.

(create type instance (new))
(create (it) name (findElseAdd name instance 'judge'))
(create dir item (it))

// Create a type named staffMember.

(create type instance (new))
(create (it) name (findElseAdd name instance 'staffMember'))
(create dir item (it))

// Create a type named clerk.

(create type instance (new))
(create (it) name (findElseAdd name instance 'clerk'))
(create dir item (it))

// Create a type named assistant.

(create type instance (new))
(create (it) name (findElseAdd name instance 'assistant'))
(create dir item (it))

// Create a type named coordinator.

(create type instance (new))
(create (it) name (findElseAdd name instance 'coordinator'))
(create dir item (it))

// Create a type named bailiff.

(create type instance (new))
(create (it) name (findElseAdd name instance 'bailiff'))
(create dir item (it))

// Create a type named courtReporter.

(create type instance (new))
(create (it) name (findElseAdd name instance 'courtReporter'))
(create dir item (it))

// Create a type named phone#.

(create type instance (new))
(create (it) name (findElseAdd name instance 'phone#'))
(create dir item (it))

// Create a type named email.

(create type instance (new))
(create (it) name (findElseAdd name instance 'email'))
(create dir item (it))

// Create a verb instance named has.
(create verb instance (new))
(create (it) name (findElseAdd name instance 'has'))

// Create a person/judge named Judy.

(create person instance (new))
(create judge instance (it))
(create (it) name (findElseAdd name instance 'judy'))
(create (it) phone# (findElseAdd phone# instance '333-5555'))
(create (it) phone# (findElseAdd phone# instance 'JDG-JUDY'))
(create (it) email (findElseAdd email instance '..._at_aol.com'))
(create (it) email (findElseAdd email instance '..._at_law.com'))

// Create a person/staffMember/clerk named Clark.

(create person instance (new))
(create staffMember instance (it))
(create clerk instance (it))
(create (it) name (findElseAdd name instance 'clark'))
(create (it) phone# (findElseAdd phone# instance '737-5588'))

// Create a person/staffMember/clerk/assistant named Ashley.

(create person instance (new))
(create staffMember instance (it))
(create clerk instance (it))
(create assistant instance (it))
(create (it) name (findElseAdd name instance 'ashley'))
(create (it) phone# (findElseAdd phone# instance '737-5588'))

// Create a person/staffMember/coordinator named Colby.

(create person instance (new))
(create staffMember instance (it))
(create coordinator instance (it))
(create (it) name (findElseAdd name instance 'colby'))
(create (it) email (findElseAdd email instance 'co..._at_msn.com'))

// Create a person/staffMember/bailiff named Brandy.

(create person instance (new))
(create staffMember instance (it))
(create bailiff instance (it))
(create (it) name (findElseAdd name instance 'brandy'))
(create (it) phone# (findElseAdd phone# instance '919-9945'))

// Create a person/staffMember/courtReporter named Courtney.

(create person instance (new))
(create staffMember instance (it))
(create courtReporter instance (it))
(create (it) name (findElseAdd name instance 'courtney'))
(create (it) phone# (findElseAdd phone# instance '203-9898'))
(create (it) email (findElseAdd email instance '..._at_gov.org'))

// Create judge judy's staffMembers.

(create judy staffMember clark)
(create judy staffMember ashley)
(create judy staffMember colby)
(create judy staffMember brandy)
(create judy staffMember courtney)

// Create Clark's assistant Ashley
(create clark assistant ashley)

// Create a building instance named CourtHouse1. (create building instance (new))
(create (it) name (findElseAdd name instance 'courtHouse1'))

// Create a floor instance named floor1
// and make it part of courtHouse1.

(create floor instance (new))
(create (it) name (findElseAdd name instance 'floor1'))
(create courtHouse1 has (it))

// Create room instances named room1
// and make it part of floor1.

(create room instance (new))
(create (it) name (findElseAdd name instance 'room1'))
(create floor1 has (it))

// Create a floor instance named floor2. // and make it part of courtHouse1.

(create floor instance (new))
(create (it) name (findElseAdd name instance 'floor2'))
(create courtHouse1 has (it))

// Create room instances named room1
// and make it part of floor2.

(create room instance (new))
(create (it) name (findElseAdd name instance 'room1'))
(create floor2 has (it))

// Create room instances named room2
// and make it part of floor2.

(create room instance (new))
(create (it) name (findElseAdd name instance 'room2'))
(create floor2 has (it))

// Create CourtHouse1's has reporter Courtney. (create courtHouse1 has courtney)

// Create CourtHouse1's floor1's has Ashley. (create (relElem (select courtHouse1 has floor1))

        has
        ashley)

// Create CourtHouse1's floor1's room1 has Clark. (create (relElem (select (relElem (select courtHouse1 has floor1))

                       has
                       room1))
        has
        clark)

// Create CourtHouse1's floor2's room2's has Judge Judy. (create (relElem (select (relElem (select courtHouse1 has floor2))

                       has
                       room2))
        has
        judy)

// Find a staff member of a judge

// whose assistant has phone# 737-5588.
// Displays clerk Clark.
(msgbox (and (select (select judge instance *) staffMember *)

             (select * assistant (select * phone# 737-5588)))) Received on Fri Apr 28 2006 - 07:10:24 CEST

Original text of this message