00001 #include <iostream>
00002 #include <fstream>
00003
00004 #include "LinguisticDefinition/LingDef.h"
00005 #include "LinguisticDefinition/LingFeatures.h"
00006 #include "LinguisticDefinition/XmlLingDefFormatter.h"
00007 #include "LinguisticDefinition/XmlLingFeaturesFormatter.h"
00008
00009 using namespace std;
00010 using namespace LinguisticDefinition;
00011
00015 int main(int argc, char *argv[]) {
00016
00017
00018 stringstream definitionSource;
00019 definitionSource << "<LingDef>" << endl;
00020 definitionSource << " <Pos id='pos_noun' inherits='pos_base'>" << endl;
00021 definitionSource << " <Name>NOUN</Name>" << endl;
00022 definitionSource << " <Misc>" << endl;
00023 definitionSource << " <Enum name='number'>" << endl;
00024 definitionSource << " <Value name='singular'/>" << endl;
00025 definitionSource << " <Value name='dual' xml:lang='ar'/>" << endl;
00026 definitionSource << " <Value name='plural'/>" << endl;
00027 definitionSource << " </Enum>" << endl;
00028 definitionSource << " </Misc>" << endl;
00029 definitionSource << " <Conflicts>" << endl;
00030 definitionSource << " <Conflict aName='hello' bName='plural'/>" << endl;
00031 definitionSource << " </Conflicts>" << endl;
00032 definitionSource << " </Pos>" << endl;
00033 definitionSource << " <Pos id='pos_base' xml:lang='!yy,!zz'>" << endl;
00034 definitionSource << " <Misc>" << endl;
00035 definitionSource << " <Boolean name='hello'/>" << endl;
00036 definitionSource << " </Misc>" << endl;
00037 definitionSource << " </Pos>" << endl;
00038 definitionSource << "</LingDef>" << endl;
00039 XmlLingDefFormatter lingDefFormatter;
00040 LingDef lingDef =
00041 lingDefFormatter.createLingDef(definitionSource.str(), "xx");
00042
00043
00044 {
00045 const LingDef::Pos *nounPos = lingDef.getPos("NOUN");
00046 cerr << nounPos->getName() << endl;
00047 {
00048 const LingDef::Feature *helloFeature = nounPos->getFeature("hello");
00049 cerr << helloFeature->getName() << endl;
00050 }
00051
00052 {
00053 const LingDef::Feature *numberFeature = nounPos->getFeature("number");
00054 cerr << numberFeature->getName() << endl;
00055
00056 const LingDef::Feature *singularFeature =
00057 nounPos->getFeature("singular");
00058 cerr << singularFeature->getName() << endl;
00059 cerr << singularFeature->getParentEnum()->getName() << endl;
00060
00061 const LingDef::Feature *dualFeature =
00062 nounPos->getFeature("dual");
00063 cerr << dualFeature << endl;
00064
00065 const LingDef::Feature *pluralFeature =
00066 nounPos->getFeature("plural");
00067 cerr << pluralFeature->getName() << endl;
00068 cerr << pluralFeature->getParentEnum()->getName() << endl;
00069
00070 }
00071
00072
00073 {
00074 LingFeatures features(*nounPos);
00075 features += "singular";
00076 features += "bad";
00077 features += "hello";
00078 cerr << features.has("plural")
00079 << features.has("singular")
00080 << features.has("number")
00081 << features.has("hello")
00082 << features.has("bad")
00083 << endl;
00084
00085
00086 {
00087 LingFeatures featuresCopy(features);
00088 cerr << featuresCopy.has("plural")
00089 << featuresCopy.has("singular")
00090 << featuresCopy.has("number")
00091 << featuresCopy.has("hello")
00092 << featuresCopy.has("bad")
00093 << endl;
00094 }
00095
00096
00097 {
00098 LingFeatures featuresCopy(*nounPos);
00099 featuresCopy = features;
00100 cerr << featuresCopy.has("plural")
00101 << featuresCopy.has("singular")
00102 << featuresCopy.has("number")
00103 << featuresCopy.has("hello")
00104 << featuresCopy.has("bad")
00105 << endl;
00106 }
00107
00108 cerr << "Should be 10100: ";
00109 features += "plural";
00110 cerr << features.has("plural")
00111 << features.has("singular")
00112 << features.has("number")
00113 << features.has("hello")
00114 << features.has("bad")
00115 << endl;
00116 }
00117
00118
00119 {
00120 stringstream definitionSource;
00121 definitionSource << "<LingFeatures pos=\"NOUN\">" << endl;
00122 definitionSource << " <Feature name=\"singular\"/>" << endl;
00123 definitionSource << " <Feature name=\"bad\"/>" << endl;
00124 definitionSource << " <Feature name=\"hello\"/>" << endl;
00125 definitionSource << "</LingFeatures>" << endl;
00126 XmlLingFeaturesFormatter formatter(lingDef);
00127 LingFeatures features =
00128 formatter.createLingFeatures(definitionSource.str());
00129 cerr << features.has("plural")
00130 << features.has("singular")
00131 << features.has("number")
00132 << features.has("hello")
00133 << features.has("bad")
00134 << endl;
00135
00136 formatter.output(features, cerr);
00137 }
00138 }
00139
00140 return 1;
00141 }