KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Head_semantic_event.h
Go to the documentation of this file.
1 #ifndef HEAD_SEMANTIC_EVENT_H_
2 #define HEAD_SEMANTIC_EVENT_H_
3 
12 #include "semantics/Event_traits.h"
13 #include <boost/make_shared.hpp>
14 
15 namespace semantics
16 {
17 
19  {
20  public:
21  boost::shared_ptr<Hsem_view> hsem_view;
22 
23  /*------------------------------------------------------------
24  * CONSTRUCTORS/DESTRUCTOR
25  *------------------------------------------------------------*/
26 
30  const Step_code_t& step_code,
31  const size_t& type_code,
32  const Node_data& parent_data,
33  const Sem_hash_pair& parent_sem_data,
34  const bool learn = true
35  );
36 
39  Head_semantic_event(const Data_type& data, bool learn = false)
40  : Semantic_step_event(data, learn)
41  {
42  update_event_views();
43  }
44 
45  /*------------------------------------------------------------
46  * COMPUTATION
47  *------------------------------------------------------------*/
48 
51  double log_probability(const bool& collins = false) const;
52 
53  /*------------------------------------------------------------
54  * MANIPULATORS
55  *------------------------------------------------------------*/
56 
60  const Sem_hash_pair& parent_semantics,
61  const Sem_hash_pair&
62  )
63  {
64  boost::tie(data_in_slot("PSEM"), data_in_slot("PSEMARGS")) =
65  parent_semantics;
66  update_event_views();
67  }
68 
72  {
73  if(learn_ == true)
74  {
75  hsem_view->unlearn();
76  learn_ = false;
77  }
78  }
79 
83  {
84  if(learn_ == false)
85  {
86  hsem_view->learn();
87  learn_ = true;
88  }
89  }
90 
94  {
95  hsem_view -> resample_table_assignment();
96  }
97 
98 
101  Event_ptr get_a_copy(bool learn = false) const
102  {
103  return boost::make_shared<Head_semantic_event>(data_, learn);
104  }
105 
106  /*------------------------------------------------------------
107  * DISPLAY
108  *------------------------------------------------------------*/
109 
112  void print_with_links(std::ostream& os) const;
113 
116  void print_view_counts(std::ostream& os) const;
117 
118  private:
119  const Key_slots::Map& var_map() const
120  {
122  }
123 
124  void update_event_views()
125  {
126  hsem_view =
127  boost::make_shared<Hsem_view>(
128  data_.begin(), data_.end(), learn_
129  );
130  }
131  };
132 };
133 
134 #endif
void print_view_counts(std::ostream &os) const
display the count data associated with this node
Definition: Head_semantic_event.cpp:46
std::vector< Value_type > Data_type
Definition: Tree_event.h:36
void resample_table_assignments()
resample CRP table assignments for all component event views
Definition: Head_semantic_event.h:93
bool learn_
Definition: Tree_event.h:183
double log_probability(const bool &collins=false) const
compute smoothed probability of this event
Definition: Head_semantic_event.cpp:29
Value_type & data_in_slot(const Key_type &variable)
return data in position as lvalue
Definition: Tree_event.cpp:119
void reacquire_view_counts()
release counts for associated views (treat as unobserved)
Definition: Head_semantic_event.h:82
Event_ptr get_a_copy(bool learn=false) const
produce a deep copy of this event and return a smart pointer
Definition: Head_semantic_event.h:101
Semantic_data_base::Hash_pair Sem_hash_pair
Definition: Tree_event.h:42
void print_with_links(std::ostream &os) const
display the immediate path to this node
Definition: Head_semantic_event.cpp:34
Definition: Semantic_step_event.h:15
boost::shared_ptr< Semantic_step_event > Event_ptr
Definition: Semantic_step_event.h:18
Data_type data_
Definition: Tree_event.h:182
Head_semantic_event(const Data_type &data, bool learn=false)
construct from data vector directly
Definition: Head_semantic_event.h:39
Definition: Head_semantic_event.h:18
Head_semantic_event(const Step_code_t &step_code, const size_t &type_code, const Node_data &parent_data, const Sem_hash_pair &parent_sem_data, const bool learn=true)
constructor from individual data elements
Definition: Head_semantic_event.cpp:12
void release_view_counts()
release counts for associated views (treat as unobserved)
Definition: Head_semantic_event.h:71
void update_semantic_context(const Sem_hash_pair &parent_semantics, const Sem_hash_pair &)
update semantic context features
Definition: Head_semantic_event.h:59
boost::tuple< Word_type, Label_type, Label_type > Node_data
Definition: Tree_event.h:41
boost::shared_ptr< Hsem_view > hsem_view
Definition: Head_semantic_event.h:21
boost::bimap< int, std::string > Map
Definition: Event_traits.h:34
Code
Definition: SemanticIO.h:54
static const Key_slots::Map variable_map
Definition: Event_traits.h:275