ModErn Text Analysis
META Enumerates Textual Applications
|
Represents the current parser state of a shift-reduce parser. More...
#include <state.h>
Public Types | |
using | stack_type = util::persistent_stack< std::unique_ptr< node >> |
A persistent stack of partial parse trees. | |
using | queue_type = std::vector< std::unique_ptr< leaf_node >> |
The underlying queue type. | |
Public Member Functions | |
state (const parse_tree &tree) | |
Constructs a state from a parse tree. More... | |
state (const sequence::sequence &sentence) | |
Constructs a state from a POS-tagged sequence. More... | |
state | advance (const transition &trans) const |
Advances the current state by taking the given transition. More... | |
bool | legal (const transition &trans) const |
Checks if a transition is legal from a current state. More... | |
transition | emergency_transition () const |
Returns a transition used in situations where there is not a transition in the model satisfying the constraints given in the original paper so that the parser can at least make progress. | |
const node * | stack_item (size_t depth) const |
const leaf_node * | queue_item (ssize_t depth) const |
size_t | stack_size () const |
size_t | queue_size () const |
bool | finalized () const |
Private Member Functions | |
state (stack_type stack, std::shared_ptr< queue_type > queue, size_t q_idx, bool done) | |
Private Attributes | |
stack_type | stack_ |
The stack of partial parse trees. | |
std::shared_ptr< queue_type > | queue_ |
The queue of preterminals. | |
size_t | q_idx_ |
The index of the front of the queue. | |
bool | done_ |
Whether or not this state has finished parsing. | |
Represents the current parser state of a shift-reduce parser.
Parser states consist of a stack of partial parse trees, a queue of pre-terminals, and whether or not the state is "finished".
The stack is represented using a persistent stack structure to ensure that updates to the parser state occur in O(1) time. The queue is static, so it can be represented as a vector + an index and updated in O(1) time.
meta::parser::state::state | ( | const parse_tree & | tree | ) |
Constructs a state from a parse tree.
This is used to generate the starting state for parsing during training.
meta::parser::state::state | ( | const sequence::sequence & | sentence | ) |
Constructs a state from a POS-tagged sequence.
This generates teh starting state for parsing during test time.
state meta::parser::state::advance | ( | const transition & | trans | ) | const |
Advances the current state by taking the given transition.
trans | The transition to take to move the state forward |
bool meta::parser::state::legal | ( | const transition & | trans | ) | const |
Checks if a transition is legal from a current state.
trans | The transition to check |
const node * meta::parser::state::stack_item | ( | size_t | depth | ) | const |
depth | The depth to seek to in the stack |
const leaf_node * meta::parser::state::queue_item | ( | ssize_t | depth | ) | const |
depth | The depth to seek to in the queue |
size_t meta::parser::state::stack_size | ( | ) | const |
size_t meta::parser::state::queue_size | ( | ) | const |
bool meta::parser::state::finalized | ( | ) | const |