00001 #include <iostream>
00002 #include <fstream>
00003
00004 #include "LinguisticDefinition/LingDef.h"
00005 #include "LinguisticDefinition/LingFeatures.h"
00006
00007 using namespace std;
00008 using namespace LinguisticDefinition;
00009
00013 void testQuery(LingDef &lingDef) {
00014 const LingDef::Pos *nounPos = lingDef.getPos("NOUN");
00015 cerr << nounPos->getName() << endl;
00016 {
00017 const LingDef::Feature *helloFeature = nounPos->getFeature("hello");
00018 cerr << helloFeature->getName() << endl;
00019 }
00020
00021 {
00022 const LingDef::Feature *numberFeature = nounPos->getFeature("number");
00023 cerr << numberFeature->getName() << endl;
00024
00025 const LingDef::Feature *singularFeature =
00026 nounPos->getFeature("singular");
00027 cerr << singularFeature->getName() << endl;
00028 cerr << singularFeature->getParentEnum()->getName() << endl;
00029
00030 const LingDef::Feature *pluralFeature =
00031 nounPos->getFeature("plural");
00032 cerr << pluralFeature->getName() << endl;
00033 cerr << pluralFeature->getParentEnum()->getName() << endl;
00034 }
00035
00036 const LingDef::Pos *verbPos = lingDef.getPos("VERB");
00037
00038
00039 {
00040 LingFeatures features(*nounPos);
00041 features += "singular";
00042 features += "bad";
00043 features += "hello";
00044 cerr << features.has("plural")
00045 << features.has("singular")
00046 << features.has("number")
00047 << features.has("hello")
00048 << features.has("bad")
00049 << endl;
00050
00051
00052 {
00053 LingFeatures featuresCopy(features);
00054 cerr << featuresCopy.has("plural")
00055 << featuresCopy.has("singular")
00056 << featuresCopy.has("number")
00057 << featuresCopy.has("hello")
00058 << featuresCopy.has("bad")
00059 << endl;
00060 }
00061
00062
00063 {
00064 LingFeatures featuresCopy(*nounPos);
00065 featuresCopy = features;
00066 cerr << featuresCopy.has("plural")
00067 << featuresCopy.has("singular")
00068 << featuresCopy.has("number")
00069 << featuresCopy.has("hello")
00070 << featuresCopy.has("bad")
00071 << endl;
00072 }
00073 }
00074
00075
00076 {
00077 LingFeatures features(*nounPos);
00078 cerr << "should be 0: " << features.isDefined("plural") << endl;
00079 features += "plural";
00080 cerr << "should be 1: " << features.has("plural") << endl;
00081 cerr << "should be 1: " << features.isDefined("plural") << endl;
00082 features.unset("plural");
00083 cerr << "should be 0: " << features.has("plural") << endl;
00084 cerr << "should be 0: " << features.isDefined("plural") << endl;
00085 features -= "plural";
00086 cerr << "should be 0: " << features.has("plural") << endl;
00087 cerr << "should be 1: " << features.isDefined("plural") << endl;
00088 features.unset("plural");
00089 cerr << "should be 0: " << features.has("plural") << endl;
00090 cerr << "should be 0: " << features.isDefined("plural") << endl;
00091 }
00092
00093
00094 {
00095 {
00096 LingFeatures features(*nounPos);
00097 features += "woman";
00098 features += "something";
00099
00100 cerr << "something? " << features.has("something") << endl;
00101 cerr << "woman? " << features.has("woman") << endl;
00102 cerr << "concrete? " << features.has("concrete") << endl;
00103
00104 const LingDef::Feature *womanFeature = nounPos->getFeature("woman");
00105 cerr << "womanFeature=" << womanFeature << endl;
00106 }
00107
00108 {
00109 LingFeatures features(*verbPos);
00110 features += "woman";
00111 cerr << "woman? " << features.has("woman") << endl;
00112 cerr << "concrete? " << features.has("concrete") << endl;
00113 }
00114 }
00115
00116
00117 {
00118 LingFeatures features(*nounPos);
00119 cerr << "should be 0: " << features.has("one") << endl;
00120 cerr << "should be 0: " << features.has("two") << endl;
00121 features += "one";
00122 cerr << "should be 1: " << features.has("one") << endl;
00123 cerr << "should be 0: " << features.has("two") << endl;
00124 features += "two";
00125 cerr << "should be 0: " << features.has("one") << endl;
00126 cerr << "should be 1: " << features.has("two") << endl;
00127 features += "one";
00128 cerr << "should be 1: " << features.has("one") << endl;
00129 cerr << "should be 0: " << features.has("two") << endl;
00130 }
00131 }
00132
00136 int main(int argc, char *argv[]) {
00137
00138 LingDef *lingDefCopy = NULL;
00139
00140
00141 {
00142 LingDef lingDef("ar");
00143
00144
00145 {
00146 {
00147 LingDef::Pos &basePos = lingDef.createVirtualPos();
00148 LingDef::Pos &nounPos = basePos.createSubPos("NOUN");
00149 {
00150 LingDef::Feature &helloFeature =
00151 basePos.createFeature("hello",
00152 LingDef::Feature::MISC,
00153 LingDef::Feature::BOOLEAN);
00154
00155 LingDef::Feature &numberFeature =
00156 nounPos.createFeature("number",
00157 LingDef::Feature::MISC,
00158 LingDef::Feature::ENUM);
00159
00160 LingDef::Feature &singularFeature =
00161 numberFeature.createEnumValueFeature("singular");
00162 singularFeature.setDefault(true);
00163
00164 LingDef::Feature &pluralFeature =
00165 numberFeature.createEnumValueFeature("plural");
00166
00167
00168 LingDef::Feature &oneFeature =
00169 basePos.createFeature("one",
00170 LingDef::Feature::MISC,
00171 LingDef::Feature::BOOLEAN);
00172
00173 LingDef::Feature &twoFeature =
00174 basePos.createFeature("two",
00175 LingDef::Feature::MISC,
00176 LingDef::Feature::BOOLEAN);
00177
00178 oneFeature.addConflict(twoFeature);
00179 }
00180
00181 LingDef::Pos &verbPos = basePos.createSubPos("VERB");
00182
00183 {
00184 LingDef::Tree &semTree = lingDef.createTree("semtree");
00185 semTree.getRootNode().
00186 createChildNode("concrete").
00187 createChildNode("human").
00188 createChildNode("woman");
00189 semTree.getRootNode().
00190 createChildNode("abstract");
00191
00192 LingDef::Feature &semFeature =
00193 nounPos.createFeature("sem",
00194 LingDef::Feature::MISC,
00195 LingDef::Feature::VTREE);
00196 semFeature.setTree(semTree);
00197 }
00198 }
00199
00200 }
00201
00202
00203 testQuery(lingDef);
00204
00205
00206
00207 lingDefCopy = new LingDef(lingDef);
00208 }
00209
00210 cerr << "====================" << endl;
00211
00212 {
00213
00214 testQuery(*lingDefCopy);
00215 }
00216
00217 delete lingDefCopy;
00218
00219 return 1;
00220 }