Re: Normalizing Every Thing with XDb2

From: x <x-false_at_yahoo.com>
Date: Thu, 29 Jul 2004 09:34:46 +0300
Message-ID: <41089a7f_at_post.usenet.com>


  • Post for FREE via your newsreader at post.usenet.com ****

Wonderful ! This is how the brain works.

"Neo" <neo55592_at_hotmail.com> wrote in message news:4b45d3ad.0407281524.59c214e9_at_posting.google.com...
> > x wrote: I wonder if you can do math with those quantities.
> > For example could one ask for the total weight of all boxes.
>
> In the example below, the quantities have been classified as integers.
>
> /**************************************************
> Create two boxes with thickness, weight and cost.
> Loop thru boxes and sum their weights.
> **************************************************/
> void Example_BoxProperties()
> {
> // Create integer
> NLI_create_r(_T("*integer cls thing"));
>
> // Create quantity
> NLI_create_r(_T("*quantity cls thing"));
>
> // Create 1
> NLI_create_r(_T("*"));
> NLI_create_r(_T("* name '1'"));
> NLI_create_r(_T("* cls quantity"));
> NLI_create_r(_T("* cls integer"));
>
> // Create 10
> NLI_create_r(_T("*"));
> NLI_create_r(_T("* name '10'"));
> NLI_create_r(_T("* cls quantity"));
> NLI_create_r(_T("* cls integer"));
>
> // Create unit
> NLI_create_r(_T("*unit cls thing"));
> NLI_create_r(_T("*cm cls unit"));
> NLI_create_r(_T("*kg cls unit"));
> NLI_create_r(_T("*$ cls unit"));
>
> // Create distance
> NLI_create_r(_T("*distance cls thing"));
>
> // Create 1 cm
> NLI_create_r(_T("*"));
> NLI_create_r(_T("* cls distance"));
> NLI_create_r(_T("* quantity 1"));
> NLI_create_r(_T("* unit cm"));
>
> // Create mass
> NLI_create_r(_T("*mass cls thing"));
>
> // Create 1 kg
> NLI_create_r(_T("*"));
> NLI_create_r(_T("* cls mass"));
> NLI_create_r(_T("* quantity 1"));
> NLI_create_r(_T("* unit kg"));
>
> // Create 10 kg
> NLI_create_r(_T("*"));
> NLI_create_r(_T("* cls mass"));
> NLI_create_r(_T("* quantity 10"));
> NLI_create_r(_T("* unit kg"));
>
> // Create money
> NLI_create_r(_T("*money cls thing"));
>
> // Create 1 $
> NLI_create_r(_T("*"));
> NLI_create_r(_T("* cls money"));
> NLI_create_r(_T("* quantity 1"));
> NLI_create_r(_T("* unit $"));
>
> // Create relators
> NLI_create_r(_T("*thickness cls relator"));
> NLI_create_r(_T("*weight cls relator"));
> NLI_create_r(_T("*cost cls relator"));
>
> // Create box
> NLI_create_r(_T("*box cls thing"));
>
> // Create box1
> NLI_create_r(_T("*box1 cls box"));
> NLI_create_r(_T("box1 thickness

(distance)((quantity)1)((unit)cm)"));

> NLI_create_r(_T("box1 weight (mass)(1)(kg)"));
> NLI_create_r(_T("box1 cost (money)(1)($)"));
>
> // Create box2
> NLI_create_r(_T("*box2 cls box"));
> NLI_create_r(_T("box2 thickness
(distance)((quantity)1)((unit)cm)"));
> NLI_create_r(_T("box2 weight (mass)(10)(kg)"));
> NLI_create_r(_T("box2 cost (money)(1)($)"));
>
> // Get ptr to things created above
> // Note: one of several methods
> int* pBox = Str_getDefT(_T("box"));
> int* pQty = Str_getDefT(_T("quantity"));
> int* pWeight = Str_getDefT(_T("weight"));
> int* pInteger = Str_getDefT(_T("integer"));
>
> // Loop thru box instances
> int totalWeight = 0;
> int* pE[32];
> Expr_SVx_get_r(pBox, pReInst_g, pE);
> while (int* pBoxX = X2(pE)){
> // Get boxX's weight
> int* pWeightX = S_SVx_1st(pBoxX, pWeight);
> if (pWeightX){
> // Get weightX's qty
> int* pQtyX = S_SVx_1st(pWeightX, pQty);
> if (pQtyX){
> // If qtyX is an integer
> if (S_SVO_1st(pQtyX, pReCls_g, pInteger)){
> // Get qtyX's name as an ascii str
> TCHAR sQtyX[kStrSz_g+1] = _T("");
> T_Name_get(pQtyX, sQtyX, kStrSz_g);
>
> // Convert ascii str to integer
> int iQtyX = _ttoi(sQtyX);
>
> // Sum weight
> totalWeight = totalWeight + iQtyX;
> }
> }
> }
> }
>
> // Print total weight of boxes (prints 11)
> TRACE(_T("Total weight of boxes is: %d\n"), totalWeight);
> }

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

  • Usenet.com - The #1 Usenet Newsgroup Service on The Planet! *** http://www.usenet.com Unlimited Download - 19 Seperate Servers - 90,000 groups - Uncensored -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Received on Thu Jul 29 2004 - 08:34:46 CEST

Original text of this message