Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Transitive Closure with XDb1

 
   Database Help (Home) -> Object-Oriented RSS
Next:  how can foxpro2.6 application be changed into vis..  
Author Message
Neo

External


Since: Nov 30, 2003
Posts: 45



(Msg. 1) Posted: Tue May 11, 2004 3:18 pm
Post subject: Transitive Closure with XDb1
Archived from groups: comp>databases>object, others (more info?)

This code demos transitive closure in XDb1
by creating the following simple hierarchy and looping thru it:

Mars is part of Universe.
John is part of Mars.
Venus is part of Universe.
Mary is part of Venus.

The code also loops thru persons, planets
and moves John to Venus and Mary to Mars.

void Example003()
{
// Create universe and classify as a thing
int* pUniverse = T_create();
T_relate(&pUniverse, rCls, &pThing_g);
T_Name_relate(&pUniverse, _T("universe"));

// Create planet and classify as a thing
int* pPlanet = T_create();
T_relate(&pPlanet, rCls, &pThing_g);
T_Name_relate(&pPlanet, _T("planet"));

// Create mars and classify as a planet
int* pMars = T_create();
T_relate(&pMars, rCls, &pThing_g);
T_Name_relate(&pMars, _T("mars"));

// Create venus and classify as a planet
int* pVenus = T_create();
T_relate(&pVenus, rCls, &pThing_g);
T_Name_relate(&pVenus, _T("venus"));

// Create person and classify as a thing
int* pPerson = T_create();
T_relate(&pPerson, rCls, &pThing_g);
T_Name_relate(&pPerson, _T("person"));

// Create john and classify as a person
int* pJohn = T_create();
T_relate(&pJohn, rCls, &pPerson);
T_Name_relate(&pJohn, _T("john"));

// Create mary and classify as a person
int* pMary = T_create();
T_relate(&pMary, rCls, &pPerson);
T_Name_relate(&pMary, _T("mary"));

// Create universe hierarchy
// Note: rPart/rAsm are reciprocal relators
T_relate(&pMars, rAsm, &pUniverse); // or (&pUniverse, rPart, &pMars)
T_relate(&pVenus, rAsm, &pUniverse); // or (&pUniverse, rPart, &pVenus)
T_relate(&pJohn, rAsm, &pMars); // or (&pMars, rPart, &pJohn)
T_relate(&pMary, rAsm, &pVenus); // or (&pVenus, rPart, &pMary)

// Demo transitive closure by
// looping thru parts of universe
// Prints: mars, john, venus, mary
#define maxTreeDepth 64
int* pDescX_a[maxTreeDepth] = {T_R_PriRecip(pUniverse), NULL};
while (int i=T_Relative(pDescX_a, maxTreeDepth, rPart, TRUE)){
// Print name of thing
TCHAR sName[kNmSz_g+1] = _T("");
int* pT = R_Dest(pDescX_a[i]);
T_Name_get(pT, sName, kNmSz_g);
TRACE(_T("%s\n"), sName);
}

// Print names of persons: john and mary
// Loop thru person's relations
int* pR = pPerson;
while (*(++pR)){
// If relation is to an instance
if (rInst == R_Type_get(pR)){
// Print name of instance
TCHAR sName[kNmSz_g+1] = _T("");
int* pInst = R_Dest(pR);
T_Name_get(pInst, sName, kNmSz_g);
TRACE(_T("%s\n"), sName);
}
}

// Print names of planets: mars and venu
// Loop thru planet's relations
pR = pPlanet;
while (*(++pR)){
// If relation is to an instance
if (rInst == R_Type_get(pR)){
// Print name of instance
TCHAR sName[kNmSz_g+1] = _T("");
int* pInst = R_Dest(pR);
T_Name_get(pInst, sName, kNmSz_g);
TRACE(_T("%s\n"), sName);
}
}

// Move john from mars to venus
// Get mar's relation to john
pR = T_R_For(pMars, pJohn);

// Move relation to venus
R_move(pR, &pVenus);


// Move mary from venus to mars
// Get venus's relation to mary
pR = T_R_For(pVenus, pMary);

// Move relation to mars
R_move(pR, &pMars);
}

