Parsing Engine

danbikel.parser
Interface Subcat

All Superinterfaces:
Event, MutableEvent, Serializable, SexpConvertible
All Known Implementing Classes:
BrokenSubcatBag, SubcatBag, SubcatList

public interface Subcat
extends MutableEvent, SexpConvertible

Specification for a collection of required arguments to be generated by a parser, also known as a subcategorization frame. In the parsing models supported by this package, a subcategorization frame, or simply subcat, has a slightly modified semantics, more general in one sense, more specific in another: it is the collection of requirements on a particular side of a head child of some parent nonterminal that have yet to be met, where a requirement is typically an argument nonterminal to be generated, but may also include other elements generated by the parser, such as traces (gaps). Thus, the subcats specified by this interface are dynamic, in that they start off with a full set of requirements that gets diminished as parsing proceeds.

Implementations of this interface may choose the manner in which these requirements are met via their implementations of the add and remove methods. For example, a very simple implementation might simply increment an internal counter for every call to add, decrementing this counter for every call to remove, causing the semantics for subcat frames to be simply a requirement on the number of modifying nonterminals generated, regardless of their labels. A more sophisticated implementation might insist on generating all arguments in the order in which they were added to this subcat frame. In general, no implementation should require more calls to remove than the number of requirements added via invocations of add and addAll.

At minimum, all implementing classes should have a no-argument default constructor and a one-argument constructor that accepts a SexpList containing only Symbol objects, to be passed to the addAll(SexpList) method.

See Also:
Subcats

Method Summary
 Subcat add(Symbol requirement)
          Adds the specified nonterminal to the required arguments of this subcat frame.
 boolean addAll(SexpList list)
          Adds the specified list of nonterminals (symbols) to the required arguments of this subcat frame.
 void become(Subcat other)
          Causes this subcat to be equal to the specified subcat by copying the specified subcat's data to this subcat.
 boolean contains(Symbol requirement)
          Returns true if this subcat frame contains the specified requirement.
 boolean empty()
          Returns true if all requirements of this subcat frame have been met.
 boolean equals(Object obj)
          Compares the specified object with this subcat frame for equality.
 Subcat getCanonical(boolean copyInto, Map map)
          Returns a canonical instance of this object using the specified map (optional operation).
 int hashCode()
          Returns a hash code of this object.
 Iterator iterator()
          Returns an iterator over the requirements contained in this subcat frame.
 boolean remove(Symbol requirement)
          Attempt to remove the specified symbol from the set of requirements in this subcat frame.
 int size()
          Returns the number of required arguments contained in this subcat frame.
 Sexp toSexp()
          Returns a list view of the information contained in this subcat, such that an equivalent subcat would result if a new Subcat object of this run-time type were constructed and its addAll(SexpList) method were invoked with the list returned by this method.
 
Methods inherited from interface danbikel.parser.MutableEvent
add, add, clear, ensureCapacity, ensureCapacity
 
Methods inherited from interface danbikel.parser.Event
canonicalize, copy, get, getClass, numComponents, numComponents, numTypes, typeIndex
 

Method Detail

add

public Subcat add(Symbol requirement)
Adds the specified nonterminal to the required arguments of this subcat frame. Implementors should check whether the specified requirement is valid and may choose not to add the specified requirement if it is not. Validity of a requirement is determined by the implementor; a typical notion of validity is that the requirement must either be a complex nonterminal with the argument augmentation (as determined by Training.isArgumentFast(Symbol)) or be the gap augmentation symbol.

Parameters:
requirement - the requirement to add to this subcat frame (typically an argument nonterminal)
Returns:
this Subcat object
See Also:
Training.defaultArgAugmentation(), Training.gapAugmentation(), Training.isArgumentFast(Symbol)

addAll

public boolean addAll(SexpList list)
Adds the specified list of nonterminals (symbols) to the required arguments of this subcat frame.

Parameters:
list - the list of requirements to be added to this subcat frame
Returns:
whether this subcat was modified

remove

public boolean remove(Symbol requirement)
Attempt to remove the specified symbol from the set of requirements in this subcat frame. It is an error to call this method after empty() returns true.

Parameters:
requirement - the element that has been generated by the parser and is thus a candidate for removal from this subcat
Returns:
true if the specified requirement can be removed from this subcat
See Also:
contains(Symbol)

size

public int size()
Returns the number of required arguments contained in this subcat frame.


empty

public boolean empty()
Returns true if all requirements of this subcat frame have been met. This method should return true if and only if size() == 0.


contains

public boolean contains(Symbol requirement)
Returns true if this subcat frame contains the specified requirement.

Parameters:
requirement - the requirement for which membership in this subcat is to be checked
Returns:
true if this subcat contains requirement, that is, returns true if and only if remove(Symbol) would remove the specified symbol from this subcat

iterator

public Iterator iterator()
Returns an iterator over the requirements contained in this subcat frame. Iterators are only required to return elements in the order in which they were added if the subcat implementation considers order relevant to equality.


hashCode

public int hashCode()
Returns a hash code of this object.

Specified by:
hashCode in interface Event

equals

public boolean equals(Object obj)
Compares the specified object with this subcat frame for equality. This method should return true if and only if the specified object is the same run-time type as this object and contains identical requirements in an identical order, if order is relevant to the implementation of this interface.

Specified by:
equals in interface Event

getCanonical

public Subcat getCanonical(boolean copyInto,
                           Map map)
Returns a canonical instance of this object using the specified map (optional operation).

Parameters:
map - the reflexive map to use for canonicalization: the key-value pair of (this, this) should be added to map if this object is not already a key in map
copyInto - specifies whether to copy this subcat before inserting into the canonical map
Returns:
a canonical instance of this object

toSexp

public Sexp toSexp()
Returns a list view of the information contained in this subcat, such that an equivalent subcat would result if a new Subcat object of this run-time type were constructed and its addAll(SexpList) method were invoked with the list returned by this method.

Specified by:
toSexp in interface SexpConvertible
Returns:
the S-expression that represents an instance of an implementor of this class

become

public void become(Subcat other)
Causes this subcat to be equal to the specified subcat by copying the specified subcat's data to this subcat.

Throws:
ClassCastException - if the specified subcat is not of the same run-time type as this subcat

Parsing Engine

Author: Dan Bikel.