Re: Demo: Db For Dummies

From: Neo <neo55592_at_hotmail.com>
Date: 13 Nov 2004 20:43:43 -0800
Message-ID: <4b45d3ad.0411132043.333472fc_at_posting.google.com>


> "Person with uniqie hair color? That is, a person with a hair color
> such that there doesn't exist anybody else with this color"

Above type queries can only be resolved via code/API at this time. The psuedo code below solves similar but simpler case:

// Loop thru hair instances
  while (hairX = X2(%.cls=hair)){
    // Loop thru persons whose hair property is hairX

      cntr = 0;
      while (sub = X2("%.hair=hairX & %.cls=person")){
        ++cntr;
      }

    // Print person with unique hair
      if (cntr == 1){
        print("%s's hair is uniquely %s"), sub, hairX);
      }

  }

> "Find a person with most frequent hair color"

// Loop thru hair instances
  mostCmnHair = NULL;
  mostCmnHairCntr = 0;
  while (hairX = X2("%.cls = hair")){
    // Loop thru persons whose hair property is hairX

      cntr = 0;
      while (sub = X2("%.hair = hiarX & %.cls=person")){
        ++cntr;
      }

    // Store current hair if more common than prior
      if (cntr > mostCmnHairCntr){
        mostCmnHair = hairX;
        mostCmnHairCntr = cntr;
      }

  }

// Print persons with most common hair
  while (personX = X2("%.cls=person & %.hair=mostCmnHair")){     print("%s's hair is %s"), personX, mostCmnHair);   } Received on Sun Nov 14 2004 - 05:43:43 CET

Original text of this message