Parsing Engine

danbikel.parser
Class SubcatList

java.lang.Object
  extended by danbikel.lisp.Sexp
      extended by danbikel.lisp.SexpList
          extended by danbikel.parser.SubcatList
All Implemented Interfaces:
SexpConvertible, Event, MutableEvent, Subcat, Externalizable, Serializable

public class SubcatList
extends SexpList
implements Subcat, Externalizable

Implements subcats where requirements need to be met in the order in which they are added to this subcat (the strictest form of a subcat). The only loosening of restrictions in this implementation of a subcat is that nonterminals are stripped of any gap augmentations before added to this subcat frame.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class danbikel.lisp.SexpList
SexpList.HashCache
 
Field Summary
 
Fields inherited from class danbikel.lisp.SexpList
emptyList
 
Constructor Summary
SubcatList()
          Construct a new empty subcat list.
SubcatList(SexpList list)
          Constructs a new subcat list from the requirements in the specified SexpList.
 
Method Summary
 MutableEvent add(int type, Object obj)
          Adds the specified object of the specified type to this event.
 MutableEvent add(Object obj)
          Adds the specified object to this event.
 Subcat add(Symbol requirement)
          Adds the specified requirement to this subcat list.
 boolean addAll(SexpList list)
          Adds the requirements (Symbol objects) of list to this subcat list.
 void become(Subcat other)
          Causes this subcat to be equal to the specified subcat by copying the specified subcat's data to this subcat.
 int canonicalize(Map canonical)
          This method does nothing and returns -1, as no internal data to this class can be canonicalized.
 boolean contains(Symbol requirement)
          Returns true if this subcat frame contains the specified requirement.
 Event copy()
          Returns a deep copy of this event of the same run-time type.
 boolean empty()
          Returns true if all requirements of this subcat frame have been met.
 void ensureCapacity(int type, int size)
          As Subcat objects only support requirements of a single type (Symbol), this method is an alias for SexpList.ensureCapacity(int).
 boolean equals(Object obj)
          Returns true if and only if the specified object is an instance of SubcatList whose underlying list is equal to that of this object, as determined by SexpList.equals(Object).
 Sexp get(int index)
          Gets the Sexp at the specified index.
 Object get(int type, int index)
          An alias for SexpList.get(int).
 Subcat getCanonical(boolean copyInto, Map<Subcat,Subcat> map)
          Returns a canonical instance of this object using the specified map (optional operation).
 Class getClass(int type)
          This method returns the one class that Subcat objects need to support: Symbol.class.
 int numComponents()
          An alias for SexpList.size.
 int numComponents(int type)
          An alias for SexpList.size.
 int numTypes()
          Returns 1 (Subcat objects only support Symbol objects).
 void readExternal(ObjectInput in)
          Reads this object from an ObjectInput instance.
 boolean remove(Symbol requirement)
          Removes the specified requirement from this subcat list, if possible.
 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 Subcat.addAll(SexpList) method were invoked with the list returned by this method.
 int typeIndex(Class cl)
          Returns 0 if the specified class is equal to Symbol.class, -1 otherwise.
protected  boolean validRequirement(Symbol requirement)
          A method to check if the specified requirement is valid.
 void writeExternal(ObjectOutput out)
          Writes this object to an ObjectOutput instance.
 
Methods inherited from class danbikel.lisp.SexpList
add, add, addAll, clear, contains, deepCopy, ensureCapacity, first, getCanonical, getChildLabel, hashCode, indexOf, isAllSymbols, isList, isSymbol, iterator, last, length, listAt, remove, reverse, set, setChildLabel, size, symbolAt, toString, trimToSize, trimToSizeRecursive
 
Methods inherited from class danbikel.lisp.Sexp
getCanonical, list, main, read, read, read, symbol
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface danbikel.parser.Subcat
hashCode, iterator, size
 
Methods inherited from interface danbikel.parser.MutableEvent
clear, ensureCapacity
 

Constructor Detail

SubcatList

public SubcatList()
Construct a new empty subcat list.


SubcatList

public SubcatList(SexpList list)
Constructs a new subcat list from the requirements in the specified SexpList.

Parameters:
list - the list of requirements from which to construct this subcat list
Method Detail

add

public MutableEvent add(Object obj)
Description copied from interface: MutableEvent
Adds the specified object to this event. The specified object must be of a type that this event is capable of collecting; that is,
 this.typeIndex(obj.getClass())
 
must not return -1.

If an implementation of this interface collects components that are primitive type values, then these values should be wrapped in their corresponding wrapper classes. For example, if an implementation of this interface accepts int values, they should be passed as Integer objects to this method. At present, an Event implementation cannot be designed accept both a primitive type and its associated wrapper class' type (this is, of course, not a serious limitation).

Specified by:
add in interface MutableEvent
Returns:
this object

add

public MutableEvent add(int type,
                        Object obj)
Description copied from interface: MutableEvent
Adds the specified object of the specified type to this event. The specified object must be of the type specified; that is, the expression
 this.typeIndex(obj.getClass()) == type
 
must be true.

If an implementation of this interface collects components that are primitive type values, then these values should be wrapped in their corresponding wrapper classes. For example, if an implementation of this interface accepts int values, they should be passed as an Integer objects to this method. At present, an Event implementation cannot be designed accept both a primitive type and its associated wrapper class' type (this is, of course, not a serious limitation).

Specified by:
add in interface MutableEvent
Returns:
this object

validRequirement

protected boolean validRequirement(Symbol requirement)
A method to check if the specified requirement is valid. For this class, a requirement is valid if it is either Training.gapAugmentation() or a symbol for which Training.isArgumentFast(Symbol) returns true. A subclass may override this method to allow for new or different valid requirements.

