KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Unary_event.h
Go to the documentation of this file.
1 #ifndef UNARY_EVENT_H_
2 #define UNARY_EVENT_H_
3 
11 #include "semantics/Event_traits.h"
13 #include <boost/shared_ptr.hpp>
14 #ifdef USE_SEMANTICS
16 #endif
17 
18 namespace semantics
19 {
20 
22 {
23 public:
24  boost::shared_ptr<U_view> u_view;
25 
27 
31  const Node_data& node_data,
32 #ifdef USE_SEMANTICS
33  const Elaboration_tree::Hash_pair& sem_data,
34  const Elaboration_tree::Hash_pair& psem_data,
35 #endif
36  const Label_type& parent_label,
37  int id,
38  bool learn = true
39  );
40 
43  Unary_event(const Data_type& data, bool learn = false)
44  : Syntactic_event(data, 0, learn)
45  {
46  update_event_views();
47  }
48 
50 
54  double log_probability(const bool& collins = false) const;
55 
57 
61  const Sem_hash_pair& parent_semantics,
62  const Sem_hash_pair&
63  )
64  {
65  boost::tie(data_in_slot("PSEM"), data_in_slot("PSEMARGS")) =
66  parent_semantics;
67  update_event_views();
68  }
69 
73  {
74  if(learn_ == true)
75  {
76  u_view->unlearn();
77  learn_ = false;
78  }
79  }
80 
84  {
85  if(learn_ == false)
86  {
87  u_view->learn();
88  learn_ = true;
89  }
90  }
91 
95  {
96  u_view -> resample_table_assignment();
97  }
98 
101  Event_ptr get_a_copy(bool learn = false) const
102  {
103  return Event_ptr(new Unary_event(data_, learn));
104  }
105 
107 
110  void print(std::ostream& os) const;
111 
114  void print_with_links(std::ostream& os) const;
115 
118  void print_view_counts(std::ostream& os) const;
119 
120 private:
121  const Key_slots::Map& var_map() const
122  {
123  return U_traits::variable_map;
124  }
125 
126  void update_event_views()
127  {
128  u_view = boost::make_shared<U_view>(data_.begin(), data_.end(), learn_);
129  }
130 };
131 
132 };
133 
134 
135 #endif
boost::shared_ptr< Syntactic_event > Event_ptr
Definition: Syntactic_event.h:27
Event_ptr get_a_copy(bool learn=false) const
produce a deep copy of this event and return a smart pointer
Definition: Unary_event.h:101
void update_semantic_context(const Sem_hash_pair &parent_semantics, const Sem_hash_pair &)
Manipulators.
Definition: Unary_event.h:60
std::vector< Value_type > Data_type
Definition: Tree_event.h:36
bool learn_
Definition: Tree_event.h:183
boost::shared_ptr< U_view > u_view
Definition: Unary_event.h:24
double log_probability(const bool &collins=false) const
Computation.
Definition: Unary_event.cpp:39
Definition: Syntactic_event.h:20
Value_type & data_in_slot(const Key_type &variable)
return data in position as lvalue
Definition: Tree_event.cpp:119
Unary_event(const Data_type &data, bool learn=false)
construct from data vector directly
Definition: Unary_event.h:43
Value_type Label_type
Definition: Tree_event.h:39
Semantic_data_base::Hash_pair Sem_hash_pair
Definition: Tree_event.h:42
void release_view_counts()
release counts for associated views (i.e., treat as unobserved)
Definition: Unary_event.h:72
Definition: Unary_event.h:21
void print_with_links(std::ostream &os) const
display the immediate path to this node
Definition: Unary_event.cpp:50
void resample_table_assignments()
resample CRP table assignments for all component event views
Definition: Unary_event.h:94
#define USE_SEMANTICS
Definition: Event_traits.h:4
void print(std::ostream &os) const
Display functions.
Definition: Unary_event.cpp:44
Data_type data_
Definition: Tree_event.h:182
static const Key_slots::Map variable_map
Definition: Event_traits.h:134
boost::tuple< Word_type, Label_type, Label_type > Node_data
Definition: Tree_event.h:41
void print_view_counts(std::ostream &os) const
display the count data associated with this node
Definition: Unary_event.cpp:64
Semantic_data_base::Hash_pair Hash_pair
Definition: Elaboration_tree.h:32
Unary_event(const Node_data &node_data, const Label_type &parent_label, int id, bool learn=true)
Constructors and destructors.
Definition: Unary_event.cpp:13
boost::bimap< int, std::string > Map
Definition: Event_traits.h:34
void reacquire_view_counts()
reacquire counts for associated events (i.e., treat as observed)
Definition: Unary_event.h:83