public class PrincetonRandomAccessDictionaryFile extends AbstractPrincetonRandomAccessDictionaryFile implements DictionaryFileFactory<PrincetonRandomAccessDictionaryFile>, DictionaryDiskFile
RandomAccessDictionaryFile
that accesses files
named with Princeton's dictionary file naming convention.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CHECK_DATA_FILE_LINE_LENGTH_LIMIT_KEY
Whether to warn about data file line length being off limits, default: true.
|
static java.lang.String |
CHECK_LEX_FILE_NUMBER_KEY
Whether to warn about lex file numbers correctness, default: true.
|
static java.lang.String |
CHECK_LEX_ID_LIMIT_KEY
Whether to warn about lex id being off limits, default: true.
|
static java.lang.String |
CHECK_POINTER_INDEX_LIMIT_KEY
Whether to warn about pointer target indices being off limits, default: true
|
static java.lang.String |
CHECK_RELATION_LIMIT_KEY
Whether to warn about relation count being off limits, default: true.
|
static java.lang.String |
CHECK_VERB_FRAME_LIMIT_KEY
Whether to warn about verb frame indices being off limits, default: true
|
static java.lang.String |
CHECK_WORD_COUNT_LIMIT_KEY
Whether to warn about word count being off limits, default: true.
|
protected java.io.File |
file |
protected java.io.RandomAccessFile |
raFile |
protected long |
raFileLength |
static java.lang.String |
WRITE_PRINCETON_HEADER_KEY
Whether to add standard princeton header to files on save, default: false.
|
encoding, ENCODING_KEY
dictionary, fileType, params, path, pos
Constructor and Description |
---|
PrincetonRandomAccessDictionaryFile(Dictionary dictionary,
java.util.Map<java.lang.String,Param> params)
Factory constructor.
|
PrincetonRandomAccessDictionaryFile(Dictionary dictionary,
java.lang.String path,
POS pos,
DictionaryFileType fileType,
java.util.Map<java.lang.String,Param> params)
Instance constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the file.
|
boolean |
delete()
Deletes the file.
|
void |
edit()
Reopens file in write mode.
|
static void |
formatOffset(long i,
int formatLength,
java.lang.StringBuilder target) |
java.io.File |
getFile()
Returns the file.
|
long |
getFirstLineOffset()
Returns offset of the first line.
|
long |
getNextLineOffset(long offset)
Returns start of the next line or -1 if no new line.
|
int |
getOffsetLength()
Returns offset length that accommodates largest offset.
|
protected PointedCharSequence |
getPointedCharSequence(long offset,
byte[] line,
int i) |
protected boolean |
isInvalidOffset(long offset) |
boolean |
isOpen()
Returns true if the file is open.
|
long |
length()
Returns the length, in bytes, of the file.
|
PrincetonRandomAccessDictionaryFile |
newInstance(Dictionary dictionary,
java.lang.String path,
POS pos,
DictionaryFileType fileType)
Creates a new instance of dictionary file.
|
void |
open()
Opens the file.
|
PointedCharSequence |
readLine(long offset)
Reads starting at offset and till the end of line.
|
PointedCharSequence |
readWord(long offset)
Reads starting at offset and till space.
|
void |
save()
Saves the file.
|
void |
setOffsetLength(int length)
Sets offset length to be used while rendering the file.
|
protected void |
writePrincetonHeader() |
getFilename
getDictionary, getFileType, getPOS, setDictionary
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getFilename, getFileType, getPOS
getDictionary, setDictionary
public static final java.lang.String WRITE_PRINCETON_HEADER_KEY
public static final java.lang.String CHECK_LEX_FILE_NUMBER_KEY
public static final java.lang.String CHECK_RELATION_LIMIT_KEY
public static final java.lang.String CHECK_WORD_COUNT_LIMIT_KEY
public static final java.lang.String CHECK_LEX_ID_LIMIT_KEY
public static final java.lang.String CHECK_POINTER_INDEX_LIMIT_KEY
public static final java.lang.String CHECK_VERB_FRAME_LIMIT_KEY
public static final java.lang.String CHECK_DATA_FILE_LINE_LENGTH_LIMIT_KEY
protected final java.io.File file
protected java.io.RandomAccessFile raFile
protected long raFileLength
public PrincetonRandomAccessDictionaryFile(Dictionary dictionary, java.util.Map<java.lang.String,Param> params)
dictionary
- dictionaryparams
- paramspublic PrincetonRandomAccessDictionaryFile(Dictionary dictionary, java.lang.String path, POS pos, DictionaryFileType fileType, java.util.Map<java.lang.String,Param> params)
dictionary
- dictionarypath
- file pathpos
- part of speechfileType
- file typeparams
- paramspublic static void formatOffset(long i, int formatLength, java.lang.StringBuilder target)
public PrincetonRandomAccessDictionaryFile newInstance(Dictionary dictionary, java.lang.String path, POS pos, DictionaryFileType fileType)
DictionaryFileFactory
newInstance
in interface DictionaryFileFactory<PrincetonRandomAccessDictionaryFile>
dictionary
- owner dictionarypath
- path to dictionary filespos
- part of speechfileType
- file typepublic PointedCharSequence readLine(long offset) throws JWNLException
RandomAccessDictionaryFile
readLine
in interface RandomAccessDictionaryFile
offset
- offsetJWNLException
- JWNLExceptionpublic PointedCharSequence readWord(long offset) throws JWNLException
RandomAccessDictionaryFile
readWord
in interface RandomAccessDictionaryFile
offset
- offsetJWNLException
- JWNLExceptionpublic long getFirstLineOffset() throws JWNLException
RandomAccessDictionaryFile
getFirstLineOffset
in interface RandomAccessDictionaryFile
JWNLException
- JWNLExceptionpublic long getNextLineOffset(long offset) throws JWNLException
RandomAccessDictionaryFile
getNextLineOffset
in interface RandomAccessDictionaryFile
offset
- starting offsetJWNLException
- JWNLExceptionpublic void open() throws JWNLException
DictionaryFile
open
in interface DictionaryFile
JWNLException
- JWNLExceptionpublic boolean isOpen()
DictionaryFile
isOpen
in interface DictionaryFile
public void close() throws JWNLException
DictionaryFile
close
in interface DictionaryFile
JWNLException
- JWNLExceptionpublic void edit() throws JWNLException
DictionaryFile
edit
in interface DictionaryFile
JWNLException
- JWNLExceptionpublic long length() throws JWNLException
RandomAccessDictionaryFile
length
in interface RandomAccessDictionaryFile
JWNLException
- JWNLExceptionpublic void save() throws JWNLException
DictionaryFile
save
in interface DictionaryFile
JWNLException
- JWNLExceptionpublic int getOffsetLength() throws JWNLException
RandomAccessDictionaryFile
getOffsetLength
in interface RandomAccessDictionaryFile
JWNLException
- JWNLExceptionpublic void setOffsetLength(int length) throws JWNLException
RandomAccessDictionaryFile
setOffsetLength
in interface RandomAccessDictionaryFile
length
- offset length to be used while rendering the fileJWNLException
- JWNLExceptionpublic java.io.File getFile()
DictionaryDiskFile
getFile
in interface DictionaryDiskFile
public boolean delete() throws JWNLException
DictionaryDiskFile
delete
in interface DictionaryDiskFile
JWNLException
- JWNLExceptionprotected PointedCharSequence getPointedCharSequence(long offset, byte[] line, int i) throws JWNLIOException
JWNLIOException
protected boolean isInvalidOffset(long offset) throws JWNLException
JWNLException
protected void writePrincetonHeader() throws java.io.IOException
java.io.IOException