Parameters:
requirement - the requirement to test
Returns:
whether the specified requirement is valid

add

public Subcat add(Symbol requirement)
Adds the specified requirement to this subcat list. If requirement is a nonterminal containing a gap augmentation, the augmentation is removed before the requirement is added.

Efficiency note: The requirement is added to the beginning of the internal list of this object--an O(n) operation--so as to make the running time of remove(Symbol) O(1). The preferred method of construction of this type of subcat is via the addAll(SexpList) method, which operates in time linear to the size of the specified list.

Specified by:
add in interface Subcat
Parameters:
requirement - the requirement to add
Returns:
this Subcat object
See Also:
Training.defaultArgAugmentation(), Training.gapAugmentation(), Training.isArgumentFast(Symbol)

addAll

public boolean addAll(SexpList list)
Adds the requirements (Symbol objects) of list to this subcat list. Functionally, the order of elements in list is preserved, in that its first element will be the first requirement of this subcat (provided that this subcat is empty when this method is invoked).

Specified by:
addAll in interface Subcat
Overrides:
addAll in class SexpList
Parameters:
list - the elements to be added at the end of this list
Returns:
whether this list was modified

remove

public boolean remove(Symbol requirement)
Removes the specified requirement from this subcat list, if possible.

Specified by:
remove in interface Subcat
Parameters:
requirement - the requirement to remove from this subcat list
Returns:
true if the specified requirement was the next requirement in this subcat and was removed, false otherwise
See Also:
Subcat.contains(Symbol)

empty

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

Specified by:
empty in interface Subcat
Returns:
whether all requirements of this subcat frame have been met

contains

public boolean contains(Symbol requirement)
Description copied from interface: Subcat
Returns true if this subcat frame contains the specified requirement.

Specified by:
contains in interface Subcat
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 Subcat.remove(Symbol) would remove the specified symbol from this subcat

equals

public boolean equals(Object obj)
Returns true if and only if the specified object is an instance of SubcatList whose underlying list is equal to that of this object, as determined by SexpList.equals(Object).

Specified by:
equals in interface Event
Specified by:
equals in interface Subcat
Overrides:
equals in class SexpList
Parameters:
obj - the object to test for equality with this list
Returns:
whether the specified object is equal to this list
See Also:
AbstractList.equals(java.lang.Object)

copy

public Event copy()
Description copied from interface: Event
Returns a deep copy of this event of the same run-time type.

Specified by:
copy in interface Event

getCanonical

public Subcat getCanonical(boolean copyInto,
                           Map<Subcat,Subcat> map)
Description copied from interface: Subcat
Returns a canonical instance of this object using the specified map (optional operation).

Specified by:
getCanonical in interface Subcat
Parameters:
copyInto - specifies whether to copy this subcat before inserting into the canonical map
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
Returns:
a canonical instance of this object

get

public Sexp get(int index)
Description copied from class: SexpList
Gets the Sexp at the specified index.

Overrides:
get in class SexpList
Parameters:
index - the index of the list element to be retrieved
Returns:
the Sexp at the specified index.

getClass

public Class getClass(int type)
This method returns the one class that Subcat objects need to support: Symbol.class.

Specified by:
getClass in interface Event
Returns:
the type (Class) associated with the specified type index

typeIndex

public int typeIndex(Class cl)
Returns 0 if the specified class is equal to Symbol.class, -1 otherwise.

Specified by:
typeIndex in interface Event

numTypes

public int numTypes()
Returns 1 (Subcat objects only support Symbol objects).

Specified by:
numTypes in interface Event

numComponents

public int numComponents()
An alias for SexpList.size.

Specified by:
numComponents in interface Event

numComponents

public int numComponents(int type)
An alias for SexpList.size.

Specified by:
numComponents in interface Event

get

public Object get(int type,
                  int index)
An alias for SexpList.get(int).

Specified by:
get in interface Event

canonicalize

public int canonicalize(Map canonical)
This method does nothing and returns -1, as no internal data to this class can be canonicalized.

Specified by:
canonicalize in interface Event
Parameters:
canonical - a reflexive map of objecs representing event information: for each unique key-value pair, the value is a reference to the key
Returns:
1 if this event was canonicalized, 0 if it was not canonicalized (and had to be added to canonical) or -1 if this event was not even eligible for canonicalization

ensureCapacity

public void ensureCapacity(int type,
                           int size)
As Subcat objects only support requirements of a single type (Symbol), this method is an alias for SexpList.ensureCapacity(int).

Specified by:
ensureCapacity in interface MutableEvent
Parameters:
type - the type of underlying abstract list for which to pre-allocate space
size - the size to pre-allocate for the specified type of abstract list

toSexp

public Sexp toSexp()
Description copied from interface: Subcat
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 Subcat.addAll(SexpList) method were invoked with the list returned by this method.

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

become

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

Specified by:
become in interface Subcat
Parameters:
other - the subcat that this subcat is to become

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Description copied from class: SexpList
Writes this object to an ObjectOutput instance.

Specified by:
writeExternal in interface Externalizable
Overrides:
writeExternal in class SexpList
Parameters:
out - the object stream to which to write an object of this class
Throws:
IOException - if the underlying write operation throws an IOException

readExternal

public void readExternal(ObjectInput in)
                  throws IOException,
                         ClassNotFoundException
Description copied from class: SexpList
Reads this object from an ObjectInput instance.

Specified by:
readExternal in interface Externalizable
Overrides:
readExternal in class SexpList
Parameters:
in - the object stream from which to read objects of this class
Throws:
IOException - if the underlying read operation throws an IOException
ClassNotFoundException - if the underlying read operation throws an ClassNotFoundException

Parsing Engine

Author: Dan Bikel.