KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tree_event.h
Go to the documentation of this file.
1 #ifndef TREE_EVENT_H_
2 #define TREE_EVENT_H_
3 
11 #include "semantics/Lexicon_db.h"
14 #include "semantics/Event_traits.h"
15 #include <boost/make_shared.hpp>
16 #include <boost/array.hpp>
17 #include <boost/tuple/tuple.hpp>
18 #include <string>
19 #include <vector>
20 #include <iostream>
21 
22 namespace semantics
23 {
24 
25 
27 {
28 public:
29  /*------------------------------------------------------------
30  * TYPEDEFS
31  *------------------------------------------------------------*/
32 
33  typedef boost::shared_ptr<Tree_event> Self_ptr;
36  typedef std::vector<Value_type> Data_type;
41  typedef boost::tuple<Word_type, Label_type, Label_type> Node_data;
43 public:
44  /*------------------------------------------------------------
45  * STATIC PUBLIC VARIABLES / ACCESSORS
46  *------------------------------------------------------------*/
47 
48  static bool VERBOSE;
49  static Lexicon_db& lexicon();
50  static Nonterminal_db& nt_lexicon();
51  static const int WORD = 0;
52  static const int TAG = 1;
53  static const int LABEL = 2;
54  static const int HEAD = 0;
55  static const int ARGS = 1;
56 
57 protected:
58 
59  /*------------------------------------------------------------
60  * CONSTRUCTORS/DESTRUCTOR
61  *------------------------------------------------------------*/
62 
65  Tree_event(bool learn);
66 
69  Tree_event(const Data_type& data, bool learn);
70 
71 public:
74  virtual ~Tree_event(){}
75 
76  /*------------------------------------------------------------
77  * COMPUTATION
78  *------------------------------------------------------------*/
79 
83  virtual double log_probability(
84  const bool& collins = false
85  ) const = 0;
86 
87  /*------------------------------------------------------------
88  * MANIPULATORS
89  *------------------------------------------------------------*/
90 
93  virtual void release_view_counts(){}
96  virtual void reacquire_view_counts(){}
97 
100  virtual void update_event_views() = 0;
101 
105  const Sem_hash_pair&,
106  const Sem_hash_pair&
107  ) {}
108 
111  virtual void resample_table_assignments() = 0;
112 
113  /*------------------------------------------------------------
114  * DISPLAY
115  *------------------------------------------------------------*/
116 
119  virtual void print_view_counts(std::ostream&) const = 0;
120 
123  virtual void print(std::ostream& os) const = 0;
124 
127  virtual void print_with_links(std::ostream&) const {}
128 
129  /*------------------------------------------------------------
130  * FRIEND FUNCTIONS
131  *------------------------------------------------------------*/
132 
135  friend
136  std::ostream& operator<<(std::ostream& os, Tree_event& e)
137  {
138  e.print_with_links(os);
139  return os;
140  }
141 
142  friend
143  std::ostream& operator<<(std::ostream& os, Tree_event* e)
144  {
145  e -> print_with_links(os);
146  return os;
147  }
148 
149  friend
150  std::ostream& operator<<(std::ostream& os, Self_ptr e)
151  {
152  e -> print_with_links(os);
153  return os;
154  }
155 
156 protected:
159  virtual const Key_slots::Map& var_map() const = 0;
162  const Key_type& data_as_word(const Key_type& variable) const;
165  const Key_type& data_as_nonterminal(const Key_type& variable) const;
168  const Key_type data_as_semantic_step(const Key_type& variable) const;
171  const Key_type& data_as_semantic_head(const Key_type& variable) const;
174  const Key_type& data_as_semantic_args(const Key_type& variable) const;
177  const Value_type& data_as_code(const Key_type& variable) const;
180  Value_type& data_in_slot(const Key_type& variable);
181 
183  bool learn_;
184 };
185 
186 
187 /*------------------------------------------------------------
188  * FREE FUNCTIONS
189  *------------------------------------------------------------*/
190 
191 template<class T>
193 {
194  T::VERBOSE = verbose;
195 }
196 
197 template<class T>
198 std::ostream& operator<<(std::ostream& os, const std::vector<T>& c)
199 {
200  os << "(";
201  for(typename std::vector<T>::const_iterator it = c.begin();
202  it != c.end(); it++)
203  {
204  os << *it << ",";
205  }
206  os << ")";
207  return os;
208 }
209 
210 };
211 
212 #endif
boost::shared_ptr< Tree_event > Self_ptr
Definition: Tree_event.h:33
const Value_type & data_as_code(const Key_type &variable) const
look up data entry in position <variable> and return as code
Definition: Tree_event.cpp:99
boost::tuple< size_t, size_t > Hash_pair
Definition: Semantic_elaboration.h:114
Tree_event(bool learn)
construct an empty event with data to be filled at derived level
Definition: Tree_event.cpp:37
virtual void release_view_counts()
turn off learn_ and remove counts from database
Definition: Tree_event.h:93
int verbose
Definition: triangle.c:724
std::vector< Value_type > Data_type
Definition: Tree_event.h:36
static bool VERBOSE
Definition: Tree_event.h:48
const Key_type data_as_semantic_step(const Key_type &variable) const
look up data entry in position <variable> and return as step code
Definition: Tree_event.cpp:57
bool learn_
Definition: Tree_event.h:183
virtual ~Tree_event()
virtual destructor
Definition: Tree_event.h:74
virtual void update_event_views()=0
update event views
static const int LABEL
Definition: Tree_event.h:53
friend std::ostream & operator<<(std::ostream &os, Tree_event *e)
Definition: Tree_event.h:143
const Key_type & data_as_nonterminal(const Key_type &variable) const
look up data entry in position <variable> and return as nt
Definition: Tree_event.cpp:50
Value_type & data_in_slot(const Key_type &variable)
return data in position as lvalue
Definition: Tree_event.cpp:119
void set_verbosity(bool verbose)
Definition: Tree_event.h:192
virtual void print(std::ostream &os) const =0
display this node's data in human readable form
std::string Key_type
Definition: Token_map.h:23
virtual void print_view_counts(std::ostream &) const =0
pure virtual dummy — instantiated versions display count data
Definition: Tree_event.h:26
Value_type Label_type
Definition: Tree_event.h:39
Semantic_data_base::Hash_pair Sem_hash_pair
Definition: Tree_event.h:42
friend std::ostream & operator<<(std::ostream &os, Self_ptr e)
Definition: Tree_event.h:150
Value_type Distance_type
Definition: Tree_event.h:40
static const int TAG
Definition: Tree_event.h:52
size_t Val_type
Definition: Token_map.h:24
virtual void update_semantic_context(const Sem_hash_pair &, const Sem_hash_pair &)
update semantic parent and head (if they exist)
Definition: Tree_event.h:104
virtual void reacquire_view_counts()
turn on learn_ and add counts to database
Definition: Tree_event.h:96
static const int ARGS
Definition: Tree_event.h:55
virtual double log_probability(const bool &collins=false) const =0
compute log probability of this event
const Key_type & data_as_semantic_head(const Key_type &variable) const
look up data entry in position <variable> and return as semhead
Definition: Tree_event.cpp:66
virtual void print_with_links(std::ostream &) const
virtual function, does nothing at base level
Definition: Tree_event.h:127
Data_type data_
Definition: Tree_event.h:182
Definition: Lexicon_db.h:17
static const int WORD
Definition: Tree_event.h:51
virtual void resample_table_assignments()=0
resample CRP table assignments for all component event views
Value_type Tag_type
Definition: Tree_event.h:38
static const int HEAD
Definition: Tree_event.h:54
Token_map::Key_type Key_type
Definition: Tree_event.h:35
boost::tuple< Word_type, Label_type, Label_type > Node_data
Definition: Tree_event.h:41
static Lexicon_db & lexicon()
Definition: Tree_event.cpp:20
virtual const Key_slots::Map & var_map() const =0
return reference to the map between variable names and positions
Definition: Nonterminal_db.h:16
boost::bimap< int, std::string > Map
Definition: Event_traits.h:34
friend std::ostream & operator<<(std::ostream &os, Tree_event &e)
display this node in tree context
Definition: Tree_event.h:136
const Key_type & data_as_semantic_args(const Key_type &variable) const
look up data entry in position <variable> and return as semargs
Definition: Tree_event.cpp:82
Token_map::Val_type Value_type
Definition: Tree_event.h:34
const Key_type & data_as_word(const Key_type &variable) const
look up data entry in position <variable> and return as word
Definition: Tree_event.cpp:43
static Nonterminal_db & nt_lexicon()
Definition: Tree_event.cpp:26
Value_type Word_type
Definition: Tree_event.h:37