• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SpellChecker类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.swabunga.spell.event.SpellChecker的典型用法代码示例。如果您正苦于以下问题:Java SpellChecker类的具体用法?Java SpellChecker怎么用?Java SpellChecker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SpellChecker类属于com.swabunga.spell.event包,在下文中一共展示了SpellChecker类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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());
                }
            }
        }
    }
}
 
开发者ID:andreymoser,项目名称:jspellchecker,代码行数:20,代码来源:JazzySpellCheckerServlet.java


示例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
    }
 
开发者ID:scheah,项目名称:eulexia,代码行数:23,代码来源:SpellCheck.java


示例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);
    }
}
 
开发者ID:killjoy1221,项目名称:TabbyChat-2,代码行数:26,代码来源:Spellcheck.java


示例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);
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:19,代码来源:JTextComponentSpellChecker.java


示例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();
    }
}
 
开发者ID:eclipse,项目名称:texlipse,代码行数:46,代码来源:TexSpellingEngine.java


示例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;
}
 
开发者ID:andreymoser,项目名称:jspellchecker,代码行数:13,代码来源:JazzySpellCheckerServlet.java


示例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;
}
 
开发者ID:andreymoser,项目名称:jspellchecker,代码行数:10,代码来源:JazzySpellCheckerServlet.java


示例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;
}
 
开发者ID:andreymoser,项目名称:jspellchecker,代码行数:18,代码来源:JazzySpellCheckerServlet.java


示例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);
}
 
开发者ID:andreymoser,项目名称:jspellchecker,代码行数:8,代码来源:JazzySpellCheckerServlet.java


示例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;
    }
  }
}
 
开发者ID:rquinio,项目名称:l10n-maven-plugin,代码行数:15,代码来源:SpellCheckError.java


示例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;
}
 
开发者ID:rquinio,项目名称:l10n-maven-plugin,代码行数:50,代码来源:SpellCheckValidator.java


示例12: initialize

import com.swabunga.spell.event.SpellChecker; //导入依赖的package包/类
private void initialize(){
    spellChecker = new SpellChecker(dictionaryHashMap);
    spellChecker.addSpellCheckListener(this);
}
 
开发者ID:ikhamlic,项目名称:esct-messenger-bot,代码行数:5,代码来源:JazzySpellChecker.java


示例13: clearSpellcheckerCache

import com.swabunga.spell.event.SpellChecker; //导入依赖的package包/类
@Override
protected void clearSpellcheckerCache() {
    spellcheckersCache.clear();
    spellcheckersCache = new Hashtable<String, SpellChecker>();
}
 
开发者ID:andreymoser,项目名称:jspellchecker,代码行数:6,代码来源:JazzySpellCheckerServlet.java


示例14: ListSpellCheckErrorListener

import com.swabunga.spell.event.SpellChecker; //导入依赖的package包/类
public ListSpellCheckErrorListener(SpellChecker spellChecker) {
  this.spellChecker = spellChecker;
}
 
开发者ID:rquinio,项目名称:l10n-maven-plugin,代码行数:4,代码来源:SpellCheckValidator.java


示例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;
}
 
开发者ID:andreymoser,项目名称:jspellchecker,代码行数:19,代码来源:JazzySpellCheckerServlet.java


示例16: getSpellChecker

import com.swabunga.spell.event.SpellChecker; //导入依赖的package包/类
SpellChecker getSpellChecker(Locale locale); 
开发者ID:rquinio,项目名称:l10n-maven-plugin,代码行数:2,代码来源:LocaleSpellCheckerRepository.java



注:本文中的com.swabunga.spell.event.SpellChecker类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java WXGesture类代码示例发布时间:2022-05-22
下一篇:
Java MaterialDrawableBuilder类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap