public class FileBasedDictionaryImplementation<T extends FileBasedDictionary> extends Object implements DictionaryImplementation<T>
isInstance
test reads some bytes from the file to test, converts them to a string using the
superclass-supplied encoding and tests it against a regular expression.Modifier and Type | Field and Description |
---|---|
protected String |
encoding |
protected String |
name |
ZERO_CONFIDENCE
Constructor and Description |
---|
FileBasedDictionaryImplementation(String name,
String encoding,
boolean doEncodingTest,
Pattern pattern,
float maxConfidence,
int lookAtLength,
Constructor<T> dictionaryConstructor)
Creates a new implementation instance for some file based dictionary format.
|
Modifier and Type | Method and Description |
---|---|
T |
createInstance(String descriptor)
Creates a new dictionary instance using
dictionaryConstructor . |
protected Object[] |
getConstructorParameters(String descriptor)
Constructs the Object array passed to the Dictionary constructor.
|
Class<T> |
getDictionaryClass(String descriptor)
Returns the class of the dictionary which would be created for this descriptor by
createInstance . |
float |
getMaxConfidence()
Returns the confidence passed to the constructor.
|
String |
getName()
Returns the dictionary format name passed to the constructor.
|
TestResult |
isInstance(String descriptor)
Test if the descriptor points to a dictionary file supported by this implementation.
|
public FileBasedDictionaryImplementation(String name, String encoding, boolean doEncodingTest, Pattern pattern, float maxConfidence, int lookAtLength, Constructor<T> dictionaryConstructor)
name
- Name of the dictionary format.encoding
- Character encoding used by dictionary files.doEncodingTest
- If true
, Use the
CharacterEncodingDetector
to guess the encoding
of the tested file and return ZERO_CONFIDENCE
if it does not match
the encoding.pattern
- Regular expression to match against the start of a tested file.maxConfidence
- The confidence which is returned when the linePattern
matches.lookAtLength
- Number of bytes read from the tested file. If the file is shorter
than the given length, the file will be read completely.dictionaryConstructor
- Constructor used to create a new dictionary instance for
a matching file. The constructor must take a single File
as parameter.public TestResult isInstance(String descriptor)
lookAtLength
bytes are read from the file pointed to
by the descriptor. The byte array is converted to a string using encoding
and the pattern
is tested against it. If the pattern matches, the file
is accepted and maxConfidence
is returned.isInstance
in interface DictionaryImplementation<T extends FileBasedDictionary>
descriptor
- Descriptor of the dictionary to test.public float getMaxConfidence()
getMaxConfidence
in interface DictionaryImplementation<T extends FileBasedDictionary>
public String getName()
getName
in interface DictionaryImplementation<T extends FileBasedDictionary>
public T createInstance(String descriptor) throws DictionaryInstantiationException
dictionaryConstructor
.
The constructor is passed a File
wrapping the descriptor
as only
argument.createInstance
in interface DictionaryImplementation<T extends FileBasedDictionary>
descriptor
- Descriptor describing the instance. For file-based dictionaries
this is usually the path to the file.DictionaryInstantiationException
- if the instantiation of the dictionary failed.protected Object[] getConstructorParameters(String descriptor)
descriptor
- Dictionary descriptor passed to createInstancepublic Class<T> getDictionaryClass(String descriptor)
DictionaryImplementation
createInstance
.getDictionaryClass
in interface DictionaryImplementation<T extends FileBasedDictionary>
Copyright © 2001-2013 the JGloss developers. All Rights Reserved.