net.sf.extjwnl.princeton.file
Class PrincetonRandomAccessDictionaryFile

java.lang.Object
  extended by net.sf.extjwnl.dictionary.file.AbstractDictionaryFile
      extended by net.sf.extjwnl.princeton.file.AbstractPrincetonDictionaryFile
          extended by net.sf.extjwnl.princeton.file.AbstractPrincetonRandomAccessDictionaryFile
              extended by net.sf.extjwnl.princeton.file.PrincetonRandomAccessDictionaryFile
All Implemented Interfaces:
DictionaryFile, DictionaryFileFactory<PrincetonRandomAccessDictionaryFile>, RandomAccessDictionaryFile, Owned

public class PrincetonRandomAccessDictionaryFile
extends AbstractPrincetonRandomAccessDictionaryFile
implements DictionaryFileFactory<PrincetonRandomAccessDictionaryFile>

A RandomAccessDictionaryFile that accesses files named with Princeton's dictionary file naming convention.

Author:
John Didion , Aliaksandr Autayeu

Field Summary
static String CHECK_LEX_FILE_NUMBER_KEY
          Whether to warn about lex file numbers correctness, default: true.
static String CHECK_LEX_ID_LIMIT_KEY
          Whether to warn about lex id being off limits, default: true.
static String CHECK_OFFSET_LIMIT_KEY
          Whether to warn about offsets being off limits, default: true.
static String CHECK_POINTER_INDEX_LIMIT_KEY
          Whether to warn about pointer target indices being off limits, default: true
static String CHECK_RELATION_LIMIT_KEY
          Whether to warn about relation count being off limits, default: true.
static String CHECK_VERB_FRAME_LIMIT_KEY
          Whether to warn about verb frame indices being off limits, default: true
static String CHECK_WORD_COUNT_LIMIT_KEY
          Whether to warn about word count being off limits, default: true.
protected  RandomAccessFile raFile
          The random-access file.
static String READ_ONLY
          Read-only file permission.
static String READ_WRITE
          Read-write file permission.
static String WRITE_PRINCETON_HEADER_KEY
          Whether to add standard princeton header to files on save, default: false.
 
Fields inherited from class net.sf.extjwnl.princeton.file.AbstractPrincetonRandomAccessDictionaryFile
encoding, ENCODING
 
Fields inherited from class net.sf.extjwnl.dictionary.file.AbstractDictionaryFile
dictionary, file, params
 
Constructor Summary
PrincetonRandomAccessDictionaryFile(Dictionary dictionary, Map<String,Param> params)
           
PrincetonRandomAccessDictionaryFile(Dictionary dictionary, String path, POS pos, DictionaryFileType fileType, Map<String,Param> params)
           
 
Method Summary
 void close()
          Closes the file.
 void edit()
          Reopens file in write mode.
 long getFilePointer()
          Returns the current position of the file pointer.
 String getOffsetFormatString()
          Returns offset format string that accommodates largest offset.
 boolean isOpen()
          Returns true if the file is open.
 long length()
          Returns the length, in bytes, of the file.
 PrincetonRandomAccessDictionaryFile newInstance(Dictionary dictionary, String path, POS pos, DictionaryFileType fileType)
          Creates a new instance of the dictionary file.
protected  void openFile()
          Here we try to be intelligent about opening files.
 int read()
          Reads a byte from the file.
 String readLine()
          Reads a line from the file.
 String readLineWord()
          Reads the first word from a file (ie offset, index word).
 void save()
          Saves the file.
 void seek(long pos)
          Goes to position pos in the file.
 void writeIndexStrings(ArrayList<String> strings)
           
 void writeLine(String line)
          Writes a line to the file.
 void writeStrings(Collection<String> strings)
          Writes strings in file.
 
Methods inherited from class net.sf.extjwnl.princeton.file.AbstractPrincetonRandomAccessDictionaryFile
getNextLineOffset, isPreviousLineOffset, setNextLineOffset
 
Methods inherited from class net.sf.extjwnl.princeton.file.AbstractPrincetonDictionaryFile
getFilename
 
Methods inherited from class net.sf.extjwnl.dictionary.file.AbstractDictionaryFile
delete, getDictionary, getFile, getFileType, getPOS, open, setDictionary
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.extjwnl.dictionary.file.DictionaryFile
delete, getFile, getFileType, getPOS, open
 
Methods inherited from interface net.sf.extjwnl.util.factory.Owned
getDictionary, setDictionary
 

Field Detail

WRITE_PRINCETON_HEADER_KEY

public static final String WRITE_PRINCETON_HEADER_KEY
Whether to add standard princeton header to files on save, default: false.

See Also:
Constant Field Values

CHECK_LEX_FILE_NUMBER_KEY

public static final String CHECK_LEX_FILE_NUMBER_KEY
Whether to warn about lex file numbers correctness, default: true.

See Also:
Constant Field Values

CHECK_RELATION_LIMIT_KEY

public static final String CHECK_RELATION_LIMIT_KEY
Whether to warn about relation count being off limits, default: true.

See Also:
Constant Field Values

CHECK_OFFSET_LIMIT_KEY

public static final String CHECK_OFFSET_LIMIT_KEY
Whether to warn about offsets being off limits, default: true.

See Also:
Constant Field Values

CHECK_WORD_COUNT_LIMIT_KEY

public static final String CHECK_WORD_COUNT_LIMIT_KEY
Whether to warn about word count being off limits, default: true.

See Also:
Constant Field Values

CHECK_LEX_ID_LIMIT_KEY

public static final String CHECK_LEX_ID_LIMIT_KEY
Whether to warn about lex id being off limits, default: true.

