test_SentencePattern.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 
00003 #include "LinguisticDefinition/LingDef.h"
00004 #include "LinguisticDefinition/SentencePattern.h"
00005 #include "LinguisticDefinition/WordPattern.h"
00006 #include "LinguisticDefinition/LingFeaturesSet.h"
00007 
00008 using namespace std;
00009 using namespace LinguisticDefinition;
00010 
00014 int main(int argc, char *argv[]) {
00015 
00016   LingDef lingDef("ar");
00017 
00018   // Populate the definition
00019   {
00020     {
00021       LingDef::Pos &basePos = lingDef.createVirtualPos();
00022       LingDef::Pos &nounPos = basePos.createSubPos("NOUN");
00023       {
00024         LingDef::Feature &helloFeature =
00025           basePos.createFeature("hello",
00026                                 LingDef::Feature::MISC,
00027                                 LingDef::Feature::BOOLEAN);
00028       }
00029       
00030       {
00031         LingDef::Feature &numberFeature =
00032           nounPos.createFeature("number",
00033                                 LingDef::Feature::MISC,
00034                                 LingDef::Feature::ENUM);
00035 
00036         LingDef::Feature &singularFeature =
00037           numberFeature.createEnumValueFeature("singular");
00038         singularFeature.setDefault(true);
00039         
00040         LingDef::Feature &pluralFeature =
00041           numberFeature.createEnumValueFeature("plural");
00042       }
00043     }
00044   }
00045 
00046   {
00047     WordPattern wordPattern;
00048 
00049     SentencePattern pattern;
00050     pattern.createElement();
00051 
00052     const LingDef::Pos *nounPos = lingDef.getPos("NOUN");
00053     const LingDef::Feature *helloFeature = nounPos->getFeature("hello");
00054     const LingDef::Feature *pluralFeature = nounPos->getFeature("plural");
00055 
00056     WordPattern::OrGroupElement &element =
00057       wordPattern.getModifiableRootElement();
00058 
00059     // [NOUN:((+hello+plural)|(-hello))]
00060     {
00061       {
00062         WordPattern::AndGroupElement &andElement = element.createAnd();
00063         andElement.createLeaf().setFeature(*helloFeature);
00064         andElement.createLeaf().setFeature(*pluralFeature);
00065       }
00066 
00067       {
00068         WordPattern::LeafElement &leafElement = element.createLeaf();
00069         leafElement.setFeature(*helloFeature);
00070         leafElement.setNegative();
00071       }
00072     }
00073 
00074     {
00075       LingFeatures features(*nounPos);
00076       cerr << wordPattern.matches(features) << endl;
00077     }
00078 
00079     {
00080       LingFeatures features(*nounPos);
00081       features += "hello";
00082       cerr << wordPattern.matches(features) << endl;
00083     }
00084 
00085     {
00086       LingFeatures features(*nounPos);
00087       features += "plural";
00088       cerr << wordPattern.matches(features) << endl;
00089     }
00090 
00091     {
00092       LingFeatures features(*nounPos);
00093       features += "hello";
00094       features += "plural";
00095       cerr << element.matches(features) << endl;
00096     }
00097 
00098     {
00099       LingFeaturesSet featuresSet;
00100       {
00101         LingFeatures features(*nounPos);
00102         features += "hello";
00103         featuresSet.add(features);
00104       }
00105 
00106       {
00107         LingFeatures features(*nounPos);
00108         features += "plural";
00109         featuresSet.add(features);
00110       }
00111 
00112       {
00113         LingFeatures features(*nounPos);
00114         features += "hello";
00115         features += "plural";
00116         featuresSet.add(features);
00117       }
00118 
00119       cerr << wordPattern.matches(featuresSet) << endl;
00120       cerr << "empty? " << wordPattern.reduce(featuresSet).isEmpty() << endl;
00121     }
00122 
00123     {
00124       LingFeaturesSet featuresSet;
00125       featuresSet.add(*nounPos);
00126       featuresSet.set("singular");
00127       featuresSet.set("plural");
00128       featuresSet.set("hello");
00129 
00130       cerr << wordPattern.matches(featuresSet) << endl;
00131       cerr << "empty? " << wordPattern.reduce(featuresSet).isEmpty() << endl;
00132     }
00133 
00134     // Copy pattern
00135     {
00136       SentencePattern patternCopy(pattern);
00137     }
00138   }
00139 
00140   return 1;
00141 }

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