本文整理汇总了Java中com.swabunga.spell.event.SpellChecker类的典型用法代码示例。如果您正苦于以下问题:Java SpellChecker类的具体用法?Java SpellChecker怎么用?Java SpellChecker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SpellChecker类属于com.swabunga.spell.event包,在下文中一共展示了SpellChecker类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addDictionaries
import com.swabunga.spell.event.SpellChecker; //导入依赖的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.event.SpellChecker; //导入依赖的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.event.SpellChecker; //导入依赖的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: JTextComponentSpellChecker
import com.swabunga.spell.event.SpellChecker; //导入依赖的package包/类
/**
*Constructor for the JTextComponentSpellChecker object
*
* @param dict Description of the Parameter
* @param userDict Description of the Parameter
* @param title Description of the Parameter
*/
public JTextComponentSpellChecker(SpellDictionary dict, SpellDictionary userDict, String title) {
spellCheck = new SpellChecker(dict);
mainDict = dict;
spellCheck.setCache();
if (userDict != null)
spellCheck.setUserDictionary(userDict);
spellCheck.addSpellCheckListener(this);
dialogTitle = title;
messages = ResourceBundle.getBundle("com.swabunga.spell.swing.messages", Locale.getDefault());
markHandler = new AutoSpellCheckHandler(spellCheck, messages);
}
示例5: check
import com.swabunga.spell.event.SpellChecker; //导入依赖的package包/类
public void check(IDocument document, IRegion[] regions, SpellingContext context,
ISpellingProblemCollector collector, IProgressMonitor monitor) {
if (ignore == null) {
ignore = new HashSet<String>();
}
IProject project = getProject(document);
String lang = DEFAULT_LANG;
if (project != null) {
lang = TexlipseProperties.getProjectProperty(project, TexlipseProperties.LANGUAGE_PROPERTY);
}
//Get spellchecker for the correct language
SpellChecker spellCheck = getSpellChecker(lang);
if (spellCheck == null) return;
if (collector instanceof TeXSpellingProblemCollector) {
((TeXSpellingProblemCollector) collector).setRegions(regions);
}
try {
spellCheck.addSpellCheckListener(this);
for (final IRegion r : regions) {
errors = new LinkedList<SpellCheckEvent>();
int roffset = r.getOffset();
//Create a new wordfinder and initialize it
TexlipseWordFinder wf = new TexlipseWordFinder();
wf.setIgnoreComments(TexlipsePlugin.getDefault().getPreferenceStore().getBoolean(TexlipseProperties.SPELLCHECKER_IGNORE_COMMENTS));
wf.setIgnoreMath(TexlipsePlugin.getDefault().getPreferenceStore().getBoolean(TexlipseProperties.SPELLCHECKER_IGNORE_MATH));
spellCheck.checkSpelling(new StringWordTokenizer(
document.get(roffset, r.getLength()), wf));
for (SpellCheckEvent error : errors) {
SpellingProblem p = new TexSpellingProblem(error, roffset, lang);
collector.accept(p);
}
}
spellCheck.removeSpellCheckListener(this);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
示例6: findMisspelledWords
import com.swabunga.spell.event.SpellChecker; //导入依赖的package包/类
protected List<String> findMisspelledWords(Iterator<String> checkedWordsIterator,
String lang) throws SpellCheckException {
List<String> misspelledWordsList = new ArrayList<String>();
SpellChecker checker = (SpellChecker) getChecker(lang);
while (checkedWordsIterator.hasNext()) {
String word = checkedWordsIterator.next();
if (!word.equals("") && !checker.isCorrect(word) && !checker.isCorrect(word.toLowerCase())) {
misspelledWordsList.add(word);
}
}
return misspelledWordsList;
}
示例7: findSuggestions
import com.swabunga.spell.event.SpellChecker; //导入依赖的package包/类
protected List<String> findSuggestions(String word, String lang, int maxSuggestions) throws SpellCheckException {
List<String> suggestionsList = new ArrayList<String>(maxSuggestions);
SpellChecker checker = (SpellChecker) getChecker(lang);
ListIterator<Word> suggestionsIt = checker.getSuggestions(word, maxSuggestions).listIterator();
while (suggestionsIt.hasNext()) {
suggestionsList.add(suggestionsIt.next().getWord());
}
return suggestionsList;
}
示例8: loadSpellChecker
import com.swabunga.spell.event.SpellChecker; //导入依赖的package包/类
/**
* Load the SpellChecker object form the file-system.
* TODO: It possibly worth to rework it to load from class-path, since current implementation assumes that WAR is exploded which is not always can be the case
*
* @param lang
* @return loaded SpellChecker object
* @throws SpellCheckException
*/
private SpellChecker loadSpellChecker(final String lang) throws SpellCheckException {
SpellChecker checker = new SpellChecker();
List<File> dictionariesFiles = getDictionaryFiles(lang);
addDictionaries(checker, dictionariesFiles);
configureSpellChecker(checker);
return checker;
}
示例9: configureSpellChecker
import com.swabunga.spell.event.SpellChecker; //导入依赖的package包/类
private void configureSpellChecker(SpellChecker checker) {
checker.getConfiguration().setBoolean(Configuration.SPELL_IGNOREDIGITWORDS, false);
checker.getConfiguration().setBoolean(Configuration.SPELL_IGNOREINTERNETADDRESSES, true);
checker.getConfiguration().setBoolean(Configuration.SPELL_IGNOREMIXEDCASE, true);
checker.getConfiguration().setBoolean(Configuration.SPELL_IGNOREUPPERCASE, true);
checker.getConfiguration().setBoolean(Configuration.SPELL_IGNORESENTENCECAPITALIZATION, false);
}
示例10: SpellCheckError
import com.swabunga.spell.event.SpellChecker; //导入依赖的package包/类
public SpellCheckError(SpellCheckEvent event, SpellChecker spellChecker) {
this.error = event.getInvalidWord();
this.position = event.getWordContextPosition();
// List<String> suggestions = event.getSuggestions();
List<Word> suggestions = spellChecker.getSuggestions(error, 1);
if (suggestions != null && suggestions.size() > 0) {
String firstSuggestion = suggestions.get(0).getWord();
if (!firstSuggestion.equals(this.error)) {
this.suggestion = firstSuggestion;
}
}
}
示例11: validate
import com.swabunga.spell.event.SpellChecker; //导入依赖的package包/类
/**
* WARN in case of spellcheck error using property locale.
*/
public int validate(Property property, List<L10nReportItem> reportItems) {
Locale locale = property.getLocale();
if (locale == null) {
// Case of root bundle
locale = Locale.ENGLISH;
}
SpellChecker spellChecker = spellCheckerLocaleRepository.getSpellChecker(locale);
if (spellChecker != null) {
ListSpellCheckErrorListener listener = new ListSpellCheckErrorListener(spellChecker);
spellChecker.addSpellCheckListener(listener);
String message = property.getMessage();
spellChecker.checkSpelling(new StringWordTokenizer(message));
Collection<SpellCheckError> errors = listener.getSpellCheckErrors();
// The message with errors replaced by suggestions
String correction = message;
// Start from last errors, so that error position remains valid
SpellCheckError[] errs = errors.toArray(new SpellCheckError[errors.size()]);
for (int i = errs.length - 1; i >= 0; i--) {
SpellCheckError error = errs[i];
if (error.getSuggestion() != null) {
int pos = error.getPosition();
correction = StringUtils.overlay(correction, error.getSuggestion(), pos, pos + error.getError().length());
}
}
if (errors.size() > 0) {
StringBuffer sb = new StringBuffer();
sb.append("Spellcheck error on word(s): ").append(errors.toString()).append(" and locale <").append(locale).append(">.");
if (correction != null) {
sb.append(" Suggested correction: [").append(correction).append("]");
}
L10nReportItem reportItem = new L10nReportItem(Type.SPELLCHECK, sb.toString(), property, null);
reportItems.add(reportItem);
logger.log(reportItem);
}
spellChecker.removeSpellCheckListener(listener);
}
return 0;
}
示例12: initialize
import com.swabunga.spell.event.SpellChecker; //导入依赖的package包/类
private void initialize(){
spellChecker = new SpellChecker(dictionaryHashMap);
spellChecker.addSpellCheckListener(this);
}
示例13: clearSpellcheckerCache
import com.swabunga.spell.event.SpellChecker; //导入依赖的package包/类
@Override
protected void clearSpellcheckerCache() {
spellcheckersCache.clear();
spellcheckersCache = new Hashtable<String, SpellChecker>();
}
示例14: ListSpellCheckErrorListener
import com.swabunga.spell.event.SpellChecker; //导入依赖的package包/类
public ListSpellCheckErrorListener(SpellChecker spellChecker) {
this.spellChecker = spellChecker;
}
示例15: getChecker
import com.swabunga.spell.event.SpellChecker; //导入依赖的package包/类
/**
* This method look for the already created SpellChecker object in the cache, if it is not present in the cache then
* it try to load it and put newly created object in the cache. SpellChecker loading is quite expensive operation
* to do it for every spell-checking request, so in-memory-caching here is almost a "MUST to have"
*
* @param lang the language code like "en" or "en-us"
* @return instance of jazzy SpellChecker
* @throws SpellCheckException if method failed to load the SpellChecker for lang (it happens if there is no
* dictionaries for that language was found in the classpath
*/
protected Object getChecker(String lang) throws SpellCheckException {
SpellChecker cachedChecker = spellcheckersCache.get(lang);
if (cachedChecker == null) {
cachedChecker = loadSpellChecker(lang);
spellcheckersCache.put(lang, cachedChecker);
}
return cachedChecker;
}