|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object uk.ac.umist.co.brailletrans.LanguageUnicode
An implementation of Language
that works with Unicode strings and
Unicode language tables.
Copyright 1999, 2004 Alasdair King. This program is free software under the terms of the GNU General Public License.
Field Summary | |
static java.lang.String |
DATAFILE_EXTENSION
The filename extension for the unprocessed Language rules tables for this implementation of language. |
char |
ESCAPE_CHAR_1
The first character forming part of the escape sequence for unicode characters to be depicted in ASCII. |
char |
ESCAPE_CHAR_2
The second character forming part of the escape sequence for unicode characters to be depicted in ASCII. |
static java.lang.String |
FILENAME_EXTENSION
Filename extension for serialized LanguageUnicode objects
that can be loaded into memory by calling the constructor with their path
and name and used for translation. |
Fields inherited from interface uk.ac.umist.co.brailletrans.Language |
FILE_EXTENSION_DELIMITER, LEFT_FOCUS_DELIMITER, RIGHT_FOCUS_DELIMITER, RULE_BUFFER, RULE_CONTENT_DELIMITER, RULE_OUTPUT_DELIMITER, SPACE_FLAG, TABLE_DELIMITER, WILDCARD_FLAG, WILDCARD_NONE, WILDCARD_ONE, WILDCARD_SEVERAL |
Constructor Summary | |
LanguageUnicode()
Constructs a LanguageUnicode object without data ready to be filled with information for the language being created in the correct order. |
|
LanguageUnicode(java.lang.String filename)
Loads a LanguageUnicode object with all the language rules table information required for translation from disk. |
Method Summary | |
void |
addCharacterInformation(java.lang.Character from,
java.lang.Character to,
java.lang.Integer flagValue)
Adds the information for one Unicode character to the language. |
void |
addTranslationRule(java.lang.String toProcess)
Adds a new translation rule to the language. |
void |
addWildcardInformation(int wildcardNumber,
int wildcardFlags,
java.lang.Character wildcardChar)
Adds one wildcard's information to the language |
java.lang.String |
getDescription()
Returns the free text description of the language. |
java.lang.String |
getInputClassDescription(int inputClass)
Returns the language description for an input class. |
LanguageUnicode |
getLanguageUnicodeFromDisk(java.lang.String filename)
Loads a LanguageUnicode object from disk |
static LanguageUnicode |
getLanguageUnicodeFromWebsite(java.lang.String languageName)
Downloads a language file from the web. |
java.lang.String |
getName()
Returns the name of the language. |
int |
getNumberCharacters()
Returns the number of Unicode characters supported by this language. |
int |
getNumberInputClasses()
Returns the number of input classes available in the language. |
int |
getNumberStates()
Returns the number of states available in this language. |
int |
getNumberWildcards()
Returns the number of wildcards defined in the language |
int |
getPermittedStates()
Returns the states permitted in this language. |
int |
getState()
Returns the current state of the virtual machine. |
java.lang.String |
getStateDescription(int state)
Returns the language description for a state. |
int |
getVersionNumber()
Returns the version of the language |
void |
setDecisionTableEntry(int state,
int inputClass,
boolean value)
Sets a state table entry for the language. |
void |
setDescription(java.lang.String description)
Allows the free text description of the language to be set. |
void |
setInputClassDescription(int inputClass,
java.lang.String description)
Applies a description to one of the input classes of the language. |
void |
setName(java.lang.String name)
Allows the name of the language to be set. |
void |
setNumberCharacters(int numberCharacters)
Sets the number of Unicode characters supported by this new language. |
void |
setNumberInputClasses(int numberInputClasses)
Sets the number of input classes for the language. |
void |
setNumberStates(int numberStates)
Sets the number of states possible for the finite state machine of the language. |
void |
setNumberWildcards(int numberWildcards)
Defines the number of wildcards for this language. |
boolean |
setState(int newState)
Sets the state of the finite state machine performing the translation, and therefore controls the type of translation performed, depending on the translation language selected. |
void |
setStateDescription(int state,
java.lang.String description)
Applies a description to one of the finite state machine states. |
void |
setVersionNumber(int versionNumber)
Sets the version number of a LanguageUnicode object. |
int[] |
translate(int[] toConvert)
Performs translation from text to Braille or from Braille to text, depending on language and state. |
java.lang.String |
translate(java.lang.String toConvert)
Performs translation from text to Braille or from Braille to text, depending on language and state. |
void |
writeLanguageUnicodeToDisk(java.lang.String filename)
Writes the current language to disk as a serialized object. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String FILENAME_EXTENSION
LanguageUnicode
objects
that can be loaded into memory by calling the constructor with their path
and name and used for translation.
public static final java.lang.String DATAFILE_EXTENSION
public final char ESCAPE_CHAR_1
public final char ESCAPE_CHAR_2
Constructor Detail |
public LanguageUnicode()
public LanguageUnicode(java.lang.String filename) throws java.io.IOException, java.lang.ClassNotFoundException, java.io.FileNotFoundException
set
methods, then serialized to disk with
writeLanguageUnicodeToDisk
, before it can be loaded in by this
constructor. If a supplied LanguageUnicode object is provided, this can be
interrogated for its translation abilities with the get
methods.
filename
- Full path and name of serialized Java object as file to load,
excluding the filename extension. For example, language file "english.dat" in
"\languages" should be instantiated with LanguageUnicode myLanguage =
new LanguageUnicode("\languages\english");
Method Detail |
public LanguageUnicode getLanguageUnicodeFromDisk(java.lang.String filename) throws java.io.IOException, java.io.FileNotFoundException, java.io.StreamCorruptedException, java.lang.ClassNotFoundException
filename
- Full path and name of serialized Java object as file to load.
java.io.IOException
java.io.FileNotFoundException
java.io.StreamCorruptedException
java.lang.ClassNotFoundException
public boolean setState(int newState)
Language
setState
in interface Language
newState
- An int
containing the new state for the machine to take.
boolean
indicating whether setting the state was
successful. It will fail if the new state requested is outside
the limits of states for the language being used.public int getPermittedStates()
Language
getPermittedStates
in interface Language
int
, the number of states defined
for the language and hence the number of permitted
states. The state can be any integer from 1 to
numberStates
.public int getState()
Language
getState
in interface Language
int
state of the virtual machine, in the
range 1 to numberStates
.public java.lang.String translate(java.lang.String toConvert)
Language
translate
in interface Language
toConvert
- String
holding characters to translate.
String
holding the output text, characters now translated.public int[] translate(int[] toConvert)
Language
translate
in interface Language
toConvert
- int[]
holding characters to translate.
int[]
holding the output text, characters now translated.public void setNumberWildcards(int numberWildcards) throws LanguageDefinitionException
numberWildcards
- int number of wildcards.
LanguageDefinitionException
public int getNumberWildcards()
public int getVersionNumber()
public void addCharacterInformation(java.lang.Character from, java.lang.Character to, java.lang.Integer flagValue) throws LanguageDefinitionException
from
- Character object wrapping the character that will be mapped
from in normalising the input text.to
- Character object wrapping the character that is produced
when mapping the input text.flagValue
- The distinctive flags for the character in to.
LanguageDefinitionException
public void addWildcardInformation(int wildcardNumber, int wildcardFlags, java.lang.Character wildcardChar) throws LanguageDefinitionException
wildcardNumber
- The value indicating whether the wildcard matches
zero or more characters (WILDCARD_NONE), one character
(WILDCARD_ONE), or one or more characters
(WILDCARD_SEVERAL).wildcardFlags
- The distinctive flags that the wildcard matches.wildcardChar
- Character object wrapping the character used for the
wildcard.
LanguageDefinitionException
public void addTranslationRule(java.lang.String toProcess) throws LanguageDefinitionException
String
argument
must be in the format "inputclass [TAB] leftContext LEFT_FOCUS_DELIMITER
focus RIGHT_FOCUS_DELIMITER rightContext RULE_OUTPUT_DELIMITER output
RULE_CONTENT_DELIMITER [TAB] newState
". The CONSTANTS are inherited
from Language
.
toProcess
- String
containing whole translation rule content, input
class to new state.
LanguageDefinitionException
public void setName(java.lang.String name)
name
- String that will become the name of the language.public java.lang.String getName()
public void setDescription(java.lang.String description)
description
- String containing the description for the language.public java.lang.String getDescription()
public void setNumberCharacters(int numberCharacters) throws LanguageDefinitionException
numberCharacters
- int
number of characters for language.
LanguageDefinitionException
public int getNumberCharacters()
public void setNumberStates(int numberStates) throws LanguageDefinitionException
numberStates
- The number of possible states.
LanguageDefinitionException
public void setStateDescription(int state, java.lang.String description) throws LanguageDefinitionException
state
- The state to have a description applied to it.description
- A String containing the description to be applied.
LanguageDefinitionException
public java.lang.String getStateDescription(int state) throws LanguageDefinitionException, java.lang.ArrayIndexOutOfBoundsException
state
- The state for which the description is required.
LanguageDefinitionException
java.lang.ArrayIndexOutOfBoundsException
public java.lang.String getInputClassDescription(int inputClass) throws LanguageDefinitionException, java.lang.ArrayIndexOutOfBoundsException
inputClass
- The input class for which the description is required.
LanguageDefinitionException
java.lang.ArrayIndexOutOfBoundsException
public void setInputClassDescription(int inputClass, java.lang.String description) throws LanguageDefinitionException
inputClass
- The input class for which a description is being provided.description
- The description as a String for the input class.
LanguageDefinitionException
public void setNumberInputClasses(int numberInputClasses) throws LanguageDefinitionException
numberInputClasses
- Number of input classes for the language.
LanguageDefinitionException
public void setDecisionTableEntry(int state, int inputClass, boolean value) throws LanguageDefinitionException, java.lang.ArrayIndexOutOfBoundsException
state
- State of table.inputClass
- Input class of table.value
- Results to be entered.
LanguageDefinitionException
java.lang.ArrayIndexOutOfBoundsException
public int getNumberInputClasses()
public int getNumberStates()
setState
. States affect the translation performed.
public void setVersionNumber(int versionNumber)
LanguageUnicode
object. Version
is not used anywhere yet, so this can be used to differentiate languages but
should not be relied upon to do this.
public static LanguageUnicode getLanguageUnicodeFromWebsite(java.lang.String languageName) throws java.lang.Exception
LanguageUnicode. Instead, the language file name
can be passed to this method, and the language file will be obtained by HTTP.
As with other Language
implementations, the filename extension
should not be added. To get language "english", simply call
getLanguageUnicodeFromDisk("english");
- Parameters:
languageName
- String
name of language file to get.
- Returns:
- The
LanguageUnicode
received.
- Throws:
java.lang.Exception
public void writeLanguageUnicodeToDisk(java.lang.String filename) throws java.io.IOException
Language
filename
- String
showing full path and filename for object as file.
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |