test_LingDef.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 
00004 #include "LinguisticDefinition/LingDef.h"
00005 #include "LinguisticDefinition/LingFeatures.h" //TODO? own test file?
00006 
00007 using namespace std;
00008 using namespace LinguisticDefinition;
00009 
00013 int main(int argc, char *argv[]) {
00014 
00015   LingDef *lingDefCopy = NULL;
00016 
00017   // Test usage of the LingDef class
00018   {
00019     LingDef lingDef("ar");
00020 
00021     // Populate the definition
00022     {
00023       {
00024         LingDef::Pos &basePos = lingDef.createVirtualPos();
00025         LingDef::Pos &nounPos = basePos.createSubPos("NOUN");
00026         {
00027           LingDef::Feature &helloFeature =
00028             basePos.createFeature("hello",
00029                                   LingDef::Feature::MISC,
00030                                   LingDef::Feature::BOOLEAN);
00031         }
00032 
00033         {
00034           LingDef::Feature &numberFeature =
00035             nounPos.createFeature("number",
00036                                   LingDef::Feature::MISC,
00037                                   LingDef::Feature::ENUM);
00038 
00039           LingDef::Feature &singularFeature =
00040             numberFeature.createEnumValueFeature("singular");
00041           singularFeature.setDefault(true);
00042 
00043           LingDef::Feature &pluralFeature =
00044             numberFeature.createEnumValueFeature("plural");
00045         }
00046       }
00047 
00048       {
00049         LingDef::Tree &semTree = lingDef.createTree("semtree");
00050         semTree.getRootNode().
00051           createChildNode("concrete").
00052           createChildNode("human").
00053           createChildNode("woman");
00054         semTree.getRootNode().
00055           createChildNode("abstract");
00056       }
00057     }
00058 
00059     // Query the definition
00060     {
00061       const LingDef::Pos *nounPos = lingDef.getPos("NOUN");
00062       cerr << nounPos->getName() << endl;
00063       {
00064         const LingDef::Feature *helloFeature = nounPos->getFeature("hello");
00065         cerr << helloFeature->getName() << endl;
00066       }
00067 
00068       {
00069         const LingDef::Feature *numberFeature = nounPos->getFeature("number");
00070         cerr << numberFeature->getName() << endl;
00071 
00072         const LingDef::Feature *singularFeature =
00073           nounPos->getFeature("singular");
00074         cerr << singularFeature->getName() << endl;
00075         cerr << singularFeature->getParentEnum()->getName() << endl;
00076 
00077         const LingDef::Feature *pluralFeature =
00078           nounPos->getFeature("plural");
00079         cerr << pluralFeature->getName() << endl;
00080         cerr << pluralFeature->getParentEnum()->getName() << endl;
00081       }
00082     }
00083 
00084 
00085     // Create a copy before the object lingDef goes out of scope, to make
00086     // sure that we copied the structure correctly
00087     lingDefCopy = new LingDef(lingDef);
00088   }
00089 
00090 
00091   {
00092     // Repeat the query test, now with the copied object
00093     {
00094       const LingDef::Pos *nounPos = lingDefCopy->getPos("NOUN");
00095       cerr << nounPos->getName() << endl;
00096       {
00097         const LingDef::Feature *helloFeature = nounPos->getFeature("hello");
00098         cerr << helloFeature->getName() << endl;
00099       }
00100 
00101       {
00102         const LingDef::Feature *numberFeature = nounPos->getFeature("number");
00103         cerr << numberFeature->getName() << endl;
00104 
00105         const LingDef::Feature *singularFeature =
00106           nounPos->getFeature("singular");
00107         cerr << singularFeature->getName() << endl;
00108         cerr << singularFeature->getParentEnum()->getName() << endl;
00109 
00110         const LingDef::Feature *pluralFeature =
00111           nounPos->getFeature("plural");
00112         cerr << pluralFeature->getName() << endl;
00113         cerr << pluralFeature->getParentEnum()->getName() << endl;
00114       }
00115     }
00116   }
00117 
00118   delete lingDefCopy;
00119 
00120   return 0;
00121 }

Generated on Fri Jun 23 14:03:15 2006 for LinguisticDefinition by  doxygen 1.4.7