public abstract class InMemoryMWEIndex extends java.lang.Object implements IMWEIndex
IMWEIndex
. Loads the entire index into
memory. Subclasses must implement the createData()
method to actually create
the index data object.Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.locks.Lock |
lifecycleLock |
commentDoubleSemicolon, commentDoubleSlash
Constructor and Description |
---|
InMemoryMWEIndex() |
Modifier and Type | Method and Description |
---|---|
protected void |
checkOpen()
Throws an
IllegalStateException if the index is closed. |
void |
close()
Closes the index if open.
|
protected abstract java.util.Map<IMWEDescID,? extends IRootMWEDesc> |
createData() |
static java.util.Map<IMWEDescID,IRootMWEDesc> |
createData(java.lang.Iterable<java.lang.String> descStrs)
Utility method that assembles a MWE index data map from a list of
multi-word expression string descriptions.
|
static java.util.Map<IMWEDescID,IRootMWEDesc> |
createData(java.io.Reader r)
Utility method that assembles a MWE index data map from a stream of
characters that contains a whitespace-delimited list of multi-word
expressions.
|
protected java.util.Map<java.lang.String,? extends IMWEDescSet> |
createIndex(java.util.Map<IMWEDescID,? extends IRootMWEDesc> data)
Uses the given map of description IDs to root descriptions in order to
create the index.
|
IMWEDesc |
get(IMWEDescID id)
Returns the MWE description for the specified ID, or
null if
this index does not contain said description. |
java.util.Set<? extends IRootMWEDesc> |
get(java.lang.String part)
Returns a set of
IRootMWEDesc objects whose MWEs contain the
specified part. |
IMWEDescSet |
getAll(java.lang.String part)
Returns a set containing both
IRootMWEDesc and IInfMWEDesc
objects that the given string is a part of. |
java.util.Iterator<java.lang.String> |
getIndexIterator()
Returns an iterator that will iterate over all MWE parts in the index, in
order.
|
IInfMWEDesc |
getInflectedMWEDesc(java.lang.String lemma,
MWEPOS pos,
java.lang.String inflected)
Returns the inflected MWE description for the specified root lemma, part
of speech, and inflected form, or
null if this index does
not contain said description. |
java.util.Iterator<IRootMWEDesc> |
getRootIterator()
Returns an iterator that will iterate over all root MWE descriptions in
the index, in order.
|
IRootMWEDesc |
getRootMWEDesc(java.lang.String lemma,
MWEPOS pos)
Returns the root MWE description for the specified lemma and part of
speech, or
null if this index does not contain said
description. |
protected void |
insert(java.lang.String key,
IMWEDesc object,
java.util.Map<java.lang.String,IMWEDescSet> map)
Adds the specified object to the set indexed under the specified key in
the given map.
|
static boolean |
isComment(java.lang.String descStr)
Returns true if the given string is a comment; that is, if it starts with
'//' or ';;'.
|
boolean |
isOpen()
Returns whether the index is open.
|
boolean |
open()
Prepares the index for use.
|
public boolean open() throws java.io.IOException
IMWEIndex
IllegalStateException
.
Once open, an index can be closed by calling the IMWEIndex.close()
method.protected abstract java.util.Map<IMWEDescID,? extends IRootMWEDesc> createData() throws java.io.IOException
java.io.IOException
protected java.util.Map<java.lang.String,? extends IMWEDescSet> createIndex(java.util.Map<IMWEDescID,? extends IRootMWEDesc> data)
data
- the map of IMWEDescID objects to IRootMWEDesc objects used to
create the indexprotected final void insert(java.lang.String key, IMWEDesc object, java.util.Map<java.lang.String,IMWEDescSet> map)
key
- the key under which the object is to be filed; may be
null
object
- the object to be filed; may be null
map
- the map into which the object should be filed; may not be
null
java.lang.NullPointerException
- if the specified map is null
public boolean isOpen()
IMWEIndex
public void close()
IMWEIndex
public IMWEDesc get(IMWEDescID id)
IMWEIndex
null
if
this index does not contain said description.public IRootMWEDesc getRootMWEDesc(java.lang.String lemma, MWEPOS pos)
IMWEIndex
null
if this index does not contain said
description.getRootMWEDesc
in interface IMWEIndex
lemma
- the lemma for the MWE description desired; may not be
null
pos
- the part of speech for the MWE description desired; may not be
null
null
if nonepublic IInfMWEDesc getInflectedMWEDesc(java.lang.String lemma, MWEPOS pos, java.lang.String inflected)
IMWEIndex
null
if this index does
not contain said description.getInflectedMWEDesc
in interface IMWEIndex
lemma
- the lemma for the MWE description desired; may not be
null
pos
- the part of speech for the MWE description desired; may not be
null
inflected
- the inflected form of the MWE description desired; may not be
null
null
if nonepublic java.util.Set<? extends IRootMWEDesc> get(java.lang.String part)
IMWEIndex
IRootMWEDesc
objects whose MWEs contain the
specified part. Retrieval is insensitive to case. If no entries are
found, this method returns an empty set. The order of the returned set is
implementation dependent.public IMWEDescSet getAll(java.lang.String part)
IMWEIndex
IRootMWEDesc
and IInfMWEDesc
objects that the given string is a part of. Retrieval is insensitive to
case. If no entries are found, this method returns an empty set. The
order of the returned set is implementation dependent.public java.util.Iterator<IRootMWEDesc> getRootIterator()
IMWEIndex
getRootIterator
in interface IMWEIndex
public java.util.Iterator<java.lang.String> getIndexIterator()
IMWEIndex
getIndexIterator
in interface IMWEIndex
protected void checkOpen()
IllegalStateException
if the index is closed.public static boolean isComment(java.lang.String descStr)
descStr
- the string to be checkedpublic static java.util.Map<IMWEDescID,IRootMWEDesc> createData(java.lang.Iterable<java.lang.String> descStrs)
tok1_tok2_..._tokN_POS
, where each tok#
is one
part of the multiword expression, and POS
is the MWE part of
speech, represented as the identifier character.descStrs
- the collection of mwe description strings to be processed into
the index data objectjava.lang.NullPointerException
- if the specified iterable is null
public static java.util.Map<IMWEDescID,IRootMWEDesc> createData(java.io.Reader r) throws java.io.IOException
tok1_tok2_..._tokN_POS
, where each tok#
is one
part of the multiword expression, and POS
is the MWE part of
speech, represented as the identifier character.r
- the reader from which to create the data, may not be
null
java.io.IOException
- if there is an IOException thrown while reading from the
readerjava.lang.NullPointerException
- if the reader is null
Copyright © 2011 Massachusetts Institute of Technology. All Rights Reserved.