edu.mit.jverbnet.index
Class VerbIndex

java.lang.Object
  extended by edu.mit.jverbnet.util.AbstractHasLifecycle
      extended by edu.mit.jverbnet.index.VerbIndex
All Implemented Interfaces:
IVerbIndex, IHasLifecycle, java.lang.Iterable<IVerbClass>

public class VerbIndex
extends AbstractHasLifecycle
implements IVerbIndex

Default implementation of the IVerbIndex interface.

Since:
JVerbnet 1.0.0
Version:
1.2.0
Author:
Mark A. Finlayson

Nested Class Summary
 
Nested classes/interfaces inherited from interface edu.mit.jverbnet.util.IHasLifecycle
IHasLifecycle.ObjectClosedException
 
Constructor Summary
VerbIndex(java.io.File file)
          Creates a new verb index that uses the data at the specified location.
VerbIndex(java.net.URL url)
          Creates a new verb index that uses the data at the specified location.
 
Method Summary
protected
<K,V> java.util.Map<K,java.util.Set<V>>
compressAndMakeUnmodifiable(java.util.Map<K,java.util.Set<V>> map)
          Utility method for reallocating and making unmodifiable a map of sets.
protected  IVersion determineVersion()
          Determines the version of verbnet, as best is able.
protected  void doClose()
          Subclasses should put tear-down, closing code in this method.
protected  boolean doIsOpen()
          Subclasses should put code that determines whether the object is open in here.
protected  boolean doOpen()
          Subclasses should put initialization code in this method.
 java.util.Set<IMember> getMembers(IWordnetKey key)
          Returns all members in the index with the specified wordnet key.
 java.util.Set<IMember> getMembers(java.lang.String grouping)
          Returns all members in the index with the specified grouping.
 IVerbClass getRootVerb(java.lang.String id)
          Returns the root verb class with the specified id, or null if no such verb class can be found in the index.
protected
<K,V> java.util.Set<V>
getSetForKey(java.util.Map<K,java.util.Set<V>> map, K key)
          Utility method for filling in a map of keys to sets.
 IVerbClass getVerb(java.lang.String id)
          Returns the verb class with the specified id, or null if no such verb class can be found in the index.
 IVersion getVersion()
          The version of the index.
protected  java.util.Map<java.lang.String,IVerbClass> initVerbByIdMap()
          Initialization code for reading the verbnet XML.
 java.util.Iterator<IVerbClass> iterator()
          Returns an iterator over all verb classes in the index, in the order they are encountered in the data files.
 java.util.Iterator<java.lang.String> iteratorGroups()
          Returns an iterator over all groupings in the index, in their natural order.
 java.util.Iterator<IVerbClass> iteratorRoots()
          Returns an iterator over all root verb classes in the index, in the order they are encountered in the data files.
 java.util.Iterator<IWordnetKey> iteratorWordnetKeys()
          Returns an iterator over all wordnet keys in the index, in their natural order.
protected  boolean parse(org.xml.sax.XMLReader parser, java.io.InputStream in, java.lang.String filename)
          Parses an XML input stream.
 void setErrorHandler(org.xml.sax.ErrorHandler eh)
          Sets the XML error handler that will be used by the index when parsing XML files.
 void setVersion(IVersion newVersion)
          Sets the version for this index.
 
Methods inherited from class edu.mit.jverbnet.util.AbstractHasLifecycle
checkOpen, close, isOpen, open
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface edu.mit.jverbnet.util.IHasLifecycle
close, isOpen, open
 

Constructor Detail

VerbIndex

public VerbIndex(java.io.File file)
Creates a new verb index that uses the data at the specified location. The file may be a directory (which holds verbnet xml files), or a single xml file containing all the verbnet data.

Parameters:
file - the file or directory containing the verbnet data
Since:
JVerbnet 1.0.0

VerbIndex

public VerbIndex(java.net.URL url)
Creates a new verb index that uses the data at the specified location. The url may point to a directory (which holds verbnet xml files), or a single xml stream/file containing all the verbnet data.

Parameters:
url - the file or directory containing the verbnet data
Since:
JVerbnet 1.0.0
Method Detail

getVersion

public IVersion getVersion()
Description copied from interface: IVerbIndex
The version of the index. If the version cannot be determined, should return IVersion.UNKNOWN. If the version has not yet been determined, and the implementation does not determine the version automatically when called (e.g., the implementation requires a call to IVerbIndex.setVersion(IVersion)) the method will throw an exception.

Specified by:
getVersion in interface IVerbIndex
Returns:
the version of the index, or IVersion.UNKNOWN

setVersion

public void setVersion(IVersion newVersion)
Description copied from interface: IVerbIndex
Sets the version for this index. May called at most once. If it is called a second time, it will throw an exception.

Specified by:
setVersion in interface IVerbIndex
Parameters:
newVersion - the version to use for this index; may not be null

determineVersion

protected IVersion determineVersion()
Determines the version of verbnet, as best is able. If the version cannot be determined, returns IVersion.UNKNOWN.

Returns:
the version of verbnet in use, or IVersion.UNKNOWN
Since:
JVerbnet 1.0.0

doOpen

protected boolean doOpen()
                  throws java.io.IOException
Description copied from class: AbstractHasLifecycle
Subclasses should put initialization code in this method. If initialization fails, the method should not attempt to cleanup; it should just return false or throw an exception. The abstract lifecycle object takes care of calling the AbstractHasLifecycle.doClose() method if initialization fails.

Specified by:
doOpen in class AbstractHasLifecycle
Returns:
true if initialization succeeds; false otherwise
Throws:
java.io.IOException - if there is an IO error while initializing

setErrorHandler

