org.languagetool.rules.RuleMatch Java Examples
The following examples show how to use
org.languagetool.rules.RuleMatch.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TextHandler.java From chatbot with Apache License 2.0 | 6 votes |
private String sanitizeText(String message) { String result = message; try { List<RuleMatch> matches = helper.getLanguageTool().check(message); for (RuleMatch match : matches) { String error = message.substring(match.getFromPos(), match.getToPos()); List<String> replacements = match.getSuggestedReplacements(); if(replacements.size() > 0) { result = result.replace(error, match.getSuggestedReplacements().get(0)); } } } catch(Exception e) { e.printStackTrace(); } return result; }
Example #2
Source File: PeriodicTasksService.java From Open-LaTeX-Studio with MIT License | 6 votes |
private void spellCheckAllText() throws BadLocationException { Document doc = etc.getrSyntaxTextArea().getDocument(); if (doc != null) { String editorText = etc.getrSyntaxTextArea().getText(0, doc.getLength()); if (editorText != null) { Highlighter highlighter = etc.getrSyntaxTextArea().getHighlighter(); if(etc.getEditorState().isSpellCheckActive()) { List<RuleMatch> matches = null; try { matches = etc.getLangTool().check(editorText); } catch (IOException ex) { Exceptions.printStackTrace(ex); } highlighter.removeAllHighlights(); //Highlight the spelling check results for (RuleMatch match : matches) { highlighter.addHighlight(match.getFromPos(), match.getToPos(), etc.getPainter()); } } else { highlighter.removeAllHighlights(); } } } }
Example #3
Source File: Corrector.java From zest-writer with GNU General Public License v3.0 | 5 votes |
public String checkHtmlContent(String htmlContent) { AnnotatedText markup = makeAnnotatedText(htmlContent); StringBuilder bf = new StringBuilder(htmlContent); langTool.getAllActiveRules().stream().filter(rule -> rule instanceof SpellingCheckRule).forEach(rule -> ((SpellingCheckRule) rule).acceptPhrases(wordsToIgnore)); List<RuleMatch> matches = new ArrayList<>(); try { matches = langTool.check(markup); } catch (Exception e) { log.error(e.getMessage(), e); } int offset = 0; for (RuleMatch match : matches) { String desc = match.getMessage(); desc = new HtmlToPlainText().getPlainText(Jsoup.parse(desc)); if (!match.getSuggestedReplacements().isEmpty()) { desc += Configuration.getBundle().getString("ui.alert.correction.tooltip.suggestion") + match.getSuggestedReplacements(); } String before = "<span class=\"error-french\" title=\"" + desc + "\">"; bf.insert(match.getFromPos() + offset, before); offset += before.length(); String after = "</span> "; bf.insert(match.getToPos() + offset, after); offset += after.length(); } return bf.toString(); }
Example #4
Source File: Corrector.java From zest-writer with GNU General Public License v3.0 | 5 votes |
public String checkHtmlContentToText(String htmlContent, String source) { AnnotatedText markup = makeAnnotatedText(htmlContent); StringBuilder bf = new StringBuilder(); langTool.getAllActiveRules().stream().filter(rule -> rule instanceof SpellingCheckRule).forEach(rule -> ((SpellingCheckRule) rule).addIgnoreTokens(wordsToIgnore)); List<RuleMatch> matches = new ArrayList<>(); try { matches = langTool.check(markup); } catch (IOException e) { log.error(e.getMessage(), e); } for (RuleMatch match : matches) { String txt = htmlContent.substring(match.getFromPos(), match.getToPos()); bf.append("\n\n"); bf.append("> "); bf.append(markup.getPlainText().split("[\n|\r]")[match.getLine()].replace(txt, "**" + txt + "**")); bf.append("\n"); bf.append(Configuration.getBundle().getString("ui.alert.correction.source")).append(source); bf.append("\n\n"); bf.append(match.getRule().getDescription()); bf.append("\n\n"); for (String s : match.getSuggestedReplacements()) { bf.append("- ").append(s).append("\n"); } } return bf.toString(); }
Example #5
Source File: Corrector.java From zest-writer with GNU General Public License v3.0 | 5 votes |
public int countMistakes(MdTextController mdTextController, String markdown) { String htmlText = StringEscapeUtils.unescapeHtml4(MenuController.markdownToHtml(mdTextController, markdown)); AnnotatedText markup = makeAnnotatedText(htmlText); langTool.getAllActiveRules().stream() .filter(rule -> rule instanceof SpellingCheckRule).forEach(rule -> ((SpellingCheckRule) rule).acceptPhrases(wordsToIgnore)); try { List<RuleMatch> matches = langTool.check(markup); return matches.size(); } catch (IOException e) { log.error(e.getMessage(), e); } return 0; }