net.sf.extjwnl.dictionary.file_manager
Class FileManagerImpl

java.lang.Object
  extended by net.sf.extjwnl.dictionary.file_manager.FileManagerImpl
All Implemented Interfaces:
FileManager, Owned

public class FileManagerImpl
extends Object
implements FileManager

An implementation of FileManager that reads files from the local file system. FileManagerImpl caches the file position before and after readLineAt in order to eliminate the redundant IO activity that a naive implementation of these methods would necessitate.

Author:
John Didion , Aliaksandr Autayeu

Field Summary
static String CACHE_USE_COUNT_KEY
          Whether to cache use counts, default false.
 
Constructor Summary
FileManagerImpl(Dictionary dictionary, Map<String,Param> params)
           
 
Method Summary
 void close()
          Shuts down the file manager.
 void delete()
          Deletes the dictionary.
 void edit()
          Reopens files for writing.
 String fileReadLineAt(RandomAccessDictionaryFile file, long offset)
           
 Dictionary getDictionary()
          Returns the dictionary this object belongs to.
 RandomAccessDictionaryFile getFile(POS pos, DictionaryFileType fileType)
          Returns the file from a part of speech and file type (ie data.noun).
 long getFirstLinePointer(POS pos, DictionaryFileType fileType)
          Return the first valid line pointer in the specified file.
 long getIndexedLinePointer(POS pos, DictionaryFileType fileType, String target)
          Returns indexed line pointer is typically used to find a word within an index file matching a given part of speech.
 long getMatchingLinePointer(POS pos, DictionaryFileType fileType, long offset, String substring)
          Search for a line whose index word contains substring, starting at offset.
 long getNextLinePointer(POS pos, DictionaryFileType fileType, long offset)
          Search for the line following the line that begins at offset.
 long getRandomLinePointer(POS pos, DictionaryFileType fileType)
          Return a randomly-chosen line pointer (offset of the beginning of a line).
 int getUseCount(String senseKey)
          Returns the number of times the sense marked by senseKey occurs in a semantic concordance.
 String readLineAt(POS pos, DictionaryFileType fileType, long offset)
          Read the line that begins at file offset offset.
 void save()
          Saves the files.
 void setDictionary(Dictionary dictionary)
          Sets the dictionary this object belongs to.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CACHE_USE_COUNT_KEY

public static final String CACHE_USE_COUNT_KEY
Whether to cache use counts, default false. Setting this parameter to true speeds up elements loading from files considerably, at the expense of some amount of memory.

See Also:
Constant Field Values
Constructor Detail

FileManagerImpl

public FileManagerImpl(Dictionary dictionary,
                       Map<String,Param> params)
                throws JWNLException
Throws:
JWNLException
Method Detail

close

public void close()
Description copied from interface: FileManager
Shuts down the file manager.

Specified by:
close in interface FileManager

delete

public void delete()
            throws IOException
Description copied from interface: FileManager
Deletes the dictionary.

Specified by:
delete in interface FileManager
Throws:
IOException - IOException

edit

public void edit()
          throws IOException
Description copied from interface: FileManager
Reopens files for writing.

Specified by:
edit in interface FileManager
Throws:
IOException - IOException

getFile

public RandomAccessDictionaryFile getFile(POS pos,
                                          DictionaryFileType fileType)
Returns the file from a part of speech and file type (ie data.noun).

Parameters:
pos - - the part of speech (NOUN, ADJ, VERB, ADV) or null
fileType - - the file type (data, index, exc, cntlist)
Returns:
- dictionary file

readLineAt

public String readLineAt(POS pos,
                         DictionaryFileType fileType,
                         long offset)
                  throws IOException
Description copied from interface: FileManager
Read the line that begins at file offset offset.

Specified by:
readLineAt in interface FileManager
Parameters:
pos - part of speech
fileType - file type
offset - file offset
Returns:
the line that begins at file offset offset
Throws:
IOException - IOException

fileReadLineAt

public String fileReadLineAt(RandomAccessDictionaryFile file,
                             long offset)
                      throws IOException
Throws:
IOException

getNextLinePointer

public long getNextLinePointer(POS pos,
                               DictionaryFileType fileType,
                               long offset)
                        throws IOException
Description copied from interface: FileManager
Search for the line following the line that begins at offset.

Specified by:
getNextLinePointer in interface FileManager
Parameters:
pos - part of speech
fileType - file type
offset - file offset
Returns:
The file offset of the start of the line, or -1 if offset is the last line in the file.
Throws:
IOException - IOException

getMatchingLinePointer

public long getMatchingLinePointer(POS pos,
                                   DictionaryFileType fileType,
                                   long offset,
                                   String substring)
                            throws IOException
Description copied from interface: FileManager
Search for a line whose index word contains substring, starting at offset.

Specified by:
getMatchingLinePointer in interface FileManager
Parameters:
pos - part of speech
fileType - file type
offset - file offset
substring - substring to search for in indexword
Returns:
The file offset of the start of the matching line, or -1 if no such line exists.
Throws:
IOException - IOException

getIndexedLinePointer

public long getIndexedLinePointer(POS pos,
                                  DictionaryFileType fileType,
                                  String target)
                           throws IOException
Returns indexed line pointer is typically used to find a word within an index file matching a given part of speech. It first accesses the appropriate file (based on pos and dictionary type), then iterates through the file. Does so by using an offset and string comparison algorithm.

Specified by:
getIndexedLinePointer in interface FileManager
Parameters:
pos - part of speech
fileType - file type
target - word to search for
Returns:
The file offset of the start of the matching line, or -1 if no such line exists.
Throws:
IOException - IOException

getRandomLinePointer

public long getRandomLinePointer(POS pos,
                                 DictionaryFileType fileType)
                          throws IOException
Description copied from interface: FileManager
Return a randomly-chosen line pointer (offset of the beginning of a line).

Specified by:
getRandomLinePointer in interface FileManager
Parameters:
pos - part of speech
fileType - file type
Returns:
a randomly-chosen line pointer
Throws:
IOException - IOException

getFirstLinePointer

public long getFirstLinePointer(POS pos,
                                DictionaryFileType fileType)
                         throws IOException
Description copied from interface: FileManager
Return the first valid line pointer in the specified file.

Specified by:
getFirstLinePointer in interface FileManager
Parameters:
pos - part of speech
fileType - file type
Returns:
the first valid line pointer in the specified file
Throws:
IOException - IOException

getDictionary

public Dictionary getDictionary()
Description copied from interface: Owned
Returns the dictionary this object belongs to.

Specified by:
getDictionary in interface Owned
Returns:
the dictionary this object belongs to

setDictionary

public void setDictionary(Dictionary dictionary)
Description copied from interface: Owned
Sets the dictionary this object belongs to.

Specified by:
setDictionary in interface Owned
Parameters:
dictionary - the dictionary this object belongs to

save

public void save()
          throws IOException,
                 JWNLException
Description copied from interface: FileManager
Saves the files.

Specified by:
save in interface FileManager
Throws:
IOException - IOException
JWNLException - JWNLException

getUseCount

public int getUseCount(String senseKey)
                throws IOException
Description copied from interface: FileManager
Returns the number of times the sense marked by senseKey occurs in a semantic concordance.

Specified by:
getUseCount in interface FileManager
Parameters:
senseKey - sense key
Returns:
the number of times the sense marked by senseKey occurs in a semantic concordance
Throws:
IOException - IOException


Copyright © 2011. All Rights Reserved.