For more info, see www.xdb1.com/Example/Ex003.asp

 >> Stay informed about: Transitive Closure with XDb1 
Back to top
Login to vote
Neo

External


Since: Nov 30, 2003
Posts: 45



(Msg. 2) Posted: Wed May 12, 2004 12:26 am
Post subject: Re: Transitive Closure with XDb1 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

 > Leandro said: You are 30 years late. Relational is declarative.

XDb1's interface allows data to be entered via three methods: API, GUI
and "Natural Language Interface" (NLI). The below statements enter the
equivalent data "declaratively":

------------------------
person isA thing.
john isA person.
mary isA person.

planet isA thing.
mars isA planet.
venus isA planet.

universe isa thing.

mars isPartOf universe.
john isPartOf mars.

venus isPartOf universe.
mary isPartOf venus.
------------------------

Could you show RDM's "declarative" equivalent?
Could you show RDM's transitive closure equivalent?<!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: Transitive Closure with XDb1 
Back to top
Login to vote
Neo

External


Since: Nov 30, 2003
Posts: 45



(Msg. 3) Posted: Wed May 12, 2004 4:22 pm
Post subject: Re: Transitive Closure with XDb1 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

  > > [person isA thing. john isA person. mary isA person. planet isA thing.
  > > mars isA planet. venus isA planet. universe isa thing. mars isPartOf
  > > universe. john isPartOf mars. venus isPartOf universe. mary isPartOf venus.]
  > > Could you show RDM's "declarative" equivalent?

 > Paul said:
 > create table Contains (whole char, part char)
 > insert into Contains values ('mars', 'john')
 > insert into Contains values ('venus', 'mary')
 > insert into Contains values ('universe', 'mars')
 > insert into Contains values ('universe', 'venus')

The above is partially equivalent. First, XDb1's declarations result
in a normalized schema/structure thus there is only one Mars which
participates in a variable number of relationships. In the above RDM
declarations, each person and planet is redundant/unnormalized.
Changing the spelling of either Mars results in data corruption.
Second, John and Mary need to be "classified" by inserting in
T_Person. Mars and Venus need to "classified" by inserting into
T_Planet. Then the keys of planets and persons need to related to
records in T_Contains. Leandro could you show RDM's declarative
equivalent?<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Transitive Closure with XDb1 
Back to top
Login to vote
Neo

External


Since: Nov 30, 2003
Posts: 45



(Msg. 4) Posted: Wed May 12, 2004 8:59 pm
Post subject: Re: Transitive Closure with XDb1 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

  > > Could you show RDM's transitive closure equivalent?
 >
 > Paul said: But we can extend our DBMS by explicity including a "TClose"
 > operator that takes a (two-columned) relation as its argument and returns
 > a relation that is the transitive closure. Then TClose(Contains) is:
 >
 > whole part
 > ===== ====
 > universe john
 > universe mary
 > universe mars
 > universe venus
 > mars john
 > venus mary

Technically, the above output using TClose(Contains) is incorrect. The
parts of universe should be mars, venus, john and mary. No output row
represents a person or a planet. It instead lists relationships
between universe and john, universe and mary, etc.

In addition, using the more appropriate schema T_Contains, T_Planet
and T_Person, how does one use TClose()? XDb1's T_Relative() works for
hierarchies consisting of different kinds of things (ie Planet,
Country, State, City, House, Person, including those added at
run-time). In addition, how does one use TClose() to get parts of
mars, since mars is not a table but a row? XDb1's T_Relative() returns
parts of mars.<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Transitive Closure with XDb1 
Back to top
Login to vote
Neo

External


Since: Nov 30, 2003
Posts: 45



(Msg. 5) Posted: Thu May 13, 2004 11:42 am
Post subject: Re: Transitive Closure with XDb1 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

   > > > Leandro said: You are 30 years late. Relational is declarative.
  > >
  > > Neo said: Could you show RDM's transitive closure equivalent?
 >
 > Paul said: Now the standard relation model can't do transitive closure
 > because it requires more than first order logic.

