ModErn Text Analysis
META Enumerates Textual Applications
internal_node.h
Go to the documentation of this file.
1 
9 #ifndef META_PARSE_INTERNAL_NODE_H_
10 #define META_PARSE_INTERNAL_NODE_H_
11 
12 #include <memory>
13 #include <vector>
14 #include "parser/trees/node.h"
15 #include "util/clonable.h"
16 
17 namespace meta
18 {
19 namespace parser
20 {
21 
22 class leaf_node;
23 
28 class internal_node : public util::clonable<node, internal_node>
29 {
30  public:
32 
33  using base::base;
34 
45  template <class FwdIt>
46  internal_node(class_label cat, FwdIt begin, FwdIt end)
47  : base{std::move(cat)}
48  {
49  auto dist = std::distance(begin, end);
50  children_.reserve(dist);
51  for (; begin != end; ++begin)
52  children_.emplace_back(std::move(*begin));
53  }
54 
63  internal_node(class_label cat,
64  std::vector<std::unique_ptr<node>>&& children);
65 
70 
76  void add_child(std::unique_ptr<node> child);
77 
81  uint64_t num_children() const;
82 
88  const node* child(uint64_t idx) const;
89 
90  bool is_leaf() const override;
91 
92  bool equal(const node& other) const override;
93 
97  const leaf_node* head_lexicon() const;
98 
102  void head_lexicon(const leaf_node* l);
103 
107  const node* head_constituent() const;
108 
112  void head_constituent(const node* n);
113 
121  void head(const node* n);
122 
127  template <class Fun>
128  void each_child(Fun&& fn) const
129  {
130  for (const auto& child : children_)
131  fn(child.get());
132  }
133 
138  template <class Fun>
139  void each_child(Fun&& fn)
140  {
141  for (auto& child : children_)
142  fn(child.get());
143  }
144 
145  private:
149  std::vector<std::unique_ptr<node>> children_;
150 
154  const leaf_node* head_lexicon_ = nullptr;
155 
160  const node* head_constituent_ = nullptr;
161 };
162 }
163 }
164 
165 #endif
const node * head_constituent_
A pointer to the head constituent for this subtree (one of this tree's children)
Definition: internal_node.h:160
A single node in a parse tree for a sentence.
Definition: node.h:24
const leaf_node * head_lexicon() const
Definition: internal_node.cpp:68
void head(const node *n)
Sets the head constituent and head lexicon based on a node whose head lexicon has already been determ...
Definition: internal_node.cpp:88
void add_child(std::unique_ptr< node > child)
Adds a child to this node.
Definition: internal_node.cpp:32
void each_child(Fun &&fn) const
Runs a functor over each child.
Definition: internal_node.h:128
std::vector< std::unique_ptr< node > > children_
A list of the children of this node, from left to right.
Definition: internal_node.h:149
An internal node in a parse tree.
Definition: internal_node.h:28
internal_node(class_label cat, FwdIt begin, FwdIt end)
Constructs a new internal node by moving the children into the node from a sequence denoted by iterat...
Definition: internal_node.h:46
Template class to facilitate polymorphic cloning.
Definition: clonable.h:28
uint64_t num_children() const
Definition: internal_node.cpp:42
const leaf_node * head_lexicon_
A pointer to the head word for this subtree.
Definition: internal_node.h:154
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retreival, data mining, and other applications of text processing.
Definition: analyzer.h:24
const node * child(uint64_t idx) const
Definition: internal_node.cpp:37
void each_child(Fun &&fn)
Runs a functor over each child.
Definition: internal_node.h:139
A leaf node (pre-terminal) in a parse tree.
Definition: leaf_node.h:24
const node * head_constituent() const
Definition: internal_node.cpp:78