test_XmlWordPatternFormatter.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <fstream>
00003 
00004 #include "LinguisticDefinition/XmlWordPatternFormatter.h"
00005 #include "LinguisticDefinition/LingFeatures.h"
00006 
00007 using namespace std;
00008 using namespace LinguisticDefinition;
00009 
00013 int main(int argc, char *argv[]) {
00014 
00015   LingDef lingDef("ar");
00016 
00017   // Populate the definition
00018   {
00019     {
00020       LingDef::Pos &nounPos = lingDef.createPos("NOUN");
00021       {
00022         LingDef::Feature &genderFeature =
00023           nounPos.createFeature("gender",
00024                                 LingDef::Feature::MISC,
00025                                 LingDef::Feature::ENUM);
00026 
00027         LingDef::Feature &masculineFeature =
00028           genderFeature.createEnumValueFeature("masculine");
00029         masculineFeature.setDefault(true);
00030 
00031         LingDef::Feature &feminineFeature =
00032           genderFeature.createEnumValueFeature("feminine");
00033 
00034         LingDef::Feature &caseFeature =
00035           nounPos.createFeature("case",
00036                                 LingDef::Feature::MISC,
00037                                 LingDef::Feature::ENUM);
00038 
00039         LingDef::Feature &nominativeFeature =
00040           caseFeature.createEnumValueFeature("nominative");
00041         nominativeFeature.setDefault(true);
00042 
00043         LingDef::Feature &genitiveFeature =
00044           caseFeature.createEnumValueFeature("genitive");
00045       }
00046     }
00047   }
00048 
00049   // Create a word pattern
00050   {
00051     XmlWordPatternFormatter wordPatternFormater(lingDef);
00052 
00053     stringstream definitionSource;
00054     definitionSource << "<WordPattern>" << endl;
00055     definitionSource << " <And>" << endl;
00056     definitionSource << "  <Pos name='NOUN'/>" << endl;
00057     definitionSource << "  <Or>" << endl;
00058     definitionSource << "   <And>" << endl;
00059     definitionSource << "    <Feature name='feminine'/>" << endl;
00060     definitionSource << "    <Feature name='nominative'/>" << endl;
00061     definitionSource << "   </And>" << endl;
00062     definitionSource << "   <And>" << endl;
00063     definitionSource << "    <Feature name='masculine'/>" << endl;
00064     definitionSource << "    <Feature name='genitive'/>" << endl;
00065     definitionSource << "   </And>" << endl;
00066     definitionSource << "  </Or>" << endl;
00067     definitionSource << "  <Not>" << endl;
00068     definitionSource << "   <Lemma>toto</Lemma>" << endl;
00069     definitionSource << "  </Not>" << endl;
00070     definitionSource << " </And>" << endl;
00071     definitionSource << "</WordPattern>" << endl;
00072     xmlDocPtr doc = xmlParseDoc((xmlChar *) definitionSource.str().c_str());
00073     if (doc != NULL) {
00074       xmlXPathContextPtr xpContext = xmlXPathNewContext(doc);
00075 
00076       xmlXPathObjectPtr xpObj =
00077         xmlXPathEval((xmlChar *) "//WordPattern", xpContext);
00078       if (xpObj != NULL) {
00079         xmlNodeSetPtr nodeSet = xpObj->nodesetval;
00080         if (nodeSet != NULL) {
00081           {for (int i = 0; i < nodeSet->nodeNr; i++) {
00082             WordPattern wordPattern =
00083               wordPatternFormater.createWordPattern(nodeSet->nodeTab[i]);
00084 
00085             {
00086               LingFeatures features(*lingDef.getPos("NOUN"));
00087               features += "feminine";
00088               features += "nominative";
00089               cerr << wordPattern.matches(features) << endl;
00090             }
00091 
00092             {
00093               LingFeatures features(*lingDef.getPos("NOUN"));
00094               features += "masculine";
00095               features += "genitive";
00096               cerr << wordPattern.matches(features) << endl;
00097             }
00098 
00099             {
00100               LingFeatures features(*lingDef.getPos("NOUN"));
00101               features += "masculine";
00102               cerr << wordPattern.matches(features) << endl;
00103             }
00104 
00105             {
00106               LingFeatures features(*lingDef.getPos("NOUN"));
00107               features += "feminine";
00108               features += "nominative";
00109               features.setLemma("toto");
00110               cerr << wordPattern.matches(features) << endl;
00111             }
00112 
00113           }}
00114         }
00115         xmlXPathFreeObject(xpObj);
00116       }
00117       xmlXPathFreeContext(xpContext);
00118     }
00119 
00120     xmlFreeDoc(doc);
00121   }
00122 
00123   return 1;
00124 }

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