|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.mit.jwi.data.FileProvider
public class FileProvider
Implementation of a data provider for Wordnet that uses files in the file
system to back instances of its data sources. This implementation takes a
URL to a file system directory as its path argument, and uses
the resource hints from the data types and parts of speech for its content
types to examine the filenames in the that directory to determine which files
contain which data.
This implementation supports loading the wordnet files into memory,
but this is actually not that beneficial for speed. This is because the
implementation loads the file data into memory uninterpreted, and on modern
machines, the time to interpret a line of data (i.e., parse it into a Java
object) is much larger than the time it takes to load the line from disk.
Those wishing to achieve speed increases from loading Wordnet into memory
should rely on the implementation in RAMDictionary, or something
similar, which pre-processes the Wordnet data into objects before caching
them.
| Nested Class Summary | |
|---|---|
protected class |
FileProvider.JWIBackgroundLoader
A thread class which tries to load each data source in this provider. |
| Nested classes/interfaces inherited from interface edu.mit.jwi.data.IHasLifecycle |
|---|
IHasLifecycle.LifecycleState, IHasLifecycle.ObjectClosedException, IHasLifecycle.ObjectOpenException |
| Field Summary |
|---|
| Fields inherited from interface edu.mit.jwi.data.ILoadPolicy |
|---|
BACKGROUND_LOAD, IMMEDIATE_LOAD, NO_LOAD |
| Constructor Summary | |
|---|---|
FileProvider(java.io.File file)
Constructs the file provider pointing to the resource indicated by the path. |
|
FileProvider(java.io.File file,
int loadPolicy)
Constructs the file provider pointing to the resource indicated by the path, with the specified load policy. |
|
FileProvider(java.io.File file,
int loadPolicy,
java.util.Collection<? extends IContentType<?>> types)
Constructs the file provider pointing to the resource indicated by the path, with the specified load policy, looking for the specified content type.s |
|
FileProvider(java.net.URL url)
Constructs the file provider pointing to the resource indicated by the path. |
|
FileProvider(java.net.URL url,
int loadPolicy)
Constructs the file provider pointing to the resource indicated by the path, with the specified load policy. |
|
FileProvider(java.net.URL url,
int loadPolicy,
java.util.Collection<? extends IContentType<?>> types)
Constructs the file provider pointing to the resource indicated by the path, with the specified load policy, looking for the specified content type.s |
|
| Method Summary | ||
|---|---|---|
protected void |
checkOpen()
Convenience method that throws an exception if the provider is closed. |
|
void |
close()
This closes the object by disposing of data backing objects or connections. |
|
protected
|
createBinarySearch(java.io.File file,
IContentType<T> type)
Creates a binary search data source for the specified type, using the specified file. |
|
protected
|
createDataSource(java.io.File file,
IContentType<T> type,
int policy)
Creates the actual data source implementations. |
|
protected
|
createDirectAccess(java.io.File file,
IContentType<T> type)
Creates a direct access data source for the specified type, using the specified file. |
|
protected java.util.Map<IContentType<?>,ILoadableDataSource<?>> |
createSourceMap(java.util.List<java.io.File> files,
int policy)
Creates the map that contains the content types mapped to the data sources. |
|
protected IVersion |
determineVersion(java.util.Collection<? extends IDataSource<?>> srcs)
Determines a version from the set of data sources, if possible, otherwise returns IVersion.NO_VERSION |
|
java.nio.charset.Charset |
getCharset()
Returns the character set associated with this object. |
|
int |
getLoadPolicy()
Returns the load policy for this object, expressed as an integer. |
|
java.net.URL |
getSource()
Returns the URL that points to the resource location; should
never return null. |
|
|
getSource(IContentType<T> type)
Returns a data source object for the specified content type, if one is available; otherwise returns null. |
|
java.util.Set<? extends IContentType<?>> |
getTypes()
Returns a set containing all the content types this provider looks for at the resource location. |
|
IVersion |
getVersion()
Returns the associated version for this object. |
|
boolean |
isLoaded()
Returns whether this object is loaded or not. |
|
static boolean |
isLocalDirectory(java.io.File dir)
A utility method for checking whether a file represents an existing local directory. |
|
static boolean |
isLocalDirectory(java.net.URL url)
A utility method for checking whether a file represents an existing local directory. |
|
boolean |
isOpen()
Returns true if the dictionary is open, that is, ready to
accept queries; returns false otherwise |
|
void |
load()
Starts a simple, non-blocking load. |
|
void |
load(boolean block)
Initiates the loading process. |
|
boolean |
open()
This opens the object by performing any required initialization steps. |
|
|
resolveContentType(IDataType<T> dt,
POS pos)
Returns the first content type, if any, that matches the specified data type and pos object. |
|
void |
setCharset(java.nio.charset.Charset charset)
Sets the character set associated with this dictionary. |
|
void |
setLoadPolicy(int policy)
Sets the load policy for this object. |
|
void |
setSource(java.net.URL url)
This method is used to set the source URL from which the provider accesses the data from which it instantiates data sources. |
|
static java.io.File |
toFile(java.net.URL url)
Transforms a URL into a File. |
|
static java.net.URL |
toURL(java.io.File file)
Transforms a file into a URL. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FileProvider(java.io.File file)
ILoadPolicy.NO_LOAD load policy.
file - A file pointing to the wordnet directory, may not be
null
java.lang.NullPointerException - if the specified file is null
public FileProvider(java.io.File file,
int loadPolicy)
file - A file pointing to the wordnet directory, may not be
nullloadPolicy - the load policy for this provider; this provider supports the
three values defined in ILoadPolicy.
java.lang.NullPointerException - if the specified file is null
public FileProvider(java.io.File file,
int loadPolicy,
java.util.Collection<? extends IContentType<?>> types)
file - A file pointing to the wordnet directory, may not be
nullloadPolicy - the load policy for this provider; this provider supports the
three values defined in ILoadPolicy.types - the content types this provider will look for when it loads
its data; may not be null or empty
java.lang.NullPointerException - if the file or content type collection is null
java.lang.IllegalArgumentException - if the set of types is emptypublic FileProvider(java.net.URL url)
ILoadPolicy.NO_LOAD load policy.
url - A file URL in UTF-8 decodable format, may not be
null
java.lang.NullPointerException - if the specified URL is null
public FileProvider(java.net.URL url,
int loadPolicy)
url - A file URL in UTF-8 decodable format, may not be
nullloadPolicy - the load policy for this provider; this provider supports the
three values defined in ILoadPolicy.
java.lang.NullPointerException - if the specified URL is null
public FileProvider(java.net.URL url,
int loadPolicy,
java.util.Collection<? extends IContentType<?>> types)
url - A file URL in UTF-8 decodable format, may not be
nullloadPolicy - the load policy for this provider; this provider supports the
three values defined in ILoadPolicy.types - the content types this provider will look for when it loads
its data; may not be null or empty
java.lang.NullPointerException - if the url or content type collection is null
java.lang.IllegalArgumentException - if the set of types is empty| Method Detail |
|---|
public java.net.URL getSource()
IDataProviderURL that points to the resource location; should
never return null.
getSource in interface IDataProviderURL that points to the resource location; must
not be nullpublic int getLoadPolicy()
ILoadPolicy
getLoadPolicy in interface ILoadPolicypublic void setSource(java.net.URL url)
IDataProviderIllegalStateException.
setSource in interface IDataProviderurl - the location of the data, may not be nullpublic void setLoadPolicy(int policy)
ILoadPolicy
setLoadPolicy in interface ILoadPolicypolicy - the policy to implement; may be one of NO_LOAD,
BACKGROUND_LOAD, IMMEDIATE_LOAD or
an implementation-dependent value.public IVersion getVersion()
IHasVersionnull.
getVersion in interface IHasVersionnull if none.protected IVersion determineVersion(java.util.Collection<? extends IDataSource<?>> srcs)
IVersion.NO_VERSION
srcs - the data sources to be used to determine the verison
IVersion.NO_VERSION if there is nonepublic java.nio.charset.Charset getCharset()
IHasCharsetnull.
getCharset in interface IHasCharsetnullpublic void setCharset(java.nio.charset.Charset charset)
IDataProvidernull.
setCharset in interface IDataProvidercharset - the possibly null character set to use when
decoding files.
public <T> IContentType<T> resolveContentType(IDataType<T> dt,
POS pos)
IDataProvidernull.
resolveContentType in interface IDataProviderdt - the data type, possibly null, of the desired
content typepos - the part of speech, possibly null, of the desired
content type
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 void load()
ILoadable
load in interface ILoadable
public void load(boolean block)
throws java.lang.InterruptedException
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.
java.lang.InterruptedException - if the method is blocking, and is interrupted while waiting
for loading to completepublic 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 otherwise
protected java.util.Map<IContentType<?>,ILoadableDataSource<?>> createSourceMap(java.util.List<java.io.File> files,
int policy)
throws java.io.IOException
files - the files from which the data sources should be created, may
not be nullpolicy - the load policy of the provider
null, of content
types mapped to data sources
java.lang.NullPointerException - if the file list is null
java.io.IOException - if there is a problem creating the data source
protected <T> ILoadableDataSource<T> createDataSource(java.io.File file,
IContentType<T> type,
int policy)
throws java.io.IOException
T - the content type of the data sourcefile - the file from which the data source should be created, may not
be nulltype - the content type of the data sourcepolicy - the load policy to follow when creating the data source
java.lang.NullPointerException - if any argument is null
java.io.IOException - if there is an IO problem when creating the data source
protected <T> ILoadableDataSource<T> createDirectAccess(java.io.File file,
IContentType<T> type)
throws java.io.IOException
T - the parameter of the content typefile - the file on which the data source is based; may not be
nulltype - the data type for the data source; may not be
null
java.lang.NullPointerException - if either argument is null
java.io.IOException - if there is an IO problem when creating the data source
object
protected <T> ILoadableDataSource<T> createBinarySearch(java.io.File file,
IContentType<T> type)
throws java.io.IOException
T - the parameter of the content typefile - the file on which the data source is based; may not be
nulltype - the data type for the data source; may not be
null
java.lang.NullPointerException - if either argument is null
java.io.IOException - if there is an IO problem when creating the data source
objectpublic 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 IClosableprotected void checkOpen()
ObjectClosedException - if the provider is closedpublic <T> ILoadableDataSource<T> getSource(IContentType<T> type)
IDataProvidernull.
getSource in interface IDataProviderT - the content type of the data sourcetype - the content type of the data source to be retrieved
null if this provider has no such data sourcepublic java.util.Set<? extends IContentType<?>> getTypes()
IDataProvider
getTypes in interface IDataProvidernull, non-empty set of content types for this
providerpublic static java.io.File toFile(java.net.URL url)
URLDecoder.
java.lang.NullPointerException - if the url is null
java.lang.IllegalArgumentException - if the url does not use the 'file' protocolpublic static java.net.URL toURL(java.io.File file)
file - the file to be transformed
java.lang.NullPointerException - if the specified file is nullpublic static boolean isLocalDirectory(java.net.URL url)
url - the url object to check, may not be null
true if the url object represents a local directory
which exists; false otherwise.
java.lang.NullPointerException - if the specified url object is nullpublic static boolean isLocalDirectory(java.io.File dir)
dir - the file object to check, may not be null
true if the file object represents a local directory
which exist; false otherwise.
java.lang.NullPointerException - if the specified file object is null
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||