ModErn Text Analysis
META Enumerates Textual Applications
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
meta::parser::state Class Reference

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 nodestack_item (size_t depth) const
 
const leaf_nodequeue_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_typequeue_
 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.
 

Detailed Description

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.

Constructor & Destructor Documentation

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.

Member Function Documentation

state meta::parser::state::advance ( const transition trans) const

Advances the current state by taking the given transition.

Parameters
transThe 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.

See also
http://www.aclweb.org/anthology/W09-3825 Appendix
Parameters
transThe transition to check
Returns
whether that transition is legal
const node * meta::parser::state::stack_item ( size_t  depth) const
Parameters
depthThe depth to seek to in the stack
Returns
the node on the stack at the given depth
const leaf_node * meta::parser::state::queue_item ( ssize_t  depth) const
Parameters
depthThe depth to seek to in the queue
Returns
the node on teh queue at the given depth
size_t meta::parser::state::stack_size ( ) const
Returns
the number of partial parse trees on the stack.
size_t meta::parser::state::queue_size ( ) const
Returns
the number of preterminals on the queue.
bool meta::parser::state::finalized ( ) const
Returns
whether or not this state has finished parsing.

The documentation for this class was generated from the following files: