KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tree.h
Go to the documentation of this file.
1 #ifndef TREE_H_
2 #define TREE_H_
3 
11 #include <iostream>
12 #include <string>
13 #include <list>
14 
15 #include "spear/RCIPtr.h"
16 #include "spear/Wide.h"
17 
18 #ifdef USE_MORPHER
19 #include "spear/Morpher.h"
20 #endif
21 
22 namespace spear {
23 
24 class Tree;
25 
26 typedef enum {
34 } PatternType;
35 
36 typedef enum {
42 } VerbType;
43 
44 class Pattern: public RCObject
45 {
46 
47 public:
48 
50  const RCIPtr<spear::Tree> & src,
51  const RCIPtr<spear::Tree> & dest,
52  const PatternType & type,
53  Tree * qual = NULL)
54  : _source(src.operator->()),
55  _destination(dest.operator->()),
56  _type(type), _qualifier(qual)
57  {};
58 
60  Tree * src,
61  Tree * dest,
62  const PatternType & type,
63  Tree * qual = NULL):
64  _source(src), _destination(dest),
65  _type(type), _qualifier(qual) {};
66 
67  spear::Tree * getSource() const { return _source; };
68 
69  spear::Tree * getDestination() const { return _destination; };
70 
71  const PatternType & getType() const { return _type; };
72 
73  const String & getQualifierString() const;
74 
75  spear::Tree * getQualifier() const { return _qualifier; };
76 
77  void display(OStream & os) const;
78 
79  void displayType(OStream & os) const;
80 
81 #ifdef DISPLAY_PROLOG
82  void displayProlog(OStream & os) const;
83 #endif
84 
85 private:
86 
87  Tree * _source;
88 
89  Tree * _destination;
90 
91  PatternType _type;
92 
93  Tree * _qualifier;
94 
95  static String NULL_QUALIFIER;
96 };
97 
99 
100 class Tree : public RCObject
101 {
102 
103 public:
104 
105  Tree() : _head(NULL), _verbType(VERB_ACTIVE), _position(-1) {};
106 
108  const String& word,
109  const String& label
110  ): _word(word),
111  _label(label),
112  _head(NULL),
113  _verbType(VERB_ACTIVE),
114  _position(-1)
115  {};
116 
117  Tree(const String & label)
118  : _label(label),
119  _head(NULL),
120  _verbType(VERB_ACTIVE),
121  _position(-1)
122  {};
123 
124  const String& getWord() const { return _word; };
125 
126  void setWord(const String& w) { _word = w; };
127 
128  const String& getLabel() const { return _label; };
129 
130  void setLabel(const String& label) { _label = label; };
131 
132  const RCIPtr<spear::Tree>& getHead() const { return _head; };
133 
134  const String& getHeadWord() const;
135 
136  short getHeadPosition() const;
137 
138  const String& getHeadNe() const;
139 
141  const String& getHeadTag() const;
142 
143  void setHead(const RCIPtr<spear::Tree>& h) { _head = h; };
144 
145  void setLemma(const String& lemma) { _lemma = lemma; };
146 
147 #ifdef USE_MORPHER
148 
149  const String & getHeadLemma();
150 
152  const String & getLemma();
153 #endif
154 
155  bool isTerminal() const
156  {
157  return (_children.empty() == true && _word.empty() == false);
158  };
159 
160  void addChild(
161  const RCIPtr<spear::Tree>& c,
162  bool atEnd = true)
163  {
164  if(atEnd == true)_children.push_back(c);
165  else _children.push_front(c);
166  };
167 
168  const std::list< RCIPtr<spear::Tree> >& getChildren() const
169  { return _children; };
170 
175  std::list< RCIPtr<spear::Tree> >& children()
176  { return _children; };
177 
179  { _patterns.push_back(p); };
180 
181  const std::list< RCIPtr<spear::Pattern> > & getPatterns() const
182  { return _patterns; };
183 
184  bool hasPatterns() const;
185 
186  const spear::VerbType & getVerbType() const { return _verbType; };
187 
188  void setVerbType(const spear::VerbType & vt) { _verbType = vt; };
189 
190  void setNe(const String & ne) { _ne = ne; };
191 
192  const String & getNe() const { return _ne; };
193 
194  void clear()
195  {
196  _word = W("");
197  _lemma = W("");
198  _label = W("");
199  _children.clear();
200  _head = RCIPtr<spear::Tree>();
201  _patterns.clear();
202  };
203 
204  void display(
205  OStream& os,
206  bool isHead = false,
207  int offset = 0
208  ) const;
209 
210  void displayParens(
211  OStream& os,
212  bool showHead = true
213  ) const;
214 
215  void displayPrettyParens(
216  OStream& os,
217  int offset = 0,
218  bool showHead = false
219  ) const;
220 
222  void displayProlog(
223  OStream& os,
224  int index
225  ) const;
226 
227  void displayPatterns(
228  OStream& os,
229  int offset = 0
230  ) const;
231 
237  short setPositions();
238 
239  short getPosition() const { return _position; };
240 
241 #ifdef USE_MORPHER
242  static void registerMorpher(const RCIPtr<spear::Morpher> & m)
243  { _morpher = m; };
244 #endif
245 
246  typedef std::list< RCIPtr<spear::Tree> >::iterator iterator;
247 
248  typedef std::list< RCIPtr<spear::Tree> >::const_iterator const_iterator;
249 
250 private:
252  void displayPrologPhrase(OStream & os) const;
253 
258  void displayPrologPatterns(OStream & os,
259  bool & printComma) const;
260 
262  void setPosition(short & current);
263 
264 private:
265 
266  Tree(const spear::Tree&);
267 
268  String _word;
269 
270  String _lemma;
271 
272  String _label;
273 
274  String _ne;
275 
276  RCIPtr<spear::Tree> _head;
277 
278  std::list< RCIPtr<spear::Tree> > _children;
279 
280  std::list< RCIPtr<spear::Pattern> > _patterns;
281 
282  spear::VerbType _verbType;
283 
288  short _position;
289 
290 #ifdef USE_MORPHER
291  static RCIPtr<spear::Morpher> _morpher;
292 #endif
293 };
294 
296 
297 }
298 
299 OStream& operator<<(OStream& os, const spear::TreePtr& tree);
300 
301 OStream& operator<<(OStream& os, const spear::Tree& tree);
302 
303 #endif
void setLemma(const String &lemma)
Definition: Tree.h:145
void setLabel(const String &label)
Definition: Tree.h:130
const String & getHeadWord() const
Definition: Tree.cc:355
Reference counting pointer class This file contains the code for the classes and class templates maki...
const String & getHeadNe() const
Definition: Tree.cc:413
Definition: Tree.h:40
Tree(const String &word, const String &label)
Definition: Tree.h:107
short getHeadPosition() const
Definition: Tree.cc:383
Definition: Tree.h:38
std::list< RCIPtr< spear::Tree > >::const_iterator const_iterator
Definition: Tree.h:248
bool isTerminal() const
Definition: Tree.h:155
Definition: Tree.h:39
void setWord(const String &w)
Definition: Tree.h:126
void setVerbType(const spear::VerbType &vt)
Definition: Tree.h:188
#define OStream
Definition: Wide.h:38
Definition: RCIPtr.h:67
Definition: Tree.h:100
void addChild(const RCIPtr< spear::Tree > &c, bool atEnd=true)
Definition: Tree.h:160
void clear()
Definition: Tree.h:194
RCIPtr< Pattern > PatternPtr
Definition: Tree.h:98
Definition: Tree.h:32
const PatternType & getType() const
Definition: Tree.h:71
Definition: Tree.h:27
Definition: Tree.h:29
Tree()
Definition: Tree.h:105
void displayType(OStream &os) const
Definition: Tree.cc:269
Definition: Tree.h:31
void displayPatterns(OStream &os, int offset=0) const
Definition: Tree.cc:323
spear::Tree * getSource() const
Definition: Tree.h:67
void displayPrettyParens(OStream &os, int offset=0, bool showHead=false) const
Definition: Tree.cc:103
RCIPtr< spear::Tree > TreePtr
Definition: Tree.h:295
bool hasPatterns() const
Definition: Tree.cc:339
const RCIPtr< spear::Tree > & getHead() const
Definition: Tree.h:132
const String & getNe() const
Definition: Tree.h:192
Pattern(const RCIPtr< spear::Tree > &src, const RCIPtr< spear::Tree > &dest, const PatternType &type, Tree *qual=NULL)
Definition: Tree.h:49
void display(OStream &os) const
Definition: Tree.cc:283
#define String
Definition: Wide.h:36
const String & getLabel() const
Definition: Tree.h:128
std::list< RCIPtr< spear::Tree > > & children()
Definition: Tree.h:175
short getPosition() const
Definition: Tree.h:239
const spear::VerbType & getVerbType() const
Definition: Tree.h:186
const String & getWord() const
Definition: Tree.h:124
void setHead(const RCIPtr< spear::Tree > &h)
Definition: Tree.h:143
OStream & operator<<(OStream &os, const spear::TreePtr &tree)
Definition: Tree.cc:50
const std::list< RCIPtr< spear::Tree > > & getChildren() const
Definition: Tree.h:168
Definition: Tree.h:33
const String & getQualifierString() const
Definition: Tree.cc:313
#define dest(triedge, pointptr)
Definition: triangle.c:938
spear::Tree * getQualifier() const
Definition: Tree.h:75
Tree(const String &label)
Definition: Tree.h:117
VerbType
Definition: Tree.h:36
const std::list< RCIPtr< spear::Pattern > > & getPatterns() const
Definition: Tree.h:181
void setNe(const String &ne)
Definition: Tree.h:190
#define W(X)
Definition: Wide.h:45
Definition: Tree.h:28
const String & getHeadTag() const
Definition: Tree.cc:369
Definition: RCIPtr.h:24
void display(OStream &os, bool isHead=false, int offset=0) const
Definition: Tree.cc:24
spear::Tree * getDestination() const
Definition: Tree.h:69
Definition: Tree.h:30
PatternType
Definition: Tree.h:26
for m
Definition: APPgetLargeConnectedEdges.m:64
Definition: Tree.h:41
Pattern(Tree *src, Tree *dest, const PatternType &type, Tree *qual=NULL)
Definition: Tree.h:59
short setPositions()
Definition: Tree.cc:442
void displayParens(OStream &os, bool showHead=true) const
Definition: Tree.cc:66
Definition: Tree.h:37
void displayProlog(OStream &os, int index) const
Definition: Tree.h:44
void addPattern(const RCIPtr< spear::Pattern > &p)
Definition: Tree.h:178
std::list< RCIPtr< spear::Tree > >::iterator iterator
Definition: Tree.h:239