T - the type of the objects represented in this filepublic abstract class WordnetFile<T> extends Object implements ILoadableDataSource<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).
| Modifier and Type | Class and Description |
|---|---|
protected class |
WordnetFile.LineIterator
Used to iterate over lines in a file.
|
IHasLifecycle.LifecycleState, IHasLifecycle.ObjectClosedException, IHasLifecycle.ObjectOpenException| Constructor and Description |
|---|
WordnetFile(File file,
IContentType<T> contentType)
Constructs an instance of this class backed by the specified java
File object, with the specified content type. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
This closes the object by disposing of data backing objects or
connections.
|
boolean |
equals(Object obj) |
ByteBuffer |
getBuffer()
Returns the buffer which backs this object.
|
IContentType<T> |
getContentType()
Returns the assigned content type of the resource that backs this object.
|
File |
getFile()
Returns the file which backs this object.
|
static String |
getLine(ByteBuffer buf)
Returns the String from the current position up to, but not including,
the next newline.
|
static String |
getLine(ByteBuffer buf,
Charset cs)
A different version of the getLine method that uses a specified character
set to decode the byte stream.
|
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(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(ByteBuffer buffer,
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(ByteBuffer buf)
Rewinds the specified buffer to the beginning of the current line.
|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitgetLineforEach, spliteratorpublic WordnetFile(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 nullNullPointerException - if the specified file or content type is nullpublic String getName()
IDataSourcegetName in interface IDataSource<T>null, empty, or
all whitespacepublic File getFile()
nullpublic ByteBuffer getBuffer()
ObjectClosedException - if the object is closedpublic IContentType<T> getContentType()
IDataSourcegetContentType in interface IDataSource<T>null.public boolean open()
throws IOException
IHasLifecyclefalse, then subsequent calls to
IHasLifecycle.isOpen() will return false.open in interface IHasLifecycletrue if there were no errors in initialization;
false otherwise.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 otherwiseisOpen in interface IHasLifecycletrue if the object is open; false
otherwisepublic void close()
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.public void load()
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.public IVersion getVersion()
getVersion in interface IHasVersionObjectClosedException - if the object is closed when this method is calledIHasVersion.getVersion()public WordnetFile.LineIterator iterator()
public WordnetFile.LineIterator iterator(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 beginpublic abstract WordnetFile.LineIterator makeIterator(ByteBuffer buffer, 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
nullByteBufferpublic static String getLine(ByteBuffer buf)
buf - the buffer from which the line should be extractedNullPointerException - if the specified buffer is nullpublic static String getLine(ByteBuffer buf, 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
nullNullPointerException - if the specified buffer is nullpublic static void rewindToLineStart(ByteBuffer buf)
buf - the buffer to be rewound; may not be nullNullPointerException - if the specified buffer is nullCopyright © 2018. All rights reserved.