|
Parsing Engine | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdanbikel.parser.SubcatBag
public class SubcatBag
Provides a bag implementation of subcat requirements (a bag
is a set that allows multiple occurrences of the same item). This list
of all argument nonterminals is provided by Training.argNonterminals()
map. As a special case, this class also supports gap requirements,
that is, requirements equal to Training.gapAugmentation()
.
This class also provides a separate bin for miscellaneous subcat
requirements, such as those that can be matched via AbstractTraining.headSym
. All nonterminal
requirements are stripped of any augmentations before being counted in
this subcat bag.
toSexp()
method describes the way in which
this class represents miscellaneous requirements.
Bugs:
Training.argNonterminals()
, unless it is modified, this class will
simply put these elements in the miscellaneous bin.
add(Symbol)
or remove(Symbol)
methods. For example, the
generation of the modifying nonterminal NP-A-g satisfies two types
of requirements, being an NP argument and having the gap feature.
Nevertheless, this class assumes that these two types of requirements will
be added or removed in two separate invocations of either add(Symbol)
or remove(Symbol)
, one invocation with NP-A
and one with g. Currently, the Decoder
class assumes that
each nonterminal generated will satisfy only a single requirement (but then,
it does not handle the gap feature at all in its current state).
toSexp()
, for
input/output purposes, this class treats miscellaneous requirements
as the symbol +STOP+-A. This “fake” argument
nonterminal will not be correctly identified by
the Training.isArgumentFast(Symbol)
method after the
Training.setUpFastArgMap(CountsTable)
method has been invoked
(unless this fake nonterminal happens to be one of the keys of the map
passed to Training.setUpFastArgMap(CountsTable)
). It is therefore
important not to invoke the
Training.setUpFastArgMap(CountsTable)
method during training,
when requirements are added individually by add(Symbol)
, which
calls validRequirement(Symbol)
which in turn invokes
Training.isArgumentFast(Symbol)
.
Subcats
,
toSexp()
,
Serialized FormConstructor Summary | |
---|---|
SubcatBag()
Constructs an empty subcat. |
|
SubcatBag(SexpList list)
Constructs a subcat bag containing the number of occurrences of the symbols of list . |
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 bag. |
boolean |
addAll(SexpList list)
Adds each of the symbols of list to this subcat bag,
effectively calling add(Symbol) for each element of
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. |
void |
clear()
This method sets all counts of this subcat bag to zero. |
boolean |
contains(Symbol requirement)
Returns true if this subcat frame contains the
specified requirement. |
Event |
copy()
Returns a deep copy of this subcat bag. |
boolean |
empty()
Returns true if and only if there are zero requirements
in this subcat bag. |
void |
ensureCapacity(int size)
This method does nothing and returns. |
void |
ensureCapacity(int type,
int size)
This method does nothing and returns. |
boolean |
equals(Object obj)
Returns true if and only if the specified object is of
type SubcatBag and has the same number of requirement
categories and has the same counts for each of those requirement
categories. |
Object |
get(int type,
int index)
Gets the index th components of this subcat bag. |
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 |
hashCode()
Computes the hash code for this subcat. |
Iterator |
iterator()
Returns an itrerator over the elements of this subcat bag, returning the canonical version of symbols for each the categories described in add(Symbol) ; for each occurrence of a miscellaneous item
present in this subcat bag, the return value of Training.stopSym()
is returned. |
int |
numComponents()
An alias for size() . |
int |
numComponents(int type)
An alias for size() . |
int |
numTypes()
Returns 1 ( Subcat objects only support Symbol
objects). |
void |
readExternal(ObjectInput stream)
Reads a serialized instance of this class from the specified stream. |
boolean |
remove(Symbol requirement)
Removes the specified requirement from this subcat bag, if possible. |
static void |
setUpFastUidMap(CountsTable nonterminals)
|
int |
size()
Returns the number of requirements contained in this subcat bag. |
Sexp |
toSexp()
As per the contract of Subcat , this method returns a
Sexp such that an equivalent SubcatBag object
would result from the addAll(SexpList) method being invoked with
this Sexp as its argument. |
String |
toString()
Returns a human-readable string representation of the requirements contained in this bag. |
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 stream)
Writes this object to the specified output stream. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public SubcatBag()
public SubcatBag(SexpList list)
list
.
list
- a list of Symbol
objects to be added to this
subcat bagMethod Detail |
---|
public static void setUpFastUidMap(CountsTable nonterminals)
protected boolean validRequirement(Symbol requirement)
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.
requirement
- the requirement to test
public Subcat add(Symbol requirement)
Training.argNonterminals()
, as
well as a bin for gap augmentations (that is, requirements that are
equal to Training.gapAugmentation()
) and a miscellaneous bin
for all other requirements, such as those that can be matched via
AbstractTraining.headSym
.
add
in interface Subcat
requirement
- the requirement to add to this subcat bag
Subcat
objectTraining.defaultArgAugmentation()
,
Training.gapAugmentation()
,
Training.isArgumentFast(Symbol)
public boolean addAll(SexpList list)
list
to this subcat bag,
effectively calling add(Symbol)
for each element of
list
.
addAll
in interface Subcat
list
- a list of Symbol
objects to be added to this
subcat bag
ClassCastException
- if one or more elements of list
is not an instance of Symbol
public boolean remove(Symbol requirement)
Language.training().isArgumentFast(requirement)
returns true
, and if this subcat contained at least
one instance of that nonterminal.
remove
in interface Subcat
requirement
- the element that has been generated by the parser
and is thus a candidate for removal from this subcat
true
if this subcat bag contained at least one
instance of the specified requirement and it was removed,
false
otherwiseTraining.isArgumentFast(Symbol)
public int size()
size
in interface Subcat
public boolean empty()
true
if and only if there are zero requirements
in this subcat bag.
empty
in interface Subcat
public boolean contains(Symbol requirement)
Subcat
true
if this subcat frame contains the
specified requirement.
contains
in interface Subcat
requirement
- the requirement for which membership in this
subcat is to be checked
true
if this subcat contains requirement
,
that is, returns true
if and only if Subcat.remove(Symbol)
would remove the specified symbol from this subcatpublic Iterator iterator()
add(Symbol)
; for each occurrence of a miscellaneous item
present in this subcat bag, the return value of Training.stopSym()
is returned.
iterator
in interface Subcat
public Event copy()
copy
in interface Event
public int hashCode()
hashCode
in interface Event
hashCode
in interface Subcat
hashCode
in class Object
public boolean equals(Object obj)
true
if and only if the specified object is of
type SubcatBag
and has the same number of requirement
categories and has the same counts for each of those requirement
categories.
equals
in interface Event
equals
in interface Subcat
equals
in class Object
public String toString()
toString
in class Object
public Subcat getCanonical(boolean copyInto, Map<Subcat,Subcat> map)
Subcat
getCanonical
in interface Subcat
copyInto
- specifies whether to copy this subcat before inserting
into the canonical mapmap
- 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
public MutableEvent add(Object obj)
MutableEvent
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).
add
in interface MutableEvent
public MutableEvent add(int type, Object obj)
MutableEvent
this.typeIndex(obj.getClass()) == typemust 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).
add
in interface MutableEvent
public void ensureCapacity(int size)
ensureCapacity
in interface MutableEvent
size
- the size to pre-allocate for all abstract lists of this eventpublic void ensureCapacity(int type, int size)
ensureCapacity
in interface MutableEvent
type
- the type of underlying abstract list for which to pre-allocate
spacesize
- the size to pre-allocate for the specified type of abstract
listpublic Class getClass(int type)
Subcat
objects
need to support: Symbol.class
.
getClass
in interface Event
Class
) associated with the specified
type indexpublic int typeIndex(Class cl)
Symbol.class
, -1 otherwise.
typeIndex
in interface Event
public int numTypes()
Subcat
objects only support Symbol
objects).
numTypes
in interface Event
public int numComponents()
size()
.
numComponents
in interface Event
public int numComponents(int type)
size()
.
numComponents
in interface Event
public int canonicalize(Map canonical)
canonicalize
in interface Event
canonical
- a reflexive map of objecs representing event
information: for each unique key-value pair, the value is a
reference to the key
canonical
) or
-1 if this event was not even eligible for canonicalizationpublic void clear()
clear
in interface MutableEvent
public Object get(int type, int index)
index
th components of this subcat bag.
Efficiency note: The time complexity of this method is linear in the number of requirement types.
get
in interface Event
type
- an unused type parameter (Subcat
events only
support the type Symbol
, so this argument is effectively
superfluous for this class)index
- the index of the requirement to get
index
th Symbol
of this
subcat bag, as would be returned by the index
th
invocation of next
from the iterator returned by
iterator()
public Sexp toSexp()
Subcat
, this method returns a
Sexp
such that an equivalent SubcatBag
object
would result from the addAll(SexpList)
method being invoked with
this Sexp
as its argument.
N.B.: For each occurrence of a miscellaneous item present
in this subcat bag, the returned list will contain the symbol
Training.stopSym()
augmented with the argument augmentation:
Symbol.get(Training.stopSym()
.toString() +Treebank.canonicalAugDelimiter()
+Training.defaultArgAugmentation()
);
toSexp
in interface SexpConvertible
toSexp
in interface Subcat
public void writeExternal(ObjectOutput stream) throws IOException
writeExternal
in interface Externalizable
stream
- the stream to which to write this object
IOException
- if there is a problem writing to the specified streampublic void readExternal(ObjectInput stream) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
stream
- the stream from which to read a serialized instance of this
class
IOException
- if there is a problem reading from the
specified stream
ClassNotFoundException
- if the concrete type of the object to be
read cannot be foundpublic void become(Subcat other)
Subcat
become
in interface Subcat
other
- the subcat that this subcat is to become
|
Parsing Engine | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |