00001 #ifndef _LINGUISTICDEFINITION_WORDPATTERN_H_ 00002 #define _LINGUISTICDEFINITION_WORDPATTERN_H_ 00003 00004 #include <string> 00005 #include <vector> 00006 #include <set> 00007 00008 #include "LingDef.h" 00009 #include "LingFeatures.h" 00010 #include "LingFeaturesSet.h" 00011 00012 //TODO: Create matcher classes! 00013 00014 namespace LinguisticDefinition { 00015 00060 class WordPattern { 00061 public: 00062 00066 WordPattern(); 00067 00071 ~WordPattern(); 00072 00076 WordPattern(const WordPattern &); 00077 00081 bool matches(const LingFeatures &) const; 00082 00086 bool matches(const LingFeaturesSet &) const; 00087 00091 LingFeaturesSet reduce(const LingFeaturesSet &) const; 00092 00096 void generate(std::vector<const LingFeatures *> &) const; 00097 00098 class Element; 00099 class OrGroupElement; 00100 class AndGroupElement; 00101 class LeafElement; 00102 00106 OrGroupElement &getModifiableRootElement(); 00107 00111 const OrGroupElement &getRootElement() const; 00112 00115 class Element { 00116 public: 00117 00121 Element(const WordPattern &); 00122 00126 virtual ~Element(); 00127 00131 Element(const Element &); 00132 00136 virtual Element *clone() const = 0; 00137 00141 const WordPattern &getElement() const; 00142 00146 void setNegative(bool = true); 00147 00151 bool isNegative() const; 00152 00156 virtual bool matches(const LingFeatures &) const = 0; 00157 00161 virtual void generate(std::vector<const LingFeatures *> &, 00162 LingFeatures *current) const = 0; 00163 00164 private: 00165 const WordPattern &d_element; 00166 bool d_negative; 00167 }; 00168 00172 class GroupElement : public Element { 00173 public: 00174 00178 GroupElement(const WordPattern &); 00179 00183 ~GroupElement(); 00184 00188 GroupElement(const GroupElement &); 00189 00193 OrGroupElement &createOr(); 00194 00198 AndGroupElement &createAnd(); 00199 00203 LeafElement &createLeaf(); 00204 00208 typedef std::vector<const Element *> ElementList; 00209 00213 typedef ElementList::const_iterator ElementIterator; 00214 00218 ElementIterator elementsBegin() const; 00219 00223 ElementIterator elementsEnd() const; 00224 00225 private: 00226 ElementList d_elements; 00227 }; 00228 00232 class OrGroupElement : public GroupElement { 00233 public: 00234 00238 OrGroupElement(const WordPattern &); 00239 00243 ~OrGroupElement(); 00244 00248 OrGroupElement(const OrGroupElement &); 00249 00253 Element *clone() const; 00254 00258 bool matches(const LingFeatures &) const; 00259 00263 void generate(std::vector<const LingFeatures *> &, 00264 LingFeatures *current) const; 00265 00266 private: 00267 }; 00268 00272 class AndGroupElement : public GroupElement { 00273 public: 00274 00278 AndGroupElement(const WordPattern &); 00279 00283 ~AndGroupElement(); 00284 00288 AndGroupElement(const AndGroupElement &); 00289 00293 Element *clone() const; 00294 00298 bool matches(const LingFeatures &) const; 00299 00303 void generate(std::vector<const LingFeatures *> &, 00304 LingFeatures *current) const; 00305 00306 private: 00307 }; 00308 00312 class LeafElement : public Element { 00313 public: 00314 00318 LeafElement(const WordPattern &); 00319 00323 ~LeafElement(); 00324 00328 LeafElement(const LeafElement &); 00329 00333 Element *clone() const; 00334 00338 const LingDef::Pos *getPosDef() const; 00339 00343 void setPosDef(const LingDef::Pos &); 00344 00348 void setForm(const std::string &); 00349 00353 void setLemma(const std::string &); 00354 00358 void setFeature(const LingDef::Feature &); 00359 00363 void setFeature(const LingDef::Feature &enumFeature, 00364 const LingDef::Feature &enumValueFeature); 00365 00369 bool matches(const LingFeatures &) const; 00370 00374 void generate(std::vector<const LingFeatures *> &, 00375 LingFeatures *current) const; 00376 00377 private: 00378 const LingDef::Pos *d_pos; 00379 const LingDef::Feature *d_feature; 00380 std::string d_form; 00381 std::string d_lemma; 00382 }; 00383 00387 class Reference { 00388 public: 00389 00393 Reference(const std::string &featureName, 00394 int sourceElementIndex, 00395 const std::string &sourceFeatureName); 00396 00400 const std::string &getFeatureName() const; 00401 00405 int getSourceElementIndex() const; 00406 00410 const std::string &getSourceFeatureName() const; 00411 00412 private: 00413 std::string d_featureName; 00414 int d_sourceElementIndex; 00415 std::string d_sourceFeatureName; 00416 }; 00417 00421 //TODO: references should be part of the and/or structure, but let's start 00422 // by doing it the easy way 00423 Reference &createReference(const std::string &featureName, 00424 int sourceElementIndex, 00425 const std::string &sourceFeatureName); 00426 00430 typedef std::vector<const Reference *> ReferenceList; 00431 00435 typedef ReferenceList::const_iterator ReferenceIterator; 00436 00440 ReferenceIterator referencesBegin() const; 00441 00445 ReferenceIterator referencesEnd() const; 00446 00447 private: 00448 OrGroupElement d_rootElement; 00449 ReferenceList d_references; 00450 }; 00451 00452 } 00453 00454 #endif //_LINGUISTICDEFINITION_WORDPATTERN_H_