See Also:
Constant Field Values

CHECK_POINTER_INDEX_LIMIT_KEY

public static final String CHECK_POINTER_INDEX_LIMIT_KEY
Whether to warn about pointer target indices being off limits, default: true

See Also:
Constant Field Values

CHECK_VERB_FRAME_LIMIT_KEY

public static final String CHECK_VERB_FRAME_LIMIT_KEY
Whether to warn about verb frame indices being off limits, default: true

See Also:
Constant Field Values

READ_ONLY

public static final String READ_ONLY
Read-only file permission.

See Also:
Constant Field Values

READ_WRITE

public static final String READ_WRITE
Read-write file permission.

See Also:
Constant Field Values

raFile

protected RandomAccessFile raFile
The random-access file.

Constructor Detail

PrincetonRandomAccessDictionaryFile

public PrincetonRandomAccessDictionaryFile(Dictionary dictionary,
                                           Map<String,Param> params)

PrincetonRandomAccessDictionaryFile

public PrincetonRandomAccessDictionaryFile(Dictionary dictionary,
                                           String path,
                                           POS pos,
                                           DictionaryFileType fileType,
                                           Map<String,Param> params)
Method Detail

newInstance

public PrincetonRandomAccessDictionaryFile newInstance(Dictionary dictionary,
                                                       String path,
                                                       POS pos,
                                                       DictionaryFileType fileType)
Description copied from interface: DictionaryFileFactory
Creates a new instance of the dictionary file.

Specified by:
newInstance in interface DictionaryFileFactory<PrincetonRandomAccessDictionaryFile>
Parameters:
dictionary - owner dictionary
path - path to dictionary files
pos - part of speech
fileType - file type
Returns:
a new instance of the dictionary file

readLine

public String readLine()
                throws IOException
Description copied from interface: RandomAccessDictionaryFile
Reads a line from the file.

Specified by:
readLine in interface RandomAccessDictionaryFile
Returns:
a line from the file
Throws:
IOException - IOException

readLineWord

public String readLineWord()
                    throws IOException
Description copied from interface: RandomAccessDictionaryFile
Reads the first word from a file (ie offset, index word).

Specified by:
readLineWord in interface RandomAccessDictionaryFile
Returns:
the first word from a file (ie offset, index word)
Throws:
IOException - IOException

seek

public void seek(long pos)
          throws IOException
Description copied from interface: RandomAccessDictionaryFile
Goes to position pos in the file.

Specified by:
seek in interface RandomAccessDictionaryFile
Parameters:
pos - position pos in the file
Throws:
IOException - IOException

getFilePointer

public long getFilePointer()
                    throws IOException
Description copied from interface: RandomAccessDictionaryFile
Returns the current position of the file pointer.

Specified by:
getFilePointer in interface RandomAccessDictionaryFile
Returns:
the current position of the file pointer
Throws:
IOException - IOException

isOpen

public boolean isOpen()
Description copied from interface: DictionaryFile
Returns true if the file is open.

Specified by:
isOpen in interface DictionaryFile
Returns:
true if the file is open

close

public void close()
Description copied from interface: DictionaryFile
Closes the file.

Specified by:
close in interface DictionaryFile
Overrides:
close in class AbstractDictionaryFile

openFile

protected void openFile()
                 throws IOException
Here we try to be intelligent about opening files. If the file does not already exist, we assume that we are going to be creating it and writing to it, otherwise we assume that we are going to be reading from it.

Specified by:
openFile in class AbstractDictionaryFile
Throws:
IOException - IOException

edit

public void edit()
          throws IOException
Description copied from interface: DictionaryFile
Reopens file in write mode.

Specified by:
edit in interface DictionaryFile
Overrides:
edit in class AbstractPrincetonRandomAccessDictionaryFile
Throws:
IOException - IOException

length

public long length()
            throws IOException
Description copied from interface: RandomAccessDictionaryFile
Returns the length, in bytes, of the file.

Specified by:
length in interface RandomAccessDictionaryFile
Returns:
the length, in bytes, of the file
Throws:
IOException - IOException

read

public int read()
         throws IOException
Description copied from interface: RandomAccessDictionaryFile
Reads a byte from the file.

Specified by:
read in interface RandomAccessDictionaryFile
Returns:
a byte from the file
Throws:
IOException - IOException

save

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

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

writeLine

public void writeLine(String line)
               throws IOException
Description copied from interface: RandomAccessDictionaryFile
Writes a line to the file.

Specified by:
writeLine in interface RandomAccessDictionaryFile
Overrides:
writeLine in class AbstractPrincetonRandomAccessDictionaryFile
Parameters:
line - a line to write
Throws:
IOException - IOException

writeStrings

public void writeStrings(Collection<String> strings)
                  throws IOException
Description copied from interface: RandomAccessDictionaryFile
Writes strings in file.

Specified by:
writeStrings in interface RandomAccessDictionaryFile
Overrides:
writeStrings in class AbstractPrincetonRandomAccessDictionaryFile
Parameters:
strings - strings to write
Throws:
IOException - IOException

writeIndexStrings

public void writeIndexStrings(ArrayList<String> strings)
                       throws IOException
Throws:
IOException

getOffsetFormatString

public String getOffsetFormatString()
Description copied from interface: RandomAccessDictionaryFile
Returns offset format string that accommodates largest offset.

Specified by:
getOffsetFormatString in interface RandomAccessDictionaryFile
Overrides:
getOffsetFormatString in class AbstractPrincetonRandomAccessDictionaryFile
Returns:
offset format string that accommodates largest offset


Copyright © 2011. All Rights Reserved.