edu.mit.jmwe.index
Class InMemoryMWEIndex

java.lang.Object
  extended by edu.mit.jmwe.index.InMemoryMWEIndex
All Implemented Interfaces:
IMWEIndex
Direct Known Subclasses:
MWEIndex

public abstract class InMemoryMWEIndex
extends Object
implements IMWEIndex

The default abstract implementation of IMWEIndex. Loads the entire index into memory. Subclasses must implement the createData() method to actually create the index data object.

Since:
jMWE 1.0.0
Version:
1.552, 05 May 2011
Author:
Nidhi Kulkarni, M.A. Finlayson

Field Summary
protected  Lock lifecycleLock
           
 
Fields inherited from interface edu.mit.jmwe.index.IMWEIndex
commentDoubleSemicolon, commentDoubleSlash
 
Constructor Summary
InMemoryMWEIndex()
           
 
Method Summary
protected  void checkOpen()
          Throws an IllegalStateException if the index is closed.
 void close()
          Closes the index if open.
protected abstract  Map<IMWEDescID,? extends IRootMWEDesc> createData()
           
static Map<IMWEDescID,IRootMWEDesc> createData(Iterable<String> descStrs)
          Utility method that assembles a MWE index data map from a list of multi-word expression string descriptions.
static Map<IMWEDescID,IRootMWEDesc> createData(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  Map<String,? extends IMWEDescSet> createIndex(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.
 Set<? extends IRootMWEDesc> get(String part)
          Returns a set of IRootMWEDesc objects whose MWEs contain the specified part.
 IMWEDescSet getAll(String part)
          Returns a set containing both IRootMWEDesc and IInfMWEDesc objects that the given string is a part of.
 Iterator<String> getIndexIterator()
          Returns an iterator that will iterate over all MWE parts in the index, in order.
 IInfMWEDesc getInflectedMWEDesc(String lemma, MWEPOS pos, 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.
 Iterator<IRootMWEDesc> getRootIterator()
          Returns an iterator that will iterate over all root MWE descriptions in the index, in order.
 IRootMWEDesc getRootMWEDesc(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(String key, IMWEDesc object, Map<String,IMWEDescSet> map)
          Adds the specified object to the set indexed under the specified key in the given map.
static boolean isComment(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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lifecycleLock

protected final Lock lifecycleLock
Constructor Detail

InMemoryMWEIndex

public InMemoryMWEIndex()
Method Detail

open

public boolean open()
             throws IOException
Description copied from interface: IMWEIndex
Prepares the index for use. Mounts necessary files, opens sockets, or loads other data into memory that allows this index to service calls to its methods without throwing an IllegalStateException. Once open, an index can be closed by calling the IMWEIndex.close() method.

Specified by:
open in interface IMWEIndex
Returns:
true if the call succeeded, and the index is ready to service calls; false otherwise.
Throws:
IOException - if an IO exception is thrown while opening the index

createData

protected abstract Map<IMWEDescID,? extends IRootMWEDesc> createData()
                                                              throws IOException
Throws:
IOException

createIndex

protected Map<String,? extends IMWEDescSet> createIndex(Map<IMWEDescID,? extends IRootMWEDesc> data)
Uses the given map of description IDs to root descriptions in order to create the index. Makes all the entries in the index unmodifiable.

Parameters:
data - the map of IMWEDescID objects to IRootMWEDesc objects used to create the index
Returns:
an unmodifiable view of the index that maps parts of MWEs to a set containing all the MWEs they are a part of.
Since:
jMWE 1.0.0

insert

protected final void insert(String key,
                            IMWEDesc object,
                            Map<String,IMWEDescSet> map)
Adds the specified object to the set indexed under the specified key in the given map. If no such set exists, the method creates one.

Parameters:
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
Throws:
NullPointerException - if the specified map is null
Since:
jMWE 1.0.0

isOpen

public boolean isOpen()
Description copied from interface: IMWEIndex
Returns whether the index is open. This method can be called at any time.

Specified by:
isOpen in interface IMWEIndex
Returns:
true if the index is open and ready to accept calls; false otherwise.

close

public void close()
Description copied from interface: IMWEIndex
Closes the index if open. If the index is not open, this method does nothing. Once closed, and index may be reopened.

Specified by:
close in interface IMWEIndex

get

public IMWEDesc get(IMWEDescID id)
Description copied from interface: IMWEIndex
Returns the MWE description for the specified ID, or null if this index does not contain said description.

Specified by:
get in interface IMWEIndex
Parameters:
id - the id for the MWE description desired; may not be null
Returns:
the MWE description for the specified ID, or null if none

getRootMWEDesc

public IRootMWEDesc getRootMWEDesc(String lemma,
                                   MWEPOS pos)
Description copied from interface: IMWEIndex
Returns the root MWE description for the specified lemma and part of speech, or null if this index does not contain said description.

Specified by:
getRootMWEDesc in interface IMWEIndex
Parameters:
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
Returns:
the root MWE description matching the specified lemma and part of speech, or null if none

getInflectedMWEDesc

public IInfMWEDesc getInflectedMWEDesc(String lemma,
                                       MWEPOS pos,
                                       String inflected)
Description copied from interface: IMWEIndex
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.

Specified by:
getInflectedMWEDesc in interface IMWEIndex
Parameters:
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
Returns:
the inflected MWE description matching the specified arguments, or null if none

get

public Set<? extends IRootMWEDesc> get(String part)
Description copied from interface: IMWEIndex
Returns a set of 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.

Specified by:
get in interface IMWEIndex
Parameters:
part - a string representing the part for which entries should be retrieved
Returns:
a set of MWE entry objects that contain the specified part and are of the specified part of speech

getAll

public IMWEDescSet getAll(String part)
Description copied from interface: IMWEIndex
Returns a set containing both 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.

Specified by:
getAll in interface IMWEIndex
Parameters:
part - a string representing the part for which entries should be retrieved
Returns:
a set of MWE entry objects that contain the specified part

getRootIterator

public Iterator<IRootMWEDesc> getRootIterator()
Description copied from interface: IMWEIndex
Returns an iterator that will iterate over all root MWE descriptions in the index, in order.

Specified by:
getRootIterator in interface IMWEIndex
Returns:
an iterator that will iterate over all root MWE descriptions in the index, in order.

getIndexIterator

public Iterator<String> getIndexIterator()
Description copied from interface: IMWEIndex
Returns an iterator that will iterate over all MWE parts in the index, in order.

Specified by:
getIndexIterator in interface IMWEIndex
Returns:
an iterator that will iterate over all MWE parts in the index, in order.

checkOpen

protected void checkOpen()
Throws an IllegalStateException if the index is closed.

Since:
jMWE 1.0.0

isComment

public static boolean isComment(String descStr)
Returns true if the given string is a comment; that is, if it starts with '//' or ';;'.

Parameters:
descStr - the string to be checked
Returns:
true if the string begins with '//' or ';;', false otherwise.
Since:
jMWE 1.0.0

createData

public static Map<IMWEDescID,IRootMWEDesc> createData(Iterable<String> descStrs)
Utility method that assembles a MWE index data map from a list of multi-word expression string descriptions. Utility method that assembles a MWE index data map from a stream of characters that contains a whitespace-delimited list of multi-word expressions. The stream may contain single line comments, begun by ';;' or '//', and each whitespace-delimited entry must be in the form 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.

Parameters:
descStrs - the collection of mwe description strings to be processed into the index data object
Returns:
the index data object
Throws:
NullPointerException - if the specified iterable is null
Since:
jMWE 1.0.0

createData

public static Map<IMWEDescID,IRootMWEDesc> createData(Reader r)
                                               throws IOException
Utility method that assembles a MWE index data map from a stream of characters that contains a whitespace-delimited list of multi-word expressions. The stream may contain single line comments, begun by ';;' or '//', and each whitespace-delimited entry must be in the form 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.

Returns:
a Map> that maps each part of a multi-word expression to a list of multi-word expression descriptions that it is a part of.
Throws:
IOException - if there is an IOException thrown while reading from the reader
NullPointerException - if the reader is null
Since:
jMWE 1.0.0


Copyright © 2011 Massachusetts Institute of Technology. All Rights Reserved.