ZGen  0.2.0
a linearization system for natural language.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tree.h
Go to the documentation of this file.
1 #ifndef __ZGEN_TYPES_DEPENDENCY_TREE_H__
2 #define __ZGEN_TYPES_DEPENDENCY_TREE_H__
3 
4 #include "settings.h"
5 #include "types/instance.h"
6 
7 namespace ZGen {
8 
10 public:
11  typedef std::vector<int> edgeset_t;
12 
14 
16 
23  virtual int set_ref(const dependency_t* _ref);
24 
25  //
26  friend std::ostream & operator << (std::ostream & ofs, const DependencyTree & tree);
27 
29  const edgeset_t& siblings(int i);
30 
32  const edgeset_t& descendants(int i);
33 
35  const edgeset_t& children(int i);
36 
38  int head(int i);
39 
41  bool arc(int source, int target);
42 protected:
46  virtual void reset(int N = kMaxNumberOfWords);
47 
49  void dependency_to_tree(const dependency_t* parse);
50 
56  void go(int now);
57 
59  const dependency_t * ref;
60 
63 
66 
69 
72 
75 
76 private:
78 
80  DependencyTree& operator = (const DependencyTree & other);
81 
88  void add_edge(int u, int v);
89 };
90 
91 
93 public:
94  int set_ref(const dependency_t* ref);
95 
96 
97  int lvl0(int i) const;
98 
99 
100  int lvl1(int i) const;
101 
102 
103  int lvl2(int i) const;
104 
105 protected:
106  void reset(int N = kMaxNumberOfWords);
107 
108 private:
109  void color(int now, int _0, int _1, int _2);
110 
111  int lvl0_deprels[kMaxNumberOfWords];
112  int lvl1_deprels[kMaxNumberOfWords];
113  int lvl2_deprels[kMaxNumberOfWords];
114 };
115 
116 //
118 public:
119 
120  int set_ref(const dependency_t* ref);
121 
122 
123  int root(int i) const;
124 
125 
126  int depth(int i) const;
127 
128 
129  int lca(int u, int v) const;
130 
131 
132  bool is_root(int i) const;
133 
134 
135  bool same_ancestor(int u, int v) const;
136 
137  //
138  friend std::ostream & operator << (std::ostream & ofs, const DependencyForest& tree);
139 protected:
140  void reset(int N = kMaxNumberOfWords);
141 
142 private:
143  void rootize(int now, int root, int depth);
144 
145  int root_[kMaxNumberOfWords];
146  int depth_[kMaxNumberOfWords];
148 };
149 
150 
151 }
152 
153 #endif // end for __SR_DEPENDENCY_H__
DependencyTree()
Definition: tree.cc:5
int set_ref(const dependency_t *ref)
Definition: tree.cc:225
bool arc(int source, int target)
Return if there is an edge between source and target.
Definition: tree.cc:70
virtual void reset(int N=kMaxNumberOfWords)
Definition: tree.cc:75
~DependencyTree()
Definition: tree.cc:8
int depth(int i) const
Definition: tree.cc:280
std::vector< int > edgeset_t
Definition: tree.h:11
const dependency_t * ref
The reference to the dependency parse instance.
Definition: tree.h:59
Definition: tree.h:9
int lca(int u, int v) const
Definition: tree.cc:285
int lvl2(int i) const
Definition: tree.cc:220
const int kMaxNumberOfWords
Definition: settings.h:8
virtual int set_ref(const dependency_t *_ref)
Definition: tree.cc:32
int head(int i)
Access the head of node i.
Definition: tree.cc:65
edgeset_t children_[kMaxNumberOfWords]
Record the children for each node.
Definition: tree.h:62
Definition: tree.h:117
const edgeset_t & siblings(int i)
Access the siblings of node i.
Definition: tree.cc:55
Definition: instance.h:18
int set_ref(const dependency_t *ref)
Definition: tree.cc:187
void reset(int N=kMaxNumberOfWords)
Definition: tree.cc:178
bool is_root(int i) const
Definition: tree.cc:293
int lvl1(int i) const
Definition: tree.cc:215
edgeset_t siblings_[kMaxNumberOfWords]
Record the siblings for each node.
Definition: tree.h:74
edgeset_t descendants_[kMaxNumberOfWords]
Record the descendant for each node.
Definition: tree.h:71
void reset(int N=kMaxNumberOfWords)
Definition: tree.cc:256
void go(int now)
Definition: tree.cc:109
bool same_ancestor(int u, int v) const
Definition: tree.cc:298
const edgeset_t & descendants(int i)
Access the descendants of node i.
Definition: tree.cc:50
friend std::ostream & operator<<(std::ostream &ofs, const DependencyForest &tree)
Definition: tree.cc:302
void dependency_to_tree(const dependency_t *parse)
Convert the dependency parse into the dependency tree.
Definition: tree.cc:17
int root(int i) const
Definition: tree.cc:275
friend std::ostream & operator<<(std::ostream &ofs, const DependencyTree &tree)
Definition: tree.cc:150
int indgr_[kMaxNumberOfWords]
Record the in degree of the graph.
Definition: tree.h:68
int lvl0(int i) const
Definition: tree.cc:210
const edgeset_t & children(int i)
Access the children of node i.
Definition: tree.cc:60
int parent_[kMaxNumberOfWords]
Record the parent for each node.
Definition: tree.h:65