KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Mod_semantic_event.h
Go to the documentation of this file.
1 #ifndef MOD_SEMANTIC_EVENT_H_
2 #define MOD_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<Msem_view> msem_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 Node_data& head_data,
34  const Sem_hash_pair& parent_sem_data,
35  const Sem_hash_pair& head_sem_data,
36  const Distance_type& dist,
37  bool learn = true
38  );
39 
42  Mod_semantic_event(const Data_type& data, bool learn = false)
43  : Semantic_step_event(data, learn)
44  {
45  update_event_views();
46  }
47 
48  /*------------------------------------------------------------
49  * COMPUTATION
50  *------------------------------------------------------------*/
51 
54  double log_probability(const bool& collins = false) const;
55 
56  /*------------------------------------------------------------
57  * MANIPULATORS
58  *------------------------------------------------------------*/
59 
63  const Semantic_data_base::Hash_pair& parent_semantics,
64  const Semantic_data_base::Hash_pair& head_semantics
65  )
66  {
67  boost::tie(data_in_slot("PSEM"), data_in_slot("PSEMARGS")) =
68  parent_semantics;
69  boost::tie(data_in_slot("HSEM"), data_in_slot("HSEMARGS")) =
70  head_semantics;
71  update_event_views();
72  }
73 
77  {
78  if(learn_ == true)
79  {
80  msem_view->unlearn();
81  learn_ = false;
82  }
83  }
84 
88  {
89  if(learn_ == false)
90  {
91  msem_view->learn();
92  learn_ = true;
93  }
94  }
95 
99  {
100  msem_view -> resample_table_assignment();
101  }
102 
105  Event_ptr get_a_copy(bool learn = false) const
106  {
107  return boost::make_shared<Mod_semantic_event>(data_, learn);
108  }
109 
110  /*------------------------------------------------------------
111  * DISPLAY FUNCTIONS
112  *------------------------------------------------------------*/
113 
116  void print_with_links(std::ostream& os) const;
117 
120  void print_view_counts(std::ostream& os) const;
121 
122  private:
123  const Key_slots::Map& var_map() const
124  {
126  }
127 
128  void update_event_views()
129  {
130  msem_view =
131  boost::make_shared<Msem_view>(
132  data_.begin(), data_.end(), learn_
133  );
134  }
135  };
136 };
137 
138 #endif
boost::tuple< size_t, size_t > Hash_pair
Definition: Semantic_elaboration.h:114
void update_semantic_context(const Semantic_data_base::Hash_pair &parent_semantics, const Semantic_data_base::Hash_pair &head_semantics)
replace semantic context with new data and update views
Definition: Mod_semantic_event.h:62
std::vector< Value_type > Data_type
Definition: Tree_event.h:36
void print_with_links(std::ostream &os) const
display the immediate path to this node
Definition: Mod_semantic_event.cpp:40
bool learn_
Definition: Tree_event.h:183
Event_ptr get_a_copy(bool learn=false) const
produce a deep copy of this event and return a smart pointer
Definition: Mod_semantic_event.h:105
boost::shared_ptr< Msem_view > msem_view
Definition: Mod_semantic_event.h:21
Value_type & data_in_slot(const Key_type &variable)
return data in position as lvalue
Definition: Tree_event.cpp:119
double dist(const pt a, const pt b)
compute approx. Great Circle distance between two UTM points
Definition: layer.cpp:45
Semantic_data_base::Hash_pair Sem_hash_pair
Definition: Tree_event.h:42
Value_type Distance_type
Definition: Tree_event.h:40
void resample_table_assignments()
resample CRP table assignments for all component event views
Definition: Mod_semantic_event.h:98
Mod_semantic_event(const Step_code_t &step_code, const size_t &type_code, const Node_data &parent_data, const Node_data &head_data, const Sem_hash_pair &parent_sem_data, const Sem_hash_pair &head_sem_data, const Distance_type &dist, bool learn=true)
constructor from individual data elements
Definition: Mod_semantic_event.cpp:12
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
void release_view_counts()
release counts for associated views (treat as unobserved)
Definition: Mod_semantic_event.h:76
Mod_semantic_event(const Data_type &data, bool learn=false)
construct from data vector directly
Definition: Mod_semantic_event.h:42
void print_view_counts(std::ostream &os) const
display the count data associated with this node
Definition: Mod_semantic_event.cpp:55
static const Key_slots::Map variable_map
Definition: Event_traits.h:301
double log_probability(const bool &collins=false) const
compute smoothed probability of this event
Definition: Mod_semantic_event.cpp:35
boost::tuple< Word_type, Label_type, Label_type > Node_data
Definition: Tree_event.h:41
Definition: Mod_semantic_event.h:18
void reacquire_view_counts()
release counts for associated views (treat as unobserved)
Definition: Mod_semantic_event.h:87
boost::bimap< int, std::string > Map
Definition: Event_traits.h:34
Code
Definition: SemanticIO.h:54