private void buildRules(BufferedReader in) throws IOException { String read = null; Vector ruleList = new Vector(); while ((read = in.readLine()) != null) { buildRule(realTrimmer(read), ruleList); } ruleArray = new TransformationRule[ruleList.size()]; ruleList.copyInto(ruleArray); }
/** * Construct a transformation table from the phonetic file * @param phonetic the phonetic file as specified in aspell. The file is * supplied as a reader. * @throws java.io.IOException indicates a problem while reading * the phonetic information */ public GenericTransformator(Reader phonetic) throws IOException { buildRules(new BufferedReader(phonetic)); alphabetString = washAlphabetIntoReplaceList(getReplaceList()); }
/** * Constructs a new SpellDictionaryASpell * @param phonetic The Reader to use for phonetic transformation of the * words list. If <code>phonetic</code> is null, the the transformation * uses {@link DoubleMeta} transformation. * @throws java.io.IOException indicates problems reading the phonetic * information */ public SpellDictionaryASpell(Reader phonetic) throws IOException { if (phonetic == null) tf = new DoubleMeta(); else tf = new GenericTransformator(phonetic); }
/** * Goes through an alphabet and makes sure that only one of those letters * that are coded equally will be in the replace list. * In other words, it removes any letters in the alphabet * that are redundant phonetically. * * This is done to improve speed in the getSuggestion method. * * @param alphabet The complete alphabet to wash. * @return The washed alphabet to be used as replace list. */ private char[] washAlphabetIntoReplaceList(char[] alphabet) { HashMap letters = new HashMap(alphabet.length); for (int i = 0; i < alphabet.length; i++) { String tmp = String.valueOf(alphabet[i]); String code = transform(tmp); if (!letters.containsKey(code)) { letters.put(code, new Character(alphabet[i])); } } Object[] tmpCharacters = letters.values().toArray(); char[] washedArray = new char[tmpCharacters.length]; for (int i = 0; i < tmpCharacters.length; i++) { washedArray[i] = ((Character) tmpCharacters[i]).charValue(); } return washedArray; }
} else { if (match) { if (!isReservedChar(str.charAt(i))) { matchExp.append(str.charAt(i)); if (!inMulti) {
/** * Constructs a new SpellDictionaryASpell * @param phonetic The file to use for phonetic transformation of the * words list. If <code>phonetic</code> is null, the the transformation * uses {@link DoubleMeta} transformation. * @throws java.io.IOException indicates problems reading the phonetic * information */ public SpellDictionaryASpell(File phonetic) throws IOException { if (phonetic == null) tf = new DoubleMeta(); else tf = new GenericTransformator(phonetic); }
/** * Construct a transformation table from the phonetic file * @param phonetic the phonetic file as specified in aspell * @throws java.io.IOException indicates a problem while reading * the phonetic file */ public GenericTransformator(File phonetic) throws IOException { buildRules(new BufferedReader(new FileReader(phonetic))); alphabetString = washAlphabetIntoReplaceList(getReplaceList()); }
/** * Constructs a new SpellDictionaryASpell * @param phonetic The file to use for phonetic transformation of the * words list. If <code>phonetic</code> is null, the the transformation * uses {@link DoubleMeta} transformation. * @param encoding Uses the character set encoding specified * @throws java.io.IOException indicates problems reading the phonetic * information */ public SpellDictionaryASpell(File phonetic, String encoding) throws IOException { if (phonetic == null) tf = new DoubleMeta(); else tf = new GenericTransformator(phonetic, encoding); }
/** * Construct a transformation table from the phonetic file * @param phonetic the phonetic file as specified in aspell * @param encoding the character set required * @throws java.io.IOException indicates a problem while reading * the phonetic file */ public GenericTransformator(File phonetic, String encoding) throws IOException { buildRules(new BufferedReader(new InputStreamReader(new FileInputStream(phonetic), encoding))); alphabetString = washAlphabetIntoReplaceList(getReplaceList()); }