Leandro the above can't be correct, can it?<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Transitive Closure with XDb1 
Back to top
Login to vote
Neo

External


Since: Nov 30, 2003
Posts: 45



(Msg. 6) Posted: Thu May 13, 2004 2:34 pm
Post subject: Re: Transitive Closure with XDb1 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

 > Leandro said: You are 30 years late. Relational is declarative.

Below shows how to create the simple hierarchy "declaratively" via
XDb1's API and loop thru parts of universe.

void Example003()
{
// Vars set by S_process_r
int* pR_r = NULL; // Relation created
const kMsgSz = 1023; // Error message size
TCHAR msg_r[kMsgSz+1] = _T(""); // Error message

// Create universe
S_process_r(_T("universe isa thing"), NULL, msg_r, kMsgSz, &pR_r);

// Create planets
S_process_r(_T("planet isa thing"), NULL, msg_r, kMsgSz, &pR_r);
S_process_r(_T("mars isa planet"), NULL, msg_r, kMsgSz, &pR_r);
S_process_r(_T("venus isa planet"), NULL, msg_r, kMsgSz, &pR_r);

// Create persons
S_process_r(_T("person isa thing"), NULL, msg_r, kMsgSz, &pR_r);
S_process_r(_T("john isa person"), NULL, msg_r, kMsgSz, &pR_r);
S_process_r(_T("mary isa person"), NULL, msg_r, kMsgSz, &pR_r);

// Create hierarchy
S_process_r(_T("mars isPartOf universe"), NULL,msg_r,kMsgSz,&pR_r);
S_process_r(_T("venus isPartOf universe"),NULL,msg_r,kMsgSz,&pR_r);
S_process_r(_T("john isPartOf mars"), NULL, msg_r, kMsgSz, &pR_r);
S_process_r(_T("mary isPartOf venus"), NULL, msg_r, kMsgSz, &pR_r);

// Get ptr to universe
// Note: one of several methods
int* pUniverse = R_Dest(Str_getDefT(_T("universe")));

// Looping thru parts of universe
// Prints: mars, john, venus, mary
#define maxTreeDepth 64
int* pDescX_a[maxTreeDepth] = {T_R_PriRecip(pUniverse), NULL};
while (int i=T_Relative(pDescX_a, maxTreeDepth, rPart, TRUE)){
TCHAR sName[kNmSz_g+1] = _T("");
int* pT = R_Dest(pDescX_a[i]);
T_Name_get(pT, sName, kNmSz_g);
TRACE(_T("%s\n"), sName);
}
}<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Transitive Closure with XDb1 
Back to top
Login to vote
Neo

External


Since: Nov 30, 2003
Posts: 45



(Msg. 7) Posted: Fri May 14, 2004 3:41 pm
Post subject: Re: Transitive Closure with XDb1 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

 > Paul wrote: "...the transitive closure of a binary relation R on a set X is
 > the smallest transitive relation on X that contains R."

After reading several web pages on transitive closure, I am realizing
that your definition and output are correct and what I was
demonstrating is related but different and I am unaware of a name for
it. I was demonstrating XDb1's ability to retrieve things in a
hierarchy [given a thing in the hierarchy and a relator [ie
isPartOf, isParentOf, isBossOf, etc)], where things in the hierarchy
can be of different type.

When applied to a simple case, man's supposed family tree, RDM's TClose(Tbl_Child)
returns:
god adam
god eve
god john
adam john
eve john

where as XDb1's T_Relative(god, isChildOf) returns:
adam
eve
john<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Transitive Closure with XDb1 
Back to top
Login to vote
Neo

External


Since: Nov 30, 2003
Posts: 45



(Msg. 8) Posted: Fri May 14, 2004 5:22 pm
Post subject: Re: Transitive Closure with XDb1 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

  > > In addition, using the more appropriate schema T_Contains, T_Planet
  > > and T_Person, how does one use TClose()? XDb1's T_Relative() works for
  > > hierarchies consisting of different kinds of things...

 > Paul wrote: I'm not sure what you mean by this schema
 > - could you expand on it?

I assume universe, planets and persons are different types thus
require different tables to "classify" them and minimize NULLs since
each type will have different attributes. Thus an "ideal" RDM
representation might be:

T_Universe
GUID Name Age ...
---- -------- --------
1 Universe Infinite

T_Planet
GUID Name Mass ...
---- ----- ------
2 Mars 100 GKg
3 Venus 10 GKg

T_Person
GUID Name Favorite Color ...
---- ------ --------------
4 John Red
5 Mary Blue

T_Contains
Whole Part
---------- -------
->Universe ->Mars (->XYZ represents appropriate GUID)
->Universe ->Venus
->Mars ->John
->Venus ->Mary

The problem with the above is the impracticality (but not
impossiblity) of resolving GUIDs in T_Contains. (I am sure there are
other, less than ideal solutions)

 > Paul wrote: By definition, transitive closure is only for hierarchies
 > of the same type of thing.

Since XDb1 uses a different data model and different set of
definitions, it is not limited to same type of things in an hierarchy.<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Transitive Closure with XDb1 
Back to top
Login to vote
Hugo Kornelis

External


Since: May 14, 2004
Posts: 243



(Msg. 9) Posted: Sat May 15, 2004 2:51 am
Post subject: Re: Transitive Closure with XDb1 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 14 May 2004 12:41:20 -0700, Neo wrote:

  >> Paul wrote: "...the transitive closure of a binary relation R on a set X is
  >> the smallest transitive relation on X that contains R."
 >
 >After reading several web pages on transitive closure, I am realizing
 >that your definition and output are correct and what I was
 >demonstrating is related but different and I am unaware of a name for
 >it. I was demonstrating XDb1's ability to retrieve things in a
 >hierarchy [given a thing in the hierarchy and a relator [ie
 >isPartOf, isParentOf, isBossOf, etc)], where things in the hierarchy
 >can be of different type.
 >
 >When applied to a simple case, man's supposed family tree, RDM's TClose(Tbl_Child)
 >returns:
 > god adam
 > god eve
 > god john
 > adam john
 > eve john
 >
 >where as XDb1's T_Relative(god, isChildOf) returns:
 > adam
 > eve
 > john

Hi Neo,

And the latter is exactly what would returned if you qualified RDM's
TClose(Tbl_Child) with WHERE whole = 'god'.

I suppose XDb1 also has some way to show the equialent of the RDM's TClose
with no where clause (as shown above) and a way to get all parents from
the same data, like the RDM's TClose(Tbl_Child) WHERE part = 'john', that
would return
god john
adam john
eve john

Groetjes, Hugo
--

Sorry, vandaag geen grappige sig lines meer.<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Transitive Closure with XDb1 
Back to top
Login to vote
Neo

External


Since: Nov 30, 2003
Posts: 45



(Msg. 10) Posted: Sat May 15, 2004 2:51 am
Post subject: Re: Transitive Closure with XDb1 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

  > > RDM's TClose(Tbl_Child) returns:
  > > god adam
  > > god eve
  > > god john
  > > adam john
  > > eve john
  > >
  > > where as XDb1's T_Relative(god, rChild) returns:
  > > adam
  > > eve
  > > john
 >
 > And the latter is exactly what would returned if you qualified RDM's
 > TClose(Tbl_Child) with WHERE whole = 'god'.

Yes, I see the relationship between the two more clearly now.

 > I suppose XDb1 also has some way to show the equialent of the RDM's TClose
 > with no where clause (as shown above).

Not directly, but it could be derived as T_Relative() also returns the
path to the current result encoded in an array. Thus when it returns
john, the array would be [god, adam, john]. If the function's distinct
flag is disabled, it would return john a second time and the array
would be [god, eve, john].

 > ... and a way to get all parents from the same data,
 > like the RDM's TClose(Tbl_Child) WHERE part = 'john'

Yes, T_Relative(john, rParent) would return: adam, eve, god.<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Transitive Closure with XDb1 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> Object-Oriented All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]