Natural Language Processing  0.1.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
syntaxtree.h
1 #ifndef SYNTAXTREE_H
2 #define SYNTAXTREE_H
3 #include "Tree.h"
4 #include "../Grammar Structure/Grammar-with-Map/grammar.h"
5 //#include "../../../Parser/Tagger/word.h"
6 //#include "../../../CONFIG/config.h"
7 #include "syntaxword.h"
8 
12 typedef std::pair<GrammarPhrase,SyntaxWord> GPSWpair;
13 
21  GPSWpair _d;
22 
27 
34  _d = GPSWpair(g,W);
35  }
36 
43  friend std::ostream& operator <<(std::ostream& out, const GSContainerpair& G){
44  out << "( " << phraseLookUp[G._d.first] << " , " << G._d.second << " )";
45  return out;
46  }
47 };
48 
52 typedef GSContainerpair GtSpair;
53 
58 
62 typedef Tree<GtSpair> Tpair;
63 
68 class SyntaxTree: public Tree<GtSpair>{
69 private:
73  SentenceType _st;
74  void recurHead(TNpair* root);
75  void recurObj(TNpair* root, const Word &W, SyntaxObject S);
76  Word getHeadWord(GrammarPhrase g, TNpair::TNvector W);
77 
78  TNpair* findPhrase(TNpair *start, GrammarPhrase find) const;
79  void setSubj(TNpair* sentence);
80  void setMV(TNpair* sentence);
81  void setDO(TNpair* sentence);
82  void setIDO(TNpair* sentence);
83  void setQ(TNpair* sentence);
84  void setAux(TNpair* sentence);
85  void setAtt(TNpair *sentence);
86  size_t hasDef(TNpair *phrase, GrammarPhrase g);
87 
88  void swapSyntax(SyntaxWord& A, SyntaxWord& B);
89 
90 public:
91  SyntaxTree();
92  SyntaxTree(TNpair* root);
93  SyntaxTree(const SyntaxTree& S);
94  SyntaxTree& operator =(const SyntaxTree& S);
95  ~SyntaxTree();
96 
97  // Public static function
98  static string getSyntaxEncoding(const vector<SyntaxWord>& SWord);
99  //These are functions for Parser only
100  void assignHeads();
101  void assignObjects();
102  void determineType();
103 
104  //Do stuff to current
105  //Create child (Must not have any children)
106  void addDef(GPlist def);
107  void removeDef();
108  GPlist getDef();
110  bool atLeaf();
111  TNpair* getLastLeaf();
112  TNpair* getFirstLeaf();
113  TNpair* getChildAt(std::size_t i);
114  bool atLastLeaf();
115  bool atFirstLeaf();
116  std::size_t leavesBefore();
117  std::size_t childIndex(TNpair* parent, TNpair* child);
118 
119  std::vector<SyntaxWord> getAll() const;
120  std::vector<SyntaxWord> getObj(SyntaxObject S) const;
121  SentenceType getSentenceType() const;
122  SyntaxObject askingFor() const;
123 };
124 
125 
126 
127 #endif // SYNTAXTREE_H
SyntaxObject askingFor() const
SyntaxTree::askingFor Gets the syntaxobject the question is asking for, if it is a question...
Definition: syntaxtree.cpp:231
GSContainerpair()
GSContainerpair Default Constructor.
Definition: syntaxtree.h:26
static string getSyntaxEncoding(const vector< SyntaxWord > &SWord)
SyntaxTree::getSyntaxEncoding External function that should be part of SyntaxTree, function does not use any of member variales.
Definition: syntaxtree.cpp:54
bool atFirstLeaf()
SyntaxTree::atFirstLeaf Checks if current is at the first leaf.
Definition: syntaxtree.cpp:155
void removeDef()
SyntaxTree::removeDef Removes the definition of current_exception() NOTE: It will remove all of the c...
Definition: syntaxtree.cpp:79
GSContainerpair(GrammarPhrase g, const SyntaxWord &W)
GSContainerpair Constructor.
Definition: syntaxtree.h:33
std::size_t leavesBefore()
SyntaxTree::leavesBefore Calculates the number of leaves before current.
Definition: syntaxtree.cpp:163
void determineType()
SyntaxTree::determineType Determines sentence type.
Definition: syntaxtree.cpp:276
bool atLastLeaf()
SyntaxTree::atLastLeaf Checks if current is at the last leaf.
Definition: syntaxtree.cpp:147
SyntaxTree & operator=(const SyntaxTree &S)
SyntaxTree::operator = assignment operator.
Definition: syntaxtree.cpp:33
TNpair * getFirstLeaf()
SyntaxTree::getFirstLeaf Returns the leftmost bottom leaf.
Definition: syntaxtree.cpp:125
GrammarPhrase getPhrase()
SyntaxTree::getPhrase Returns the phrase at current.
Definition: syntaxtree.cpp:98
GPSWpair _d
_d the pair
Definition: syntaxtree.h:21
SyntaxTree()
SyntaxTree::SyntaxTree Default Constructor.
Definition: syntaxtree.cpp:6
std::vector< SyntaxWord > getAll() const
SyntaxTree::getAll Gets all of the syntax words.
Definition: syntaxtree.cpp:196
SyntaxObject
Definition: config.h:167
~SyntaxTree()
SyntaxTree::~SyntaxTree Destructor.
Definition: syntaxtree.cpp:43
void assignHeads()
SyntaxTree::assignHeads assigns the head words to each node.
Definition: syntaxtree.cpp:254
SentenceType getSentenceType() const
SyntaxTree::getSentenceType gets the sentence type.
Definition: syntaxtree.cpp:223
void addDef(GPlist def)
SyntaxTree::addDef Adds the Definition to the current node (the children)
Definition: syntaxtree.cpp:70
friend std::ostream & operator<<(std::ostream &out, const GSContainerpair &G)
operator << insertion
Definition: syntaxtree.h:43
Definition: word.h:21
bool atLeaf()
SyntaxTree::atLeaf Checks if current is a leaf.
Definition: syntaxtree.cpp:106
std::vector< SyntaxWord > getObj(SyntaxObject S) const
SyntaxTree::getObj Gets all of the instances of the syntax object.
Definition: syntaxtree.cpp:209
TNpair * getChildAt(std::size_t i)
SyntaxTree::getChildAt gets the child at index of current.
Definition: syntaxtree.cpp:137
void assignObjects()
SyntaxTree::assignObjects assigns the syntax to each node.
Definition: syntaxtree.cpp:261
std::vector< TreeNode * > TNvector
TNvector typedef of std::vector<TreeNode*>
Definition: Tree.h:17
TNpair * getLastLeaf()
SyntaxTree::getLastLeaf Returns the Rightmost bottom leaf.
Definition: syntaxtree.cpp:114
The GSContainerpair struct Container for a GPSWpair.
Definition: syntaxtree.h:17
std::vector< GrammarPhrase > GPlist
GPlist typedef for vector<GrammarPhrase>
Definition: config.h:265
GPlist getDef()
SyntaxTree::getDef Returns the definition as a vector of grammar phrases of current.
Definition: syntaxtree.cpp:86
The SyntaxWord class Container for a Word and a Syntax Identifier.
Definition: syntaxword.h:10
std::size_t childIndex(TNpair *parent, TNpair *child)
SyntaxTree::childIndex Calculates which child is the child (from 0)
Definition: syntaxtree.cpp:184
GrammarPhrase
The GrammarPhrase enum Denotes the Grammar Phrase.
Definition: config.h:99
The SyntaxTree class The Tree specialized for holding syntax and words INHERITS: from Tree...
Definition: syntaxtree.h:68