|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.mit.jwi.data.WordnetFile<T>
T - the type of the objects represented in this filepublic abstract class WordnetFile<T>
Abstract superclass of wordnet data file objects. Provides all the
infrastructure required to access the files, except for the construction of
iterators and the actual implementation of the IDataSource.getLine(String)
method.
While this object is implemented to provider load/unload capabilities (i.e., it allows the whole wordnet file to be loaded into memory, rather than read from disk), this does not provide much of a performance boost. In tests, the time to parsing a line of data into a data object dominates the time required to read the data from disk (for a reasonable modern harddrive).
| Nested Class Summary | |
|---|---|
protected class |
WordnetFile.LineIterator
Used to iterate over lines in a file. |
| Nested classes/interfaces inherited from interface edu.mit.jwi.data.IHasLifecycle |
|---|
IHasLifecycle.LifecycleState, IHasLifecycle.ObjectClosedException, IHasLifecycle.ObjectOpenException |
| Constructor Summary | |
|---|---|
WordnetFile(java.io.File file,
IContentType<T> contentType)
Constructs an instance of this class backed by the specified java File object, with the specified content type. |
|
| Method Summary | |
|---|---|
void |
close()
This closes the object by disposing of data backing objects or connections. |
boolean |
equals(java.lang.Object obj)
|
java.nio.ByteBuffer |
getBuffer()
Returns the buffer which backs this object. |
IContentType<T> |
getContentType()
Returns the assigned content type of the resource that backs this object. |
java.io.File |
getFile()
Returns the file which backs this object. |
static java.lang.String |
getLine(java.nio.ByteBuffer buf)
Returns the String from the current position up to, but not including, the next newline. |
static java.lang.String |
getLine(java.nio.ByteBuffer buf,
java.nio.charset.Charset cs)
A different version of the getLine method that uses a specified character set to decode the byte stream. |
java.lang.String |
getName()
Returns a string representation of the name of this resource. |
IVersion |
getVersion()
Returns the wordnet version associated with this object, or null if the version cannot be determined. |
int |
hashCode()
|
boolean |
isLoaded()
Returns whether this object is loaded or not. |
boolean |
isOpen()
Returns true if the dictionary is open, that is, ready to
accept queries; returns false otherwise |
WordnetFile.LineIterator |
iterator()
|
WordnetFile.LineIterator |
iterator(java.lang.String key)
Returns an iterator that will iterator over lines in the data resource, starting at the line specified by the given key. |
void |
load()
Starts a simple, non-blocking load. |
void |
load(boolean block)
Initiates the loading process. |
abstract WordnetFile.LineIterator |
makeIterator(java.nio.ByteBuffer buffer,
java.lang.String key)
Constructs an iterator that can be used to iterate over the specified ByteBuffer, starting from the specified key. |
boolean |
open()
This opens the object by performing any required initialization steps. |
static void |
rewindToLineStart(java.nio.ByteBuffer buf)
Rewinds the specified buffer to the beginning of the current line. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface edu.mit.jwi.data.IDataSource |
|---|
getLine |
| Constructor Detail |
|---|
public WordnetFile(java.io.File file,
IContentType<T> contentType)
File object, with the specified content type. No effort is made
to ensure that the data in the specified file is actually formatted in
the proper manner for the line parser associated with the content type's
data type. If these are mismatched, this will result in
MisformattedLineExceptions in later calls.
file - the file which backs this wordnet file; may not be
nullcontentType - the content type for this file; may not be null
java.lang.NullPointerException - if the specified file or content type is null| Method Detail |
|---|
public java.lang.String getName()
IDataSource
getName in interface IDataSource<T>null, empty, or
all whitespacepublic java.io.File getFile()
nullpublic java.nio.ByteBuffer getBuffer()
ObjectClosedException - if the object is closedpublic IContentType<T> getContentType()
IDataSource
getContentType in interface IDataSource<T>null.
public boolean open()
throws java.io.IOException
IHasLifecyclefalse, then subsequent calls to
IHasLifecycle.isOpen() will return false.
open in interface IHasLifecycletrue if there were no errors in initialization;
false otherwise.
java.io.IOException - if there was IO error while performing initializataionpublic boolean isOpen()
IHasLifecycletrue if the dictionary is open, that is, ready to
accept queries; returns false otherwise
isOpen in interface IHasLifecycletrue if the object is open; false
otherwisepublic void close()
IClosable
close in interface IClosablepublic boolean isLoaded()
ILoadabletrue only if the loading process has completed and the
object is actually loaded; if the object is still in the process of
loading, or failed to load, the method should return false.
isLoaded in interface ILoadabletrue if the method has completed loading;
false otherwisepublic void load()
ILoadable
load in interface ILoadablepublic void load(boolean block)
ILoadableblock is false), or return
only when the loading process is complete. If the object is already
loaded, the method returns immediately and has no effect. If the object
is in the process of loading, and the method is called in blocking mode,
the method blocks until loading is complete, even if that call of the
method did not initiate the loading process. Some implementors of this
interface may not support the immediate-return functionality.
load in interface ILoadableblock - if true, the method returns only when the loading
process is complete; if false, the method returns
immediately.public IVersion getVersion()
getVersion in interface IHasVersionObjectClosedException - if the object is closed when this method is calledIHasVersion.getVersion()public WordnetFile.LineIterator iterator()
iterator in interface java.lang.Iterable<java.lang.String>public WordnetFile.LineIterator iterator(java.lang.String key)
IDataSourcenull, this is the same as calling the plain
Iterable.iterator() method. If no line starts with the pattern, the
iterator's Iterator.hasNext() will return false. The
iterator does not support the Iterator.remove() operation; if
that method is called, the iterator will throw an
UnsupportedOperationException.
iterator in interface IDataSource<T>key - the key at which the iterator should begin
public abstract WordnetFile.LineIterator makeIterator(java.nio.ByteBuffer buffer,
java.lang.String key)
ByteBuffer, starting from the specified key.
buffer - the buffer over which the iterator will iterate, should not be
nullkey - the key at which the iterator should begin, should not be
null
ByteBufferpublic int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic static java.lang.String getLine(java.nio.ByteBuffer buf)
buf - the buffer from which the line should be extracted
java.lang.NullPointerException - if the specified buffer is null
public static java.lang.String getLine(java.nio.ByteBuffer buf,
java.nio.charset.Charset cs)
null, the method defaults to the previous method
getLine(ByteBuffer).
buf - the buffer from which the line should be extractedcs - the character set to use for decoding; may be
null
java.lang.NullPointerException - if the specified buffer is nullpublic static void rewindToLineStart(java.nio.ByteBuffer buf)
buf - the buffer to be rewound; may not be null
java.lang.NullPointerException - if the specified buffer is null
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||