public void setErrorHandler(org.xml.sax.ErrorHandler eh)
Sets the XML error handler that will be used by the index when parsing XML files. This setting will not take effect until the next time the index is opened

Parameters:
eh - the error handler to be used; may be null
Since:
JVerbnet 1.0.0

initVerbByIdMap

protected java.util.Map<java.lang.String,IVerbClass> initVerbByIdMap()
                                                              throws java.io.IOException
Initialization code for reading the verbnet XML.

Returns:
a map of verb class Ids to verb classes
Throws:
java.io.IOException - if there is an IO error
Since:
JVerbnet 1.0.0

parse

protected boolean parse(org.xml.sax.XMLReader parser,
                        java.io.InputStream in,
                        java.lang.String filename)
                 throws java.io.IOException
Parses an XML input stream.

Parameters:
parser - the parser to use; may not be null
in - the input stream from which to read the data
Returns:
true if the parse failed and the initialization should halt; false otherwise
Throws:
java.io.IOException - if there is an IO error when parsing
{@link - NullPointerException} if the parser or input stream are null
Since:
JVerbnet 1.0.0

getSetForKey

protected <K,V> java.util.Set<V> getSetForKey(java.util.Map<K,java.util.Set<V>> map,
                                              K key)
Utility method for filling in a map of keys to sets. The map is queried for the set indexed under the specified key; if none is found, the set is created and added. The set is returned.

Parameters:
map - the map to query for the set indexed by the key
key - the key under which to look for the set
Returns:
the set in the map for the key; never null
Since:
JVerbnet 1.0.0

compressAndMakeUnmodifiable

protected <K,V> java.util.Map<K,java.util.Set<V>> compressAndMakeUnmodifiable(java.util.Map<K,java.util.Set<V>> map)
Utility method for reallocating and making unmodifiable a map of sets.

Parameters:
map - the map whose set values should be reallocated and made unmodifiable; the map itself is made unmodifiable
Returns:
the new unmodifiable map with unmodifiable set values
Since:
JVerbnet 1.0.0

doIsOpen

protected boolean doIsOpen()
Description copied from class: AbstractHasLifecycle
Subclasses should put code that determines whether the object is open in here. Returns true if the object is open; false otherwise.

Specified by:
doIsOpen in class AbstractHasLifecycle
Returns:
true if the object is open; false otherwise.

doClose

protected void doClose()
Description copied from class: AbstractHasLifecycle
Subclasses should put tear-down, closing code in this method. This method should be able to clean up after a failed attempt to AbstractHasLifecycle.open() the object.

Specified by:
doClose in class AbstractHasLifecycle

getVerb

public IVerbClass getVerb(java.lang.String id)
Description copied from interface: IVerbIndex
Returns the verb class with the specified id, or null if no such verb class can be found in the index. Ids are usually of the form 'verb-##.#', e.g., 'accompany-51.7'.

Specified by:
getVerb in interface IVerbIndex
Parameters:
id - the id of the class
Returns:
the verb with the specified id, or null if none

getRootVerb

public IVerbClass getRootVerb(java.lang.String id)
Description copied from interface: IVerbIndex
Returns the root verb class with the specified id, or null if no such verb class can be found in the index. Ids are usually of the form 'verb-##.#', e.g., 'accompany-51.7'.

Specified by:
getRootVerb in interface IVerbIndex
Parameters:
id - the id of the class
Returns:
the verb with the specified id, or null if none

getMembers

public java.util.Set<IMember> getMembers(IWordnetKey key)
Description copied from interface: IVerbIndex
Returns all members in the index with the specified wordnet key. A null key indicates all members that have no key specified.

Specified by:
getMembers in interface IVerbIndex
Parameters:
key - the key for which members should be retrieved; may be null
Returns:
a set of members with the specified wordnet keys, or an empty set if none; will never return null

getMembers

public java.util.Set<IMember> getMembers(java.lang.String grouping)
Description copied from interface: IVerbIndex
Returns all members in the index with the specified grouping. A null, empty, or all whitespace grouping indicates all members that have no grouping specified.

Specified by:
getMembers in interface IVerbIndex
Parameters:
grouping - the grouping for which members should be retrieved; may be null, empty, or all whitespace.
Returns:
a set of members with the specified grouping, or an empty set if none; will never return null

iterator

public java.util.Iterator<IVerbClass> iterator()
Description copied from interface: IVerbIndex
Returns an iterator over all verb classes in the index, in the order they are encountered in the data files.

Specified by:
iterator in interface IVerbIndex
Specified by:
iterator in interface java.lang.Iterable<IVerbClass>
Returns:
an iterator over all verb classes in the index

iteratorRoots

public java.util.Iterator<IVerbClass> iteratorRoots()
Description copied from interface: IVerbIndex
Returns an iterator over all root verb classes in the index, in the order they are encountered in the data files.

Specified by:
iteratorRoots in interface IVerbIndex
Returns:
an iterator over all root verb classes in the index

iteratorWordnetKeys

public java.util.Iterator<IWordnetKey> iteratorWordnetKeys()
Description copied from interface: IVerbIndex
Returns an iterator over all wordnet keys in the index, in their natural order. The iterator will not return the 'null' wordnet key.

Specified by:
iteratorWordnetKeys in interface IVerbIndex
Returns:
an iterator over all wordnet keys in the index

iteratorGroups

public java.util.Iterator<java.lang.String> iteratorGroups()
Description copied from interface: IVerbIndex
Returns an iterator over all groupings in the index, in their natural order. The iterator will not return the 'null' grouping.

Specified by:
iteratorGroups in interface IVerbIndex
Returns:
an iterator over all wordnet keys in the index


Copyright © 2012 ${project.organization.name}. All Rights Reserved.