KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Dependency_event.h
Go to the documentation of this file.
1 #ifndef DEPENDENCY_EVENT_H_
2 #define DEPENDENCY_EVENT_H_
3 
11 #include "semantics/Event_view.h"
12 #include "semantics/Event_traits.h"
14 #include <boost/shared_ptr.hpp>
15 #include <boost/array.hpp>
16 #include <boost/tuple/tuple.hpp>
17 #include <string>
18 #include <vector>
19 #ifdef USE_SEMANTICS
21 #endif
22 
23 namespace semantics
24 {
25 
27 {
28 public:
29  boost::shared_ptr<D1_view> d1_view;
30  boost::shared_ptr<D2_view> d2_view;
31  boost::shared_ptr<PCC1_view> punc1_view;
32  boost::shared_ptr<PCC2_view> punc2_view;
33  boost::shared_ptr<PCC1_view> coord1_view;
34  boost::shared_ptr<PCC2_view> coord2_view;
35 
37 
41  const Node_data& node_data,
42  const Node_data& parent_data,
43  const Node_data& head_data,
44 #ifdef USE_SEMANTICS
45  const Elaboration_tree::Hash_pair& sem_data,
46  const Elaboration_tree::Hash_pair& parent_sem_data,
47  const Elaboration_tree::Hash_pair& head_sem_data,
48 #endif
49  const Distance_type& distance,
50  bool punc_flag,
51  const Node_data& punc_data,
52  bool coord_flag,
53  const Node_data& coord_data,
54  int id,
55  bool learn = true
56  );
57 
59  const Data_type& data,
60  const Data_type& punc_data,
61  const Data_type& coord_data,
62  bool learn = false
63  ): Syntactic_event(data, 0, learn),
64  pcc_data_(punc_data),
65  coord_data_(coord_data)
66  {
67  update_event_views();
68  }
69 
71 
74  double log_probability(const bool& collins = false) const;
75 
77 
81  const Semantic_data_base::Hash_pair& parent_semantics,
82  const Semantic_data_base::Hash_pair& head_semantics
83  )
84  {
85  boost::tie(data_in_slot("PSEM"), data_in_slot("PSEMARGS")) =
86  parent_semantics;
87  boost::tie(data_in_slot("HSEM"), data_in_slot("HSEMARGS")) =
88  head_semantics;
89  update_event_views();
90  }
91 
95  {
96  if(learn_ == true)
97  {
98  d1_view->unlearn();
99  if(d2_view != NULL) d2_view->unlearn();
100  learn_ = false;
101  }
102  }
103 
107  {
108  if(learn_ == false)
109  {
110  d1_view->learn();
111  if(d2_view != NULL) d2_view->learn();
112  learn_ = true;
113  }
114  }
115 
119  {
120  d1_view -> resample_table_assignment();
121  d2_view -> resample_table_assignment();
122  }
123 
124 
125  Event_ptr get_a_copy(bool learn = false) const
126  {
127  return Event_ptr(
128  new Dependency_event(data_, pcc_data_, coord_data_, learn));
129  }
130 
132 
135  void print_with_links(std::ostream& os) const;
136 
139  void print_view_counts(std::ostream& os) const;
140 
141 private:
142  const Key_slots::Map& var_map() const
143  {
145  }
146 
147  void update_event_views();
148 
149  Data_type pcc_data_;
150  Data_type coord_data_;
151 };
152 
153 };
154 
155 #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
Definition: Dependency_event.h:26
std::vector< Value_type > Data_type
Definition: Tree_event.h:36
boost::shared_ptr< PCC2_view > coord2_view
Definition: Dependency_event.h:34
static const Key_slots::Map variable_map
Definition: Event_traits.h:197
bool learn_
Definition: Tree_event.h:183
Definition: Syntactic_event.h:20
void resample_table_assignments()
resample CRP table assignments for all component event views
Definition: Dependency_event.h:118
Value_type & data_in_slot(const Key_type &variable)
return data in position as lvalue
Definition: Tree_event.cpp:119
void reacquire_view_counts()
reacquire counts for associated events (i.e., treat as observed)
Definition: Dependency_event.h:106
Value_type Distance_type
Definition: Tree_event.h:40
void print_with_links(std::ostream &os) const
Display functions.
Definition: Dependency_event.cpp:84
Dependency_event(const Data_type &data, const Data_type &punc_data, const Data_type &coord_data, bool learn=false)
Definition: Dependency_event.h:58
Event_ptr get_a_copy(bool learn=false) const
return a pointer to a deep copy of this instance
Definition: Dependency_event.h:125
#define USE_SEMANTICS
Definition: Event_traits.h:4
void release_view_counts()
release counts for associated views (i.e., treat as unobserved)
Definition: Dependency_event.h:94
void update_semantic_context(const Semantic_data_base::Hash_pair &parent_semantics, const Semantic_data_base::Hash_pair &head_semantics)
Manipulation.
Definition: Dependency_event.h:80
Data_type data_
Definition: Tree_event.h:182
boost::shared_ptr< D1_view > d1_view
Definition: Dependency_event.h:29
boost::shared_ptr< PCC2_view > punc2_view
Definition: Dependency_event.h:32
Dependency_event(const Node_data &node_data, const Node_data &parent_data, const Node_data &head_data, const Distance_type &distance, bool punc_flag, const Node_data &punc_data, bool coord_flag, const Node_data &coord_data, int id, bool learn=true)
Constructors and destructors.
Definition: Dependency_event.cpp:8
boost::shared_ptr< D2_view > d2_view
Definition: Dependency_event.h:30
boost::shared_ptr< PCC1_view > coord1_view
Definition: Dependency_event.h:33
boost::tuple< Word_type, Label_type, Label_type > Node_data
Definition: Tree_event.h:41
boost::shared_ptr< PCC1_view > punc1_view
Definition: Dependency_event.h:31
double log_probability(const bool &collins=false) const
Calculation.
Definition: Dependency_event.cpp:68
Semantic_data_base::Hash_pair Hash_pair
Definition: Elaboration_tree.h:32
void print_view_counts(std::ostream &os) const
display count information associated with this node
Definition: Dependency_event.cpp:105
boost::bimap< int, std::string > Map
Definition: Event_traits.h:34