00001 #ifndef _LINGUISTICDEFINITION_LINGDEF_H_
00002 #define _LINGUISTICDEFINITION_LINGDEF_H_
00003
00019 #include <string>
00020 #include <vector>
00021 #include <map>
00022 #include <set>
00023 #include <sstream>
00024 #include <iostream>
00025
00026
00027
00028
00029
00030
00031
00032
00033 namespace LinguisticDefinition {
00034
00116 class LingDef {
00117 public:
00118
00126 LingDef(const std::string &isoLanguageCode);
00127
00131 ~LingDef();
00132
00138 LingDef(const LingDef &);
00139
00143 LingDef &operator=(const LingDef &);
00144
00149 const std::string &getIsoLanguageCode() const;
00150
00151 class Pos;
00152
00176 class Tree {
00177 friend class LingDef;
00178 public:
00179
00183 Tree(const std::string &name);
00184
00188 Tree(const Tree &);
00189
00193 ~Tree();
00194
00198 const std::string &getName() const;
00199
00203 class Node {
00204 friend class Tree;
00205 private:
00206
00210 Node(Tree &, const std::string &name);
00211
00212 public:
00213
00217 ~Node();
00218
00222 Node &createChildNode(const std::string &name);
00223
00227 Tree &getParentTree() const;
00228
00232 const std::string &getName() const;
00233
00239 bool isAncestorOf(const Node &) const;
00240
00241 private:
00242 Tree *d_parentTree;
00243 std::string d_name;
00244 };
00245
00249 typedef std::vector<const Node *> NodeList;
00250 typedef NodeList::const_iterator NodeIterator;
00251
00255 NodeIterator nodesBegin() const;
00256
00260 NodeIterator nodesEnd() const;
00261
00265 Node &getRootNode();
00266 const Node *getNode(const std::string &) const;
00267
00268 private:
00269 std::string d_name;
00270 NodeList d_nodes;
00271 std::map<std::string, Node *> d_nodeNameMap;
00272 Node d_rootNode;
00273
00274 std::multimap<const Node *, const Node *> d_ancestorsMap;
00275 std::set<std::pair<const Node *,
00276 const Node *> > d_grandChildAncestorPairSet;
00277 };
00278
00282 Tree &createTree(const std::string &name);
00283
00288 const Tree *getTree(const std::string &name) const;
00289
00294 class Feature {
00295 friend class Pos;
00296 friend class LingDef;
00297 public:
00298
00302 ~Feature();
00303
00307 typedef enum { SYNTAX, MORPHO, SEMANTIC, MISC } Domain;
00308
00312 typedef enum { BOOLEAN, ENUM, REFERENCE, VTREE } Type;
00313
00317 const std::string &getName() const;
00318
00322 Domain getDomain() const;
00323
00327 Type getType() const;
00328
00332 const LingDef *getLingDef() const;
00333
00337 const LingDef::Pos *getPosDef() const;
00338
00346 const Feature *getParentEnum() const;
00347
00351 typedef std::set<Feature *> EnumChildrenSet;
00352
00356 typedef EnumChildrenSet::const_iterator EnumChildrenIterator;
00357
00362 EnumChildrenIterator enumChildrenBegin() const {
00363 return d_enumChildren.begin();
00364 }
00365
00370 EnumChildrenIterator enumChildrenEnd() const {
00371 return d_enumChildren.end();
00372 }
00373
00378 void setTree(const Tree &);
00379
00384 const Tree *getTree() const;
00385
00390 const Tree::Node *getTreeNode() const;
00391
00396 bool isIn(const std::set<const LingDef::Feature *> &) const;
00397
00410 void setAllowSeveralValues(bool);
00411
00415 bool allowSeveralValues() const;
00416
00423 void setAllowNoValue(bool);
00424
00428 bool allowNoValue() const;
00429
00433 void setDefault(bool);
00434
00438 bool isDefault() const;
00439
00443 void setShortName(const std::string &);
00444
00448 const std::string &getShortName() const;
00449
00454 Feature &createEnumValueFeature(const std::string &name);
00455
00459 void addConflict(const Feature &);
00460
00461 private:
00462
00466 Feature(Pos &,
00467 const std::string &name,
00468 Domain domain,
00469 Type type);
00470
00474 Feature(Feature &parentEnum,
00475 const std::string &name);
00476
00480 void setDefaultSub(bool, bool);
00481
00482 private:
00483 LingDef *d_lingDef;
00484 Pos *d_posDef;
00485 std::string d_name;
00486 Domain d_domain;
00487 Type d_type;
00488 std::string d_shortName;
00489
00490 Feature *d_parentEnum;
00491 EnumChildrenSet d_enumChildren;
00492
00493 bool d_allowSeveralValues;
00494 bool d_allowNoValue;
00495
00496 bool d_isDefault;
00497
00498 const Tree *d_tree;
00499 const Tree::Node *d_treeNode;
00500 };
00501
00505 class Pos {
00506 friend class Feature;
00507 friend class LingDef;
00508 public:
00509
00513 ~Pos();
00514
00518 Pos(const Pos &);
00519
00523 Pos &operator=(const Pos &);
00524
00528 const std::string &getName() const;
00529
00533 const LingDef *getLingDef() const;
00534
00539 const Pos *getSuperPos() const;
00540
00544 void setShortName(const std::string &);
00545
00549 const std::string &getShortName() const;
00550
00554 typedef enum { VIRTUAL, ELEMENT, SYNTAGM } Type;
00555
00559 void setType(Type);
00560
00564 Type getType() const;
00565
00569 void setNote(const std::string &);
00570
00575 const Feature *getFeature(const std::string &) const;
00576
00580 Feature &createFeature(const std::string &name,
00581 Feature::Domain domain,
00582 Feature::Type type);
00583
00587 typedef std::set<const Feature *> FeatureList;
00588
00592 typedef FeatureList::const_iterator FeatureIterator;
00593
00597 FeatureIterator featuresBegin() const;
00598
00602 FeatureIterator featuresEnd() const;
00603
00608 FeatureIterator defaultFeaturesBegin() const;
00609
00614 FeatureIterator defaultFeaturesEnd() const;
00615
00619 Pos &createSubPos(const std::string &name);
00620
00624 Pos &createVirtualSubPos();
00625
00626 private:
00627
00631 Pos(LingDef &lingDef, const std::string &name);
00632
00636 Pos(Pos &superPos, const std::string &name);
00637
00641 void addFeature(Feature *feature);
00642
00643 private:
00644 LingDef *d_lingDef;
00645 const Pos *d_superPos;
00646 std::string d_name;
00647 std::string d_shortName;
00648 Type d_type;
00649 std::string d_note;
00650
00651 std::vector<const Pos *> d_subPoses;
00652
00653 std::set<const Feature *> d_featureDefs;
00654 std::map<std::string, const Feature *> d_featureNameMap;
00655 std::map<std::string, const Feature *> d_featureShortNameMap;
00656 std::set<const Feature *> d_defaultFeatures;
00657 };
00658
00662 Pos &createPos(const std::string &name);
00663
00669 Pos &createVirtualPos();
00670
00675 const Pos *getPos(const std::string &id) const;
00676
00680 typedef std::map<const Feature *, Pos::FeatureList *> ConflictMap;
00681
00685 void addConflict(const Feature &featureA, const Feature &featureB);
00686
00690 const Pos::FeatureList *getConflicts(const Feature &) const;
00691
00692 private:
00693
00697 void addPos(Pos *pos);
00698
00702 void addTree(Tree *);
00703
00704 private:
00705 std::string d_isoLanguageCode;
00706
00707 std::vector<Pos *> d_posDefs;
00708 std::map<std::string, Pos *> d_posNameMap;
00709 std::map<std::string, Pos *> d_posShortNameMap;
00710
00711 std::vector<Tree *> d_treeDefs;
00712 std::map<std::string, Tree *> d_treeNameMap;
00713
00714 ConflictMap d_conflicts;
00715 };
00716
00717 }
00718
00719 #endif //_LINGUISTICDEFINITION_LINGDEF_H_