KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Root_event.h
Go to the documentation of this file.
1 #ifndef ROOT_EVENT_H_
2 #define ROOT_EVENT_H_
3 
13 #include "semantics/Event_view.h"
14 #include "semantics/Event_traits.h"
15 #include <boost/shared_ptr.hpp>
16 #ifdef USE_SEMANTICS
18 #endif
19 
20 
21 namespace semantics
22 {
23 
25 {
26 public:
27  boost::shared_ptr<S1_view> s1_view;
28  boost::shared_ptr<S2_view> s2_view;
29 
30  /*------------------------------------------------------------
31  * CONSTRUCTORS AND DESTRUCTOR
32  *------------------------------------------------------------*/
33 
36 #ifdef USE_SEMANTICS
37  Root_event(
38  const Node_data& node_data,
39  const Semantic_data_base::Hash_pair& sem_data,
40  int id,
41  bool learn = true);
42 #endif
43  Root_event(
44  const Node_data& node_data,
45  int id,
46  bool learn = true);
47 
50  Root_event(const Data_type& data, bool learn = false)
51  : Syntactic_event(data, 0, learn)
52  {
53  update_event_views();
54  }
55 
59 
60  /*------------------------------------------------------------
61  * COMPUTATION
62  *------------------------------------------------------------*/
63 
67  double log_probability(const bool& collins = false) const;
68 
69  /*------------------------------------------------------------
70  * DISPLAY
71  *------------------------------------------------------------*/
72 
75  void print(std::ostream& os) const;
76 
79  void print_with_links(std::ostream& os) const;
80 
83  void print_view_counts(std::ostream& os) const;
84 
85  /*------------------------------------------------------------
86  * MANIPULATORS
87  *------------------------------------------------------------*/
88 
92  {
93  if(learn_ == true)
94  {
95  s1_view -> unlearn();
96  s2_view -> unlearn();
97  learn_ = false;
98  }
99  }
100 
104  {
105  if(learn_ == false)
106  {
107  s1_view -> learn();
108  s2_view -> learn();
109  learn_ = true;
110  }
111  }
112 
116  {
117  s1_view -> resample_table_assignment();
118  s2_view -> resample_table_assignment();
119  }
120 
123  Event_ptr get_a_copy(bool learn = false) const
124  {
125  return Event_ptr(new Root_event(data_, learn));
126  }
127 
128 private:
129  const Key_slots::Map& var_map() const
130  {
132  }
133 
134  void update_event_views()
135  {
136  s1_view =
137  boost::make_shared<S1_view>(data_.begin() + 1, data_.end(), learn_);
138  s2_view =
139  boost::make_shared<S2_view>(data_.begin(), data_.end(), learn_);
140  }
141 
142 };
143 
144 };
145 
146 #endif
boost::shared_ptr< Syntactic_event > Event_ptr
Definition: Syntactic_event.h:27
boost::tuple< size_t, size_t > Hash_pair
Definition: Semantic_elaboration.h:114
void release_view_counts()
release counts for associated views (i.e., treat as unobserved)
Definition: Root_event.h:91
Root_event(const Node_data &node_data, int id, bool learn=true)
constructor
Definition: Root_event.cpp:12
std::vector< Value_type > Data_type
Definition: Tree_event.h:36
bool learn_
Definition: Tree_event.h:183
void reacquire_view_counts()
reacquire counts for associated views (i.e., treat as observed)
Definition: Root_event.h:103
double log_probability(const bool &collins=false) const
compute smoothed probability of this event
Definition: Root_event.cpp:35
Definition: Syntactic_event.h:20
Root_event(const Data_type &data, bool learn=false)
data constructor
Definition: Root_event.h:50
static const Key_slots::Map variable_map
Definition: Event_traits.h:103
~Root_event()
default destructor
Definition: Root_event.h:58
Event_ptr get_a_copy(bool learn=false) const
return a smart pointer to a deep copy of this instance
Definition: Root_event.h:123
void print_view_counts(std::ostream &os) const
print counts of various event "views"
Definition: Root_event.cpp:59
Data_type data_
Definition: Tree_event.h:182
boost::shared_ptr< S1_view > s1_view
Definition: Root_event.h:27
void print(std::ostream &os) const
print bare node information
Definition: Root_event.cpp:41
void print_with_links(std::ostream &os) const
print node in context
Definition: Root_event.cpp:47
boost::tuple< Word_type, Label_type, Label_type > Node_data
Definition: Tree_event.h:41
Definition: Root_event.h:24
boost::bimap< int, std::string > Map
Definition: Event_traits.h:34
void resample_table_assignments()
resample CRP table assignments for all component event views
Definition: Root_event.h:115
boost::shared_ptr< S2_view > s2_view
Definition: Root_event.h:28