This example models two pizza orders using XDb1, a small experimental
db for Windows and Pocket PCs. The first order consists of a small,
thin pizza with mozzarella and veggies. The second order consists of a
large, thick pizza with mozzarella, parmesan, sausage, pepperoni,
black olives and four cokes.

To enter the above data via Natural Language Interface (as opposed to
via GUI or API), submit the following sentences:

order isa thing.
pizza isa thing.
size isa thing.
crust isa thing.
cheese isa thing.
topping isa thing.
drink isa thing.
drinkType isa thing.
qty isa thing.

order 1 isa order.
* isa pizza. (* now refers to a new unnamed instance of pizza class)
* isPartOf order 1.
*'s size is small.
*'s crust is thin.
*'s cheese is mozzarella.
*'s topping is veggies.

order 2 isa order.
* isa pizza. (* now refers to a new unnamed instance of pizza class)
* isPartOf order 2.
*'s size is large.
*'s crust is thick.
*'s cheese is mozzarella.
*'s cheese is parmesan.
*'s topping is sausage.
*'s topping is pepperoni.
*'s topping is black olives.
* isa drink. (* now refers to a new unnamed instance of drink class)
* isPartOf order 2.
*'s drinkType is coke.
*'s qty is 4.

The result of the above statements can be seen at
www.xdb1.com/Example/Ex108.asp An equivalent NULL-less RDM schema
might consist of the following tables:

T_Order
T_Pizza
T_Size
T_Crust
T_Cheese
T_Topping
T_Drink
T_DrinkType
T_Qty

T_OrderPizzaMap (to allow orders with variable number of pizzas)
T_PizzaCheeseMap (to allow pizzas with variable number of cheeses)
T_PizzaToppingMap (to allow pizzas with variable number of toppings)
T_OrderDrinkMap (to allow orders with variable number of drinks)

--------------------------------------------------
To find things via "relational expressions", submit the following
sentences:

The following expressions find order 1:
order (pizza thin veggies)
order (small thin pizza mozzarella veggies)

The following expressions find order 2:
order (pizza thick pepperoni "black olives")
order (pizza parmesan) (drink coke)

The following expressions find both orders:
order (pizza mozzarella)
order (pizza)

-------------------------------------------------------------------------
The following code models the equivalent data programmatically via
XDb1's API (<100KB).

void Example108()
{
// Create classes
// Create order
int* pOrder = T_create();
T_relate(&pOrder, rCls, &pThing_g);
T_Name_set(&pOrder, _T("order"));

// Create pizza
int* pPizza = T_create();
T_relate(&pPizza, rCls, &pThing_g);
T_Name_set(&pPizza, _T("pizza"));

// Create size
int* pSize = T_create();
T_relate(&pSize, rCls, &pThing_g);
T_Name_set(&pSize, _T("size"));

// Create crust
int* pCrust = T_create();
T_relate(&pCrust, rCls, &pThing_g);
T_Name_set(&pCrust, _T("crust"));

// Create cheese
int* pCheese = T_create();
T_relate(&pCheese, rCls, &pThing_g);
T_Name_set(&pCheese, _T("cheese"));

// Create topping
int* pTopping = T_create();
T_relate(&pTopping, rCls, &pThing_g);
T_Name_set(&pTopping, _T("topping"));

// Create drink
int* pDrink = T_create();
T_relate(&pDrink, rCls, &pThing_g);
T_Name_set(&pDrink, _T("drink"));

// Create drinkType
int* pDrinkType = T_create();
T_relate(&pDrinkType, rCls, &pThing_g);
T_Name_set(&pDrinkType, _T("drinkType"));

// Create qty
int* pQty = T_create();
T_relate(&pQty, rCls, &pThing_g);
T_Name_set(&pQty, _T("qty"));

// Create order 1
int* pOrder1 = T_create();
T_relate(&pOrder1, rCls, &pOrder);
T_Name_set(&pOrder1, _T("order 1"));

// Create a pizza
int* pAPizza = T_create();
T_relate(&pAPizza, rCls, &pPizza);

// Relate pizza is part of order 1
T_relate(&pAPizza, rAsm, &pOrder1);

// Set the pizza's size is thin
T_Val_set(&pAPizza, &pSize, _T("small"));

// Set the pizza's crust is thin
T_Val_set(&pAPizza, &pCrust, _T("thin"));

// Set the pizza's cheese is mozzarella
T_Val_set(&pAPizza, &pCheese, _T("mozzarella"));

// Set the pizza's topping is veggies
T_Val_set(&pAPizza, &pTopping, _T("veggies"));

// Create order 2
int* pOrder2 = T_create();
T_relate(&pOrder2, rCls, &pOrder);
T_Name_set(&pOrder2, _T("order 2"));

// Create a pizza
pAPizza = T_create();
T_relate(&pAPizza, rCls, &pPizza);

// Relate the pizza is part of order 2
T_relate(&pAPizza, rAsm, &pOrder2);

// Set the pizza's size is large
T_Val_set(&pAPizza, &pSize, _T("large"));

// Set the pizza's crust is thick
T_Val_set(&pAPizza, &pCrust, _T("thick"));

// Set the pizza's cheese is mozzarella
T_Val_set(&pAPizza, &pCheese, _T("mozzarella"));

// Set the pizza's cheese is mozzarella
T_Val_set(&pAPizza, &pCheese, _T("parmesan"));

// Set the pizza's topping is sausage
T_Val_set(&pAPizza, &pTopping, _T("sausage"));

// Set the pizza's topping is pepperoni
T_Val_set(&pAPizza, &pTopping, _T("pepperoni"));

// Set the pizza's topping is black olives
T_Val_set(&pAPizza, &pTopping, _T("black olives"));

// Create a drink
int* pADrink = T_create();
T_relate(&pADrink, rCls, &pDrink);

// Relate the drink is part of order 2
T_relate(&pADrink, rAsm, &pOrder2);

// Set the drink's drinkType is coke
T_Val_set(&pADrink, &pDrinkType, _T("coke"));

// Set the drink's qty is 4
T_Val_set(&pADrink, &pQty, _T("4"));

// Create a relational expression string to find order 1
TCHAR str[kNmSz_g+1] = _T("order (pizza thin veggies)");

// Prepare relational expression str
#define aSz 255
int* pExpr[aSz+1] = {NULL};
if (Q_Str_parse_r(str, pExpr, aSz)) {return;}
if (Q_SymStr_parse_r(pExpr)) {return;}

// Loop thru things satisfying expression
while (int* pT=X(pExpr)){
TCHAR sOrder[kNmSz_g+1] = _T("");
T_Name_get(pT, sOrder, kNmSz_g);
TRACE(_T("%s\n"), sOrder);
}
}