ModErn Text Analysis
META Enumerates Textual Applications
state.h
Go to the documentation of this file.
1 
9 #ifndef META_PARSER_STATE_H_
10 #define META_PARSER_STATE_H_
11 
12 #include <memory>
13 #include <vector>
14 
15 #include "parser/transition.h"
16 #include "parser/trees/node.h"
18 #include "sequence/sequence.h"
19 #include "util/persistent_stack.h"
20 
21 namespace meta
22 {
23 namespace parser
24 {
25 
36 class state
37 {
38  public:
43 
47  using queue_type = std::vector<std::unique_ptr<leaf_node>>;
48 
53  state(const parse_tree& tree);
54 
59  state(const sequence::sequence& sentence);
60 
65  state advance(const transition& trans) const;
66 
74  bool legal(const transition& trans) const;
75 
82 
87  const node* stack_item(size_t depth) const;
88 
93  const leaf_node* queue_item(ssize_t depth) const;
94 
98  size_t stack_size() const;
99 
103  size_t queue_size() const;
104 
108  bool finalized() const;
109 
110  private:
111  state(stack_type stack, std::shared_ptr<queue_type> queue, size_t q_idx,
112  bool done);
113 
118 
122  std::shared_ptr<queue_type> queue_;
123 
127  size_t q_idx_;
128 
132  bool done_;
133 };
134 }
135 }
136 #endif
size_t q_idx_
The index of the front of the queue.
Definition: state.h:127
A single node in a parse tree for a sentence.
Definition: node.h:24
std::vector< std::unique_ptr< leaf_node >> queue_type
The underlying queue type.
Definition: state.h:47
Represents the parse tree for a sentence.
Definition: parse_tree.h:32
const node * stack_item(size_t depth) const
Definition: state.cpp:360
size_t queue_size() const
Definition: state.cpp:355
Represents the current parser state of a shift-reduce parser.
Definition: state.h:36
Represents a tagged sequence of observations.
Definition: sequence.h:24
bool legal(const transition &trans) const
Checks if a transition is legal from a current state.
Definition: state.cpp:284
bool finalized() const
Definition: state.cpp:378
stack_type stack_
The stack of partial parse trees.
Definition: state.h:117
Represents a transition taken by the parser.
Definition: transition.h:27
transition emergency_transition() const
Returns a transition used in situations where there is not a transition in the model satisfying the c...
Definition: state.cpp:312
bool done_
Whether or not this state has finished parsing.
Definition: state.h:132
state advance(const transition &trans) const
Advances the current state by taking the given transition.
Definition: state.cpp:55
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retreival, data mining, and other applications of text processing.
Definition: analyzer.h:24
Definition: persistent_stack.h:21
size_t stack_size() const
Definition: state.cpp:350
const leaf_node * queue_item(ssize_t depth) const
Definition: state.cpp:371
A leaf node (pre-terminal) in a parse tree.
Definition: leaf_node.h:24
std::shared_ptr< queue_type > queue_
The queue of preterminals.
Definition: state.h:122
state(const parse_tree &tree)
Constructs a state from a parse tree.
Definition: state.cpp:20