The following is an example of ontology that describes familly relationships:
animal = being & ~human; human = being & ~animal; male = animal & ~female & ~hermaphrodite; female = animal & ~male & ~hermaphrodite; hermaphrodite = animal & ~male & ~female; man = human & ~woman; woman = human & ~man; parent = human & (?has_child/human | ?married_to/parent); mother = parent & woman; father = parent & man; husband = man & ?married_to/woman; wife = woman & ?married_to/man; married = human & ?married_to/human; child = human & ?has_parent/human; son = child & man; daughter = child & woman; grand_parent = human & ?has_child/parent; grand_father = man & grand_parent; grand_mother = woman & grand_parent;
The following is an example of low-level symbol table:
#ifndef __STORE__ #define __STORE__ // ................................................................................ // Ontologies #define O_family (0x01000001) // ................................................................................ // Roles #define R_has_child (0x08000014) #define R_married_to (0x08000017) #define R_has_parent (0x08000028) // ................................................................................ // Concepts #define C_being (0x06000002) #define C_human (0x06000003) // ~animal&being #define C_animal (0x06000005) // ~human&being #define C_female (0x06000007) // ~hermaphrodite&~male&animal #define C_hermaphrodite (0x06000009) // ~female&~male&animal #define C_male (0x0600000b) // ~hermaphrodite&~female&animal #define C_woman (0x06000010) // ~man&human #define C_man (0x06000012) // ~woman&human #define C_parent (0x06000016) // (?married_to/parent|?has_child/human)&human #define C_mother (0x0600001c) // woman&parent #define C_father (0x0600001e) // man&parent #define C_husband (0x06000021) // ?married_to/woman&man #define C_wife (0x06000024) // ?married_to/man&woman #define C_married (0x06000027) // ?married_to/human&human #define C_child (0x0600002b) // ?has_parent/human&human #define C_son (0x0600002d) // man&child #define C_daughter (0x0600002f) // woman&child #define C_grand_parent (0x06000032) // ?has_child/parent&human #define C_grand_father (0x06000034) // grand_parent&man #define C_grand_mother (0x06000036) // grand_parent&woman #endif //__STORE__
Ontologies can be loaded in stores in few lines of code:
const string stDB = "sample.db"; if (tFile::exist(stDB)) { cout << "Erase ontologies store" << endl; tFile::erase(stDB); } cout << "Create new store" << endl; spiSession spSession = iSession::Create(stDB); cout << "Load ontology in store" << endl; if (!spSession->Load("family.txt", "family")) { cout << "Parsing errors : " << endl << endl; const list<string>& oErrors = spSession->Errors(); for(list<string>::const_iterator p = oErrors.begin(); p != oErrors.end(); p ++) { cout << *p << endl; } } cout << "Dump store" << endl; spSession->Dump("sample.h");
This is an example of reasoner invocation using the high-level API:
// Create store session spiSession spSession = iSession::Create("sample.db"); // Parse concept sptExpression spExpr = iSession->Parse("father&~animal"); // Check concept satisfiability bool fRes = iSession->Satisfiable(spExpr);
This is an example of reasoner invocation using the low-level API:
// Create store object spiStore sp = StoreFactorySQLite::Create("test.db"); // Open store sp->Open(); // Create reasoner object spiReasoner spReasoner = iReasoner::Create(sp); // Build concept "grand_parent& ~animal" tExprFactory oFact; oFact.concept(C_grand_parent); oFact.concept(OP_NEG(C_animal)); oFact.andop(); sptExpression spExpr = oFact.expr(); // Check concept satisfiablity bool fRet = spReasoner->Satisfiable(spExpr);