本文整理汇总了Java中com.swabunga.spell.engine.SpellDictionaryHashMap类的典型用法代码示例。如果您正苦于以下问题:Java SpellDictionaryHashMap类的具体用法?Java SpellDictionaryHashMap怎么用?Java SpellDictionaryHashMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SpellDictionaryHashMap类属于com.swabunga.spell.engine包,在下文中一共展示了SpellDictionaryHashMap类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addDictionaries
import com.swabunga.spell.engine.SpellDictionaryHashMap; //导入依赖的package包/类
private void addDictionaries(SpellChecker checker, List<File> langDictionaries) throws SpellCheckException {
for (File dicitonaryFile : langDictionaries) {
Reader dictionaryReader = null;
try {
dictionaryReader = new BufferedReader(new InputStreamReader(new FileInputStream(dicitonaryFile)));
checker.addDictionary(new SpellDictionaryHashMap(dictionaryReader));
} catch (Exception ex) {
throw new SpellCheckException("Failed to open dictionary=" + dicitonaryFile.getName(), ex);
} finally {
if (dictionaryReader != null) {
try {
dictionaryReader.close();
} catch (IOException e) {
logger.warning("Failed to close dictionary file " + dicitonaryFile.getPath());
}
}
}
}
}
示例2: SpellCheck
import com.swabunga.spell.engine.SpellDictionaryHashMap; //导入依赖的package包/类
protected SpellCheck(Context context/*, String bodyText*/) {
mContext = context;
//mOriginalText = bodyText;
AssetManager assetManager = context.getAssets();
try {
File directoryOnDisk = mContext.getFilesDir();
if (!directoryOnDisk.exists()) directoryOnDisk.mkdirs();
InputStream dictInputStream = assetManager.open(dictFile);
// Following code used for disk-based dictionary
// File dict = createFileFromInputStream(dictInputStream, dictFile);
// InputStream phoneticInputStream = assetManager.open(phoneticFile);
// File phonetic = createFileFromInputStream(phoneticInputStream, phoneticFile);
// mDictionary = new SpellDictionaryCachedDichoDisk(dict);
Reader reader = new InputStreamReader(dictInputStream, "UTF-8");
mDictionary = new SpellDictionaryHashMap(reader);
} catch (IOException e) {
e.printStackTrace();
}
jazzySpellCheck = new SpellChecker(mDictionary);
jazzySpellCheck.addSpellCheckListener(this); // callbacks implemented in this class, can possibly add listener to a different class
//jazzySpellCheck.checkSpelling(new StringWordTokenizer(bodyText)); // asynchronous
}
示例3: loadDictionary
import com.swabunga.spell.engine.SpellDictionaryHashMap; //导入依赖的package包/类
public synchronized void loadDictionary(LangDict lang) throws IOException {
if (lang == null || lang.equals(language)) {
return;
}
InputStream in = null;
Reader read = null;
try {
try {
in = lang.openStream();
} catch (FileNotFoundException e) {
TabbyChat.getLogger().warn(e + " Falling back to English.");
lang = LangDict.ENGLISH;
in = lang.openStream();
}
read = new InputStreamReader(in);
SpellDictionary dictionary = new SpellDictionaryHashMap(read);
spellCheck = new SpellChecker(dictionary);
spellCheck.setUserDictionary(userDict);
spellCheck.addSpellCheckListener(errors::add);
this.language = lang;
} finally {
Closeables.closeQuietly(in);
Closeables.closeQuietly(read);
}
}
示例4: SpellChecker
import com.swabunga.spell.engine.SpellDictionaryHashMap; //导入依赖的package包/类
/**
* Constructs the SpellChecker.
*/
public SpellChecker() {
try {
userdictionary = new SpellDictionaryHashMap();
}
catch (IOException e) {
throw new RuntimeException("this exception should never happen because we are using null phonetic file");
}
}
示例5: SpellCheckValidator
import com.swabunga.spell.engine.SpellDictionaryHashMap; //导入依赖的package包/类
/**
* Initialize by loading dictionaries following {@link Locale} naming convention
*
* @param logger
* @param directory
* dictionaries location
*/
public SpellCheckValidator(L10nValidatorLogger logger, File directory) {
super(logger);
spellCheckerLocaleRepository = new LocaleTreeSpellCheckerRepository(logger);
if (directory != null) {
logger.getLogger().info("Looking for .dic files in: " + directory.getAbsolutePath());
File[] files = directory.listFiles((FilenameFilter) new SuffixFileFilter(".dic"));
if (files == null || files.length == 0) {
logger.getLogger().warn("No dictionary file under folder " + directory.getAbsolutePath() + ". Skipping spellcheck validation.");
} else {
// Load each dictionary, using file name to detect associated locale
for (File file : files) {
try {
String fileName = FilenameUtils.getBaseName(file.getName());
String localePart = null;
String[] parts = fileName.split("_", 2);
if (parts[0].length() == 2) {
localePart = fileName;
} else if (parts.length == 2) {
localePart = parts[1];
}
Locale locale = PropertiesFileUtils.getLocale(localePart);
logger.getLogger().info("Loading file <" + file.getName() + "> associated to locale <" + locale + ">");
SpellDictionary dictionary = new SpellDictionaryHashMap(file);
spellCheckerLocaleRepository.addDictionary(locale, dictionary);
} catch (IOException e) {
logger.getLogger().error(e);
}
}
}
} else {
logger.getLogger().warn("No dictionary folder provided, skipping spellcheck validation.");
}
}
示例6: SpellChecker
import com.swabunga.spell.engine.SpellDictionaryHashMap; //导入依赖的package包/类
/**
* Constructs the SpellChecker.
*/
public SpellChecker() {
try {
userdictionary = new SpellDictionaryHashMap();
} catch (IOException e) {
throw new RuntimeException("this exception should never happen because we are using null phonetic file");
}
}
示例7: SpellChecker
import com.swabunga.spell.engine.SpellDictionaryHashMap; //导入依赖的package包/类
private SpellChecker(OpenNLP opennlp_) throws Exception {
opennlp = opennlp_;
InputStream im = this.getClass().getClassLoader().getResource("words.txt").openStream();
dict = new SpellDictionaryHashMap(new InputStreamReader(im));
}
示例8: JTextComponentSpellChecker
import com.swabunga.spell.engine.SpellDictionaryHashMap; //导入依赖的package包/类
/**
*Constructor for the JTextComponentSpellChecker object
*
* @param dictFile Description of the Parameter
* @param title Description of the Parameter
* @exception IOException Description of the Exception
*/
public JTextComponentSpellChecker(String dictFile, String title)
throws IOException {
this(new SpellDictionaryHashMap(new File(dictFile)), null, title);
}