Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Re: How to model searchable properties of an entity

Re: How to model searchable properties of an entity

From: Neo <neo55592_at_hotmail.com>
Date: 30 Aug 2004 10:00:28 -0700
Message-ID: <4b45d3ad.0408300900.4ab3ba53@posting.google.com>


> There are two simple solutions; nulls and sub-entities.  

This XDb2 example (www.xdb2.com/Example/Ex109.asp) represents the following things with variable number of properties and values:

wig1's color is red.
wig2's color is red, green AND texture is soft AND material is nylon.
wig3's texture is soft AND material is jute.

coat1's color is red.

coat2's texture is soft AND material is cotton. coat3's color is green AND texture is smooth, supple.
/*****************************************************
Below code shows how to create and query above things, including finding all things that are red.

For the sake of comparision,
please show RM's equivalent schema/data and code/query to find all things that are red.

******************************************************/

// Create wig class

   int* pWig = T_create();
   T_Name_relate(&pWig, _T("wig"));
   T_relate(&pWig, &pReCls_g, &pThing_g);

// Create coat class

   int* pCoat = T_create();
   T_Name_relate(&pCoat, _T("coat"));
   T_relate(&pCoat, &pReCls_g, &pThing_g);

// Create color class

   int* pColor = T_create();
   T_Name_relate(&pColor, _T("color"));
   T_relate(&pColor, &pReCls_g, &pThing_g);

// Create texture class

   int* pTexture = T_create();
   T_Name_relate(&pTexture, _T("texture"));    T_relate(&pTexture, &pReCls_g, &pThing_g);

// Create material class

   int* pMaterial = T_create();
   T_Name_relate(&pMaterial, _T("material"));    T_relate(&pMaterial, &pReCls_g, &pThing_g);

// Create wig1
// Its color is red.

   int* pWig1 = T_create();

   T_Name_relate(&pWig1, _T("wig1"));
   T_relate(&pWig1, &pReCls_g, &pWig);
   T_Val_relate(&pWig1, &pColor, _T("red"));

// Create wig2
// Its color is red, green AND texture is soft AND material is nylon.

   int* pWig2 = T_create();

   T_Name_relate(&pWig2, _T("wig2"));
   T_relate(&pWig2, &pReCls_g, &pWig);
   T_Val_relate(&pWig2, &pColor, _T("red"));
   T_Val_relate(&pWig2, &pColor, _T("green"));
   T_Val_relate(&pWig2, &pTexture, _T("soft"));
   T_Val_relate(&pWig2, &pMaterial, _T("nylon"));

// Create wig3
// Its texture is soft AND material is jute.

   int* pWig3 = T_create();

   T_Name_relate(&pWig3, _T("wig3"));
   T_relate(&pWig3, &pReCls_g, &pWig);
   T_Val_relate(&pWig3, &pTexture, _T("soft"));
   T_Val_relate(&pWig3, &pMaterial, _T("jute"));

// Create coat1
// Its color is red.

   int* pCoat1 = T_create();

   T_Name_relate(&pCoat1, _T("coat1"));
   T_relate(&pCoat1, &pReCls_g, &pCoat);
   T_Val_relate(&pCoat1, &pColor, _T("red"));

// Create coat2
// Its texture is soft AND material is cotton.

   int* pCoat2 = T_create();

   T_Name_relate(&pCoat2, _T("coat2"));
   T_relate(&pCoat2, &pReCls_g, &pCoat);
   T_Val_relate(&pCoat2, &pTexture, _T("soft"));
   T_Val_relate(&pCoat2, &pMaterial, _T("cotton"));

// Create coat3
// Its color is green AND texture is smooth, supple.

   int* pCoat3 = T_create();

   T_Name_relate(&pCoat3, _T("coat3"));
   T_relate(&pCoat3, &pReCls_g, &pCoat);
   T_Val_relate(&pCoat3, &pColor, _T("green"));
   T_Val_relate(&pCoat3, &pTexture, _T("smooth"));
   T_Val_relate(&pCoat3, &pTexture, _T("supple"));


// Find wigs related to color AND texture.
// The loop below prints:
// "((wig))(wig2)(((color))(red))(((color))(green))(((texture))(soft))

       (((material))(nylon))"
   #define aSz 255
   int* pExpr1[aSz+1] = {NULL};
   if (Z_parse_r(_T("(wig) ((color)) ((texture))"), pExpr1, aSz))

      {return;}
   while (int* pT=Z(pExpr1, TRUE)){

      TCHAR sName[kStrSz_g+1] = _T("");
      T_Name_get(pT, sName, kStrSz_g, TRUE);
      TRACE(_T("%s\n"), sName);

   }

// Find coats related to color AND texture.
// The loop below prints:
// "((coat))(coat3)(((color))(green))(((texture))(smooth))(((texture))(supple))"

   int* pExpr2[aSz+1] = {NULL};
   if (Z_parse_r(_T("(coat) ((color)) ((texture))"), pExpr2, aSz))

      {return;}
   while (int* pT=Z(pExpr2, TRUE)){

      TCHAR sName[kStrSz_g+1] = _T("");
      T_Name_get(pT, sName, kStrSz_g, TRUE);
      TRACE(_T("%s\n"), sName);

   }

// Find all things that are red.
// The loop below prints:
// "(wig1)((wig))(((color))(red))"
// "(wig2)((wig))(((color))(red))(((color))(green))(((texture))(soft))

     (((material))(nylon))"
// "(coat1)((coat))(((color))(red))"

   int* pRed = AStr_getDefT(_T("red"));
   int* pE1[32];
   if (Expr_xVO_get_r(pColor, pRed, pE1)){return;}    while (int* pT=X2(pE1)){

      TCHAR sName[kStrSz_g+1] = _T("");
      T_Name_get(pT, sName, kStrSz_g, TRUE);
      TRACE(_T("%s\n"), sName);

   }

// Given wig1, print its info.
// Prints: "((wig))(wig1)(((color))(red))"

   TCHAR sName[kStrSz_g+1] = _T("");
   T_Name_get(pWig1, sName, kStrSz_g, TRUE);    TRACE(_T("%s\n"), sName);

// Given wig2, print its info.
// Prints: "((wig))(wig2)(((color))(red))(((color))(green))(((texture))(soft))

             (((material))(nylon))"
   _tcscpy(sName, _T(""));
   T_Name_get(pWig2, sName, kStrSz_g, TRUE);    TRACE(_T("%s\n"), sName);

// Given wig3, print its properties/values using alternate method
// "wig3's cls is wig."
// "wig3's name is wig3."
// "wig3's texture is soft."
// "wig3's material is jute."
// Loop thru wig3's properties and values

   int* pE2[32];
   Expr_S_getN_r(pWig3, pE2);
   while (int* pN = X2(pE2)){

      // Get property
         int* pProp = N_getV(pN);

      // Get value
         int* pVal = N_getO(pN);

      // Print "thingX's propY is valX."
         TCHAR sThing[kStrSz_g+1] = _T("");
         T_Name_get(pWig3, sThing, kStrSz_g);

         TCHAR sProp[kStrSz_g+1] = _T("");
         T_Name_get(pProp, sProp, kStrSz_g);

         TCHAR sVal[kStrSz_g+1] = _T("");
         T_Name_get(pVal, sVal, kStrSz_g);

         TCHAR sSent[3*kStrSz_g+1] = _T("");
         _stprintf(sSent, _T("%s's %s is %s."), sThing, sProp, sVal);
         TRACE(_T("%s\n"), sSent);

   } Received on Mon Aug 30 2004 - 12:00:28 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US