Re: Nested Relations / RVAs / NFNF
Date: 31 Oct 2004 20:11:47 -0800
Message-ID: <4b45d3ad.0410312011.312f0b51_at_posting.google.com>
> how would you represent "two kilograms" in a program?
Below code is equivalent to the script listed earlier. The 2Kg is created by calling XDb2's API. The actual 2Kg exists in the db not in the program. General steps are similar for any other thing.
void main()
{
// Create unit
// Equivalent to NLI_create2("*unit.cls=thing");
pUnit = T_create(); T_Name_relate(pUnit, "unit"); T_relate(pUnit, pCls, pThing);
// Create unit > kg
// Equivalent to NLI_create2("*kg.cls=unit");
pKg = T_create(); T_Name_relate(pKg, "kg"); T_relate(pKg, pCls, pUnit);
// Create qty
// Equivalent to NLI_create2("*qty.cls=thing");
pQty = T_create(); T_Name_relate(pQty , "qty"); T_relate(pQty , pCls, pThing);
// Create qty > 2
// Equivalent to NLI_create2("*2.cls=qty");
p2 = T_create(); T_Name_relate(p2, "2"); T_relate(p2, pCls, pQty);
// Create mass
// Equivalent to NLI_create2("*mass.cls=thing");
pMass = T_create(); T_Name_relate(pMass, "mass"); T_relate(pMass, pCls, pThing);
// Create mass > 2Kg
// Equivalent to NLI_create2("*");
// NLI_create2("it.cls=mass");
// NLI_create2("it.qty=2");
// NLI_create2("it.unit=kg");
p2Kg = T_create(); T_relate(p2Kg, pCls, pMass); T_relate(p2Kg, pQty, p2); T_relate(p2Kg, pUnit, pKg);
// Assume, program restarts
// Find 2Kg in db
pQuery = NLI_select2("%.cls=mass & %.qty=2 & %.unit=kg); p2Kg = X2(pQuery);
// Use code similar to above section to get pCls, pQty, pUnit
// Get p2Kg's class
p2Kg_cls = S_SV_getO(p2Kg, pCls);
// Get p2Kg's qty
p2Kg_qty = S_SV_getO(p2Kg, pQty);
// Get p2Kg's unit
p2Kg_unit = S_SV_getO(p2Kg, pUnit);
// Print "mass 2 kg"
sCls = T_Name_get(p2Kg_cls); sQty = T_Name_get(p2Kg_qty); sUnit = T_Name_get(p2Kg_unit); printf("%s %s %s", sCls, sQty, sUnit);
// Also prints "mass 2 kg" which is auto-generated
s2Kg = T_Name_get(p2kg); printf("%s", s2Kg);
// p2Kg is a ptr/handle to a thing in db which represents 2kg
// And yes, things are normalized within db,
// including the symbol 't' in "unit" and "qty"
}
Received on Mon Nov 01 2004 - 05:11:47 CET