KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Syntactic_event.h
Go to the documentation of this file.
1 #ifndef SYNTACTIC_EVENT_H_
2 #define SYNTACTIC_EVENT_H_
3 
11 #include "semantics/Tree_event.h"
12 #include "semantics/Event_traits.h"
13 #include <deque>
14 #include <iosfwd>
15 
16 namespace semantics
17 {
18 
19 
21 {
22 public:
23  /*------------------------------------------------------------
24  * TYPEDEFS
25  *------------------------------------------------------------*/
26 
27  typedef boost::shared_ptr<Syntactic_event> Event_ptr;
28  typedef Event_ptr Self_ptr; //temporary redundant typedef
29  typedef std::deque<Self_ptr> Event_ptr_container;
30 
31  /*------------------------------------------------------------
32  * STATIC MEMBERS
33  *------------------------------------------------------------*/
34 
35  static bool VERBOSE;
36 protected:
37 
38  /*------------------------------------------------------------
39  * CONSTRUCTORS/DESTRUCTOR
40  *------------------------------------------------------------*/
41 
44  Syntactic_event(int id, bool learn);
45 
48  Syntactic_event(const Data_type& data, int id, bool learn);
49 
52  virtual ~Syntactic_event() {};
53 
54 public:
55  /*------------------------------------------------------------
56  * ACCESSORS
57  *------------------------------------------------------------*/
58 
61  int id() const {return id_;};
62 
63 
66  size_t head_pos() const {return head_pos_;}
67 
68  /*------------------------------------------------------------
69  * MANIPULATORS
70  *------------------------------------------------------------*/
71 
74  void add_head_child(const Event_ptr head)
75  {
76  assert(children_.empty());
77  children_.push_back(head);
78  head_pos_ = 0;
79  }
80 
85  void add_dependency_child(const Event_ptr child, bool on_left = false)
86  {
87  if(on_left)
88  {
89  children_.push_front(child);
90  ++head_pos_;
91  }
92  else
93  {
94  children_.push_back(child);
95  }
96  }
97 
100  virtual Event_ptr get_a_copy(bool learn = false) const = 0;
101 
104  virtual void update_semantics(const Sem_hash_pair&);
105 
108  virtual void update_event_views() {};
109 
110  /*------------------------------------------------------------
111  * CALCULATION
112  *------------------------------------------------------------*/
113 
116  virtual double subtree_log_probability() const;
117 
118 
119  /*------------------------------------------------------------
120  * DISPLAY FUNCTIONS
121  *------------------------------------------------------------*/
122 
125  virtual void print_view_counts(std::ostream&) const = 0;
126 
129  virtual void print_subtree_view_counts(
130  std::ostream&,
131  int indent_level = 0
132  ) const;
133 
136  virtual void print(std::ostream& os) const;
137 
140  virtual void print_semantics(std::ostream& os) const;
141 
144  virtual void print_with_links(std::ostream&) const {}
145 
148  virtual void print_subtree(std::ostream& os, int indent_level = 0) const;
149 
152  virtual void print_constituency_tree_with_head(std::ostream& os) const;
153 
156  void print_child_constituency_trees(std::ostream& os) const;
157 
158  /*------------------------------------------------------------
159  * FRIEND FUNCTIONS
160  *------------------------------------------------------------*/
161 
164  friend
165  std::ostream& operator<<(std::ostream& os, const Syntactic_event& e)
166  {
167  e.print_with_links(os);
168  return os;
169  }
170  friend
171  std::ostream& operator<<(std::ostream& os, const Syntactic_event* e)
172  {
173  e -> print_with_links(os);
174  return os;
175  }
176  friend
177  std::ostream& operator<<(std::ostream& os, const Event_ptr e)
178  {
179  e -> print_with_links(os);
180  return os;
181  }
182 
183 protected:
186  virtual const Key_slots::Map& var_map() const = 0;
187 
190  void print_child_trees(std::ostream& os, int indent_level) const;
191 
192  int id_;
193  size_t head_pos_;
195 };
196 
197 };
198 
199 #endif
int id() const
return unique id
Definition: Syntactic_event.h:61
boost::shared_ptr< Syntactic_event > Event_ptr
Definition: Syntactic_event.h:27
void add_head_child(const Event_ptr head)
add the first child
Definition: Syntactic_event.h:74
std::vector< Value_type > Data_type
Definition: Tree_event.h:36
virtual void print_subtree(std::ostream &os, int indent_level=0) const
recursively print full subtree
Definition: Syntactic_event.cpp:74
virtual void print_with_links(std::ostream &) const
virtual function, does nothing at base level
Definition: Syntactic_event.h:144
virtual ~Syntactic_event()
virtual destructor
Definition: Syntactic_event.h:52
void print_child_trees(std::ostream &os, int indent_level) const
print children subtrees in sequence
Definition: Syntactic_event.cpp:128
Definition: Syntactic_event.h:20
Syntactic_event(int id, bool learn)
construct an empty event with data to be filled at derived level
Definition: Syntactic_event.cpp:21
virtual void print(std::ostream &os) const
display this node's data in human readable form
Definition: Syntactic_event.cpp:57
size_t head_pos_
Definition: Syntactic_event.h:193
virtual void update_semantics(const Sem_hash_pair &)
replace semantic data with new data and update views
Definition: Syntactic_event.cpp:50
virtual Event_ptr get_a_copy(bool learn=false) const =0
return a pointer to a deep copy of this instance
Definition: Tree_event.h:26
void add_dependency_child(const Event_ptr child, bool on_left=false)
add a pointer to a new child which is not the head
Definition: Syntactic_event.h:85
virtual void print_subtree_view_counts(std::ostream &, int indent_level=0) const
show counts at each node, recursively descending
Definition: Syntactic_event.cpp:112
Semantic_data_base::Hash_pair Sem_hash_pair
Definition: Tree_event.h:42
virtual const Key_slots::Map & var_map() const =0
return reference to the map between variable names and positions
Event_ptr_container children_
Definition: Syntactic_event.h:194
friend std::ostream & operator<<(std::ostream &os, const Event_ptr e)
Definition: Syntactic_event.h:177
friend std::ostream & operator<<(std::ostream &os, const Syntactic_event &e)
display this node in tree context
Definition: Syntactic_event.h:165
virtual void update_event_views()
update event views
Definition: Syntactic_event.h:108
size_t head_pos() const
return head position
Definition: Syntactic_event.h:66
virtual double subtree_log_probability() const
get log probability of entire subtree
Definition: Syntactic_event.cpp:34
void print_child_constituency_trees(std::ostream &os) const
recursively print subtree as constituency tree with head info
Definition: Syntactic_event.cpp:103
friend std::ostream & operator<<(std::ostream &os, const Syntactic_event *e)
Definition: Syntactic_event.h:171
virtual void print_semantics(std::ostream &os) const
display the semantic node associated with this node
Definition: Syntactic_event.cpp:67
static bool VERBOSE
Static initialization.
Definition: Syntactic_event.h:35
virtual void print_view_counts(std::ostream &) const =0
pure virtual dummy — instantiated versions display count data
std::deque< Self_ptr > Event_ptr_container
Definition: Syntactic_event.h:29
Event_ptr Self_ptr
Definition: Syntactic_event.h:28
virtual void print_constituency_tree_with_head(std::ostream &os) const
recursively print subtree as constituency tree with head info
Definition: Syntactic_event.cpp:85
boost::bimap< int, std::string > Map
Definition: Event_traits.h:34
int id_
Definition: Syntactic_event.h:192