KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Event_parser.h
Go to the documentation of this file.
1 #ifndef EVENT_PARSER_H_
2 #define EVENT_PARSER_H_
3 
12 #include <boost/shared_ptr.hpp>
13 #include <string>
14 #include <vector>
15 #include <fstream>
16 #include <sstream>
17 #include <map>
18 
19 #define PRINT(a) std::cout << #a << " = " << a << std::endl
20 
21 namespace semantics
22 {
23 
24  class Lexicon_db;
25  class Nonterminal_db;
26 
30  class Event_db
31  {
32  // Pointer to generic Syntactic_event
33  typedef boost::shared_ptr<Syntactic_event> Event_ptr;
34  // Containers for syntactic event pointers
35  typedef std::vector<Event_ptr> Event_list;
36  // The low frequency word map
37  typedef std::map<Lexicon_db::Val_type, bool> LF_map_t;
38  public:
39 
42  Event_db() : event_list_(), tree_list_(), num_events_(0), learn_(false)
43  {}
44 
50  std::string event_file,
51  std::string lexicon_file,
52  bool learn = true,
53  int num_lines = 10000
54  ) : event_list_(), tree_list_(), num_events_(0), learn_(learn)
55  {
56  read_lexicon(lexicon_file);
57  event_list_.push_back(Event_ptr());
58  read_events(event_file, num_lines);
59  }
60 
64  Event_ptr get_tree(const int& i) const {return tree_list_[i];}
65 
68  void print_tree(const int& i, std::ostream& os) const
69  {
70  tree_list_[i] -> print_subtree(os);
71  }
72 
75  size_t num_trees() const {return tree_list_.size();}
76 
79  size_t num_events() const {return num_events_;}
80  public:
84 
88  {
90  }
93  static LF_map_t& lf_word_map()
94  {
95  static boost::shared_ptr<LF_map_t> lfwm(new LF_map_t);
96  return *lfwm;
97  }
98  static bool VERBOSE;
99  private:
100  Event_list event_list_;
101  Event_list tree_list_;
102  size_t num_events_;
103  bool learn_;
107  void read_lexicon(const std::string& lexicon_file);
108 
113  void read_events(const std::string& event_file, const int& num_lines);
114 
118  bool read_event(std::istringstream& event_stream);
119 
123  bool read_event_f(std::istringstream&)
124  {
125  num_events_ += event_list_.size();
126  event_list_.clear();
127  return true;
128  }
129 
134  bool read_event_u(std::istringstream& input);
135 
140  bool read_event_d(std::istringstream& input);
141  };
142 
144 
145  Event_db process_event_file(
146  std::string train_path,
147  std::string lexicon_file,
148  size_t max_events,
149  std::string test_path = ""
150  );
151 };
152 
153 #endif
static bool VERBOSE
Definition: Event_parser.h:98
Database class to read and count parse tree events.
Definition: Event_parser.h:30
size_t num_trees() const
returns number of trees in list
Definition: Event_parser.h:75
Event_db(std::string event_file, std::string lexicon_file, bool learn=true, int num_lines=10000)
constructs an event database object
Definition: Event_parser.h:49
static LF_map_t & lf_word_map()
accessor to a global map flagging low frequency words
Definition: Event_parser.h:93
Event_ptr get_tree(const int &i) const
gets pointer to tree in position i in the list
Definition: Event_parser.h:64
static Lexicon_db & lexicon()
returns a reference to the map between words and codes
Definition: Event_parser.h:83
size_t num_events() const
returns number of events
Definition: Event_parser.h:79
Definition: Lexicon_db.h:17
Event_db()
default ctor, creates empty database
Definition: Event_parser.h:42
static Nonterminal_db & nt_lexicon()
returns a reference to the map between nonterminals and codes
Definition: Event_parser.h:87
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
static Lexicon_db & lexicon()
Definition: Tree_event.cpp:20
Event_db process_event_file(std::string train_path, std::string lexicon_file, size_t max_events, std::string test_path)
Free_function definitions.
Definition: Event_parser.cpp:272
Definition: Nonterminal_db.h:16
void print_tree(const int &i, std::ostream &os) const
print tree in position i to ostream os
Definition: Event_parser.h:68
static Nonterminal_db & nt_lexicon()
Definition: Tree_event.cpp:26