Class GenericTransformator

java.lang.Object
com.swabunga.spell.engine.GenericTransformator
All Implemented Interfaces:
Transformator

public class GenericTransformator extends Object implements Transformator
A Generic implementation of a transformator takes an aspell phonetics file and constructs some sort of transformation table using the inner class TransformationRule.

Basically, each transformation rule represent a line in the phonetic file. One line contains two groups of characters separated by white space(s). The first group is the match expression. The match expression describe letters to associate with a syllable. The second group is the replacement expression giving the phonetic equivalent of the match expression.
Author:
Robert Gustavsson (robert@lindesign.se)
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final char
    The alphabet end marker.
    static final char
    The alphabet start marker.
    static final String
    During phonetic transformation of a word each numeric character is replaced by this DIGITCODE.
    static final char
    End a group of characters which can be appended to the match expression of the phonetic file.
    static final String[]
    Phonetic file lines starting with the keywords are skipped.
    static final String
    Phonetic file keyword indicating that a different alphabet is used for this language.
    static final String
    Phonetic file character code indicating that the replace expression is empty.
    static final char
    Start a group of characters which can be appended to the match expression of the phonetic file.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a transformation table from the phonetic file
    GenericTransformator(File phonetic, String encoding)
    Construct a transformation table from the phonetic file
    Construct a transformation table from the phonetic file
  • Method Summary

    Modifier and Type
    Method
    Description
    char[]
    Takes out all single character replacements and put them in a char array.
    char[]
    Builds up an char array with the chars in the alphabet of the language as it was read from the alphabet tag in the phonetic file.
    Builds the phonetic code of the word.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ALPHABET_START

      public static final char ALPHABET_START
      The alphabet start marker.
      See Also:
    • ALPHABET_END

      public static final char ALPHABET_END
      The alphabet end marker.
      See Also:
    • KEYWORD_ALPHBET

      public static final String KEYWORD_ALPHBET
      Phonetic file keyword indicating that a different alphabet is used for this language. The keyword must be followed an ALPHABET_START marker, a list of characters defining the alphabet and a ALPHABET_END marker.
      See Also:
    • IGNORED_KEYWORDS

      public static final String[] IGNORED_KEYWORDS
      Phonetic file lines starting with the keywords are skipped. The key words are: version, followup, collapse_result. Comments, starting with '#', are also skipped to the end of line.
    • STARTMULTI

      public static final char STARTMULTI
      Start a group of characters which can be appended to the match expression of the phonetic file.
      See Also:
    • ENDMULTI

      public static final char ENDMULTI
      End a group of characters which can be appended to the match expression of the phonetic file.
      See Also:
    • DIGITCODE

      public static final String DIGITCODE
      During phonetic transformation of a word each numeric character is replaced by this DIGITCODE.
      See Also:
    • REPLACEVOID

      public static final String REPLACEVOID
      Phonetic file character code indicating that the replace expression is empty.
      See Also:
  • Constructor Details

    • GenericTransformator

      public GenericTransformator(File phonetic) throws IOException
      Construct a transformation table from the phonetic file
      Parameters:
      phonetic - the phonetic file as specified in aspell
      Throws:
      IOException - indicates a problem while reading the phonetic file
    • GenericTransformator

      public GenericTransformator(File phonetic, String encoding) throws IOException
      Construct a transformation table from the phonetic file
      Parameters:
      phonetic - the phonetic file as specified in aspell
      encoding - the character set required
      Throws:
      IOException - indicates a problem while reading the phonetic file
    • GenericTransformator

      public GenericTransformator(Reader phonetic) throws IOException
      Construct a transformation table from the phonetic file
      Parameters:
      phonetic - the phonetic file as specified in aspell. The file is supplied as a reader.
      Throws:
      IOException - indicates a problem while reading the phonetic information
  • Method Details

    • getCodeReplaceList

      public char[] getCodeReplaceList()
      Takes out all single character replacements and put them in a char array. This array can later be used for adding or changing letters in getSuggestion().
      Returns:
      char[] An array of chars with replacements characters
    • getReplaceList

      public char[] getReplaceList()
      Builds up an char array with the chars in the alphabet of the language as it was read from the alphabet tag in the phonetic file.
      Specified by:
      getReplaceList in interface Transformator
      Returns:
      char[] An array of chars representing the alphabet or null if no alphabet was available.
    • transform

      public String transform(String word)
      Builds the phonetic code of the word.
      Specified by:
      transform in interface Transformator
      Parameters:
      word - the word to transform
      Returns:
      the phonetic transformation of the word