private void setUpRule(Language language) { lt = new JLanguageTool(language); for (Rule rule : lt.getAllRules()) { lt.disableRule(rule.getId()); } GenericUnpairedBracketsRule rule = new GenericUnpairedBracketsRule(TestTools.getEnglishMessages(), Arrays.asList("»"), Arrays.asList("«")); lt.addRule(rule); }
@Override public final RuleMatch[] match(List<AnalyzedSentence> sentences) { UnsyncStack<SymbolLocator> symbolStack = new UnsyncStack<>(); // the stack for pairing symbols UnsyncStack<SymbolLocator> ruleMatchStack = new UnsyncStack<>(); List<RuleMatch> ruleMatches = new ArrayList<>(); int startPosBase = 0; for (AnalyzedSentence sentence : sentences) { AnalyzedTokenReadings[] tokens = sentence.getTokensWithoutWhitespace(); for (int i = 1; i < tokens.length; i++) { for (int j = 0; j < startSymbols.length; j++) { if (fillSymbolStack(startPosBase, tokens, i, j, symbolStack, sentence)) { break; } } } for (AnalyzedTokenReadings readings : sentence.getTokens()) { startPosBase += readings.getToken().length(); } } for (SymbolLocator sLoc : symbolStack) { RuleMatch rMatch = createMatch(ruleMatches, ruleMatchStack, sLoc.getStartPos(), sLoc.getSymbol(), sLoc.getSentence()); if (rMatch != null) { ruleMatches.add(rMatch); } } return toRuleMatchArray(ruleMatches); }
@Nullable private RuleMatch createMatch(List<RuleMatch> ruleMatches, UnsyncStack<SymbolLocator> ruleMatchStack, int startPos, String symbol, AnalyzedSentence sentence) { if (!ruleMatchStack.empty()) { int index = findSymbolNum(symbol, endSymbols); if (index >= 0) { SymbolLocator rLoc = ruleMatchStack.peek(); if (rLoc.getSymbol().equals(startSymbols[index])) { if (ruleMatches.size() > rLoc.getIndex()) { ruleMatches.remove(rLoc.getIndex()); ruleMatchStack.pop(); return null; } } } } ruleMatchStack.push(new SymbolLocator(symbol, ruleMatches.size(), startPos, sentence)); String otherSymbol = findCorrespondingSymbol(symbol); String message = MessageFormat.format(messages.getString("unpaired_brackets"), otherSymbol); return new RuleMatch(this, sentence, startPos, startPos + symbol.length(), message); }
@Override public List<Rule> getRelevantRules(ResourceBundle messages, UserConfig userConfig, List<Language> altLanguages) { return Arrays.asList( new CommaWhitespaceRule(messages), new DoublePunctuationRule(messages), new GenericUnpairedBracketsRule(messages, Arrays.asList("[", "(", "{", "\"", "”"), Arrays.asList("]", ")", "}", "\"", "”")), new HunspellNoSuggestionRule(messages, this, userConfig, altLanguages), new UppercaseSentenceStartRule(messages, this), // abbreviation exceptions, done in DanishSentenceTokenizer // "WORD_REPEAT_RULE" implemented in grammar.xml new MultipleWhitespaceRule(messages, this) ); }
@Override public final RuleMatch[] match(List<AnalyzedSentence> sentences) { UnsyncStack<SymbolLocator> symbolStack = new UnsyncStack<>(); // the stack for pairing symbols UnsyncStack<SymbolLocator> ruleMatchStack = new UnsyncStack<>(); List<RuleMatch> ruleMatches = new ArrayList<>(); int startPosBase = 0; for (AnalyzedSentence sentence : sentences) { AnalyzedTokenReadings[] tokens = sentence.getTokensWithoutWhitespace(); for (int i = 1; i < tokens.length; i++) { for (int j = 0; j < startSymbols.length; j++) { if (fillSymbolStack(startPosBase, tokens, i, j, symbolStack, sentence)) { break; } } } for (AnalyzedTokenReadings readings : sentence.getTokens()) { startPosBase += readings.getToken().length(); } } for (SymbolLocator sLoc : symbolStack) { RuleMatch rMatch = createMatch(ruleMatches, ruleMatchStack, sLoc.getStartPos(), sLoc.getSymbol(), sLoc.getSentence()); if (rMatch != null) { ruleMatches.add(rMatch); } } return toRuleMatchArray(ruleMatches); }
@Nullable private RuleMatch createMatch(List<RuleMatch> ruleMatches, UnsyncStack<SymbolLocator> ruleMatchStack, int startPos, String symbol, AnalyzedSentence sentence) { if (!ruleMatchStack.empty()) { int index = findSymbolNum(symbol, endSymbols); if (index >= 0) { SymbolLocator rLoc = ruleMatchStack.peek(); if (rLoc.getSymbol().equals(startSymbols[index])) { if (ruleMatches.size() > rLoc.getIndex()) { ruleMatches.remove(rLoc.getIndex()); ruleMatchStack.pop(); return null; } } } } ruleMatchStack.push(new SymbolLocator(symbol, ruleMatches.size(), startPos, sentence)); String otherSymbol = findCorrespondingSymbol(symbol); String message = MessageFormat.format(messages.getString("unpaired_brackets"), otherSymbol); return new RuleMatch(this, sentence, startPos, startPos + symbol.length(), message); }
@Override public List<Rule> getRelevantRules(ResourceBundle messages, UserConfig userConfig, List<Language> altLanguages) throws IOException { return Arrays.asList( new CommaWhitespaceRule(messages), new DoublePunctuationRule(messages), new GenericUnpairedBracketsRule(messages), new MorfologikAsturianSpellerRule(messages, this, userConfig, altLanguages), new UppercaseSentenceStartRule(messages, this), new MultipleWhitespaceRule(messages, this) ); }
@Override public List<Rule> getRelevantRules(ResourceBundle messages, UserConfig userConfig, List<Language> altLanguages) throws IOException { return Arrays.asList( new CommaWhitespaceRule(messages), new DoublePunctuationRule(messages), new GenericUnpairedBracketsRule(messages), new UppercaseSentenceStartRule(messages, this), new MultipleWhitespaceRule(messages, this), // specific to Tagalog: new MorfologikTagalogSpellerRule(messages, this, userConfig, altLanguages) ); }
@Override public List<Rule> getRelevantRules(ResourceBundle messages) throws IOException { return Arrays.asList( new CommaWhitespaceRule(messages), new DoublePunctuationRule(messages), new GenericUnpairedBracketsRule(messages), new MorfologikLithuanianSpellerRule(messages, this), new UppercaseSentenceStartRule(messages, this), new MultipleWhitespaceRule(messages, this) ); }
@Override public List<Rule> getRelevantRules(ResourceBundle messages, UserConfig userConfig, List<Language> altLanguages) throws IOException { return Arrays.asList( new CommaWhitespaceRule(messages), new DoublePunctuationRule(messages), new GenericUnpairedBracketsRule(messages, Arrays.asList("[", "(", "{", "“", "«", "»", "¿", "¡"), Arrays.asList("]", ")", "}", "”", "»", "«", "?", "!")), new MorfologikSpanishSpellerRule(messages, this, userConfig, altLanguages), new UppercaseSentenceStartRule(messages, this), new WordRepeatRule(messages, this), new MultipleWhitespaceRule(messages, this), new SpanishWikipediaRule(messages) ); }
@Override public List<Rule> getRelevantRules(ResourceBundle messages, UserConfig userConfig, List<Language> altLanguages) throws IOException { return Arrays.asList( new WhitespaceBeforePunctuationRule(messages), new CommaWhitespaceRule(messages), new DoublePunctuationRule(messages), new GenericUnpairedBracketsRule(messages, Arrays.asList("[", "(", "{", "»", "«" /*"‘"*/), Arrays.asList("]", ")", "}", "«", "»" /*"’"*/)), new MorfologikItalianSpellerRule(messages, this, userConfig, altLanguages), new UppercaseSentenceStartRule(messages, this), new ItalianWordRepeatRule(messages, this), new MultipleWhitespaceRule(messages, this) ); }
@Override public List<Rule> getRelevantRules(ResourceBundle messages) throws IOException { return Arrays.asList( new CommaWhitespaceRule(messages), new DoublePunctuationRule(messages), new GenericUnpairedBracketsRule(messages, Arrays.asList("[", "(", "{" /*"«", "‘"*/), Arrays.asList("]", ")", "}" /*"»", French dialog can contain multiple sentences. */ /*"’" used in "d’arm" and many other words */)), new MorfologikYourLanguageSpellerRule(messages, this), new UppercaseSentenceStartRule(messages, this), new MultipleWhitespaceRule(messages, this), new SentenceWhitespaceRule(messages), // specific to French: new CompoundRule(messages), new QuestionWhitespaceRule(messages) ); }
@Override public List<Rule> getRelevantRules(ResourceBundle messages) throws IOException { return Arrays.asList( new CommaWhitespaceRule(messages), new DoublePunctuationRule(messages), new GenericUnpairedBracketsRule(messages), new MorfologikMalayalamSpellerRule(messages, this), new UppercaseSentenceStartRule(messages, this), new WordRepeatRule(messages, this), new MultipleWhitespaceRule(messages, this) ); }
@Override public List<Rule> getRelevantRules(ResourceBundle messages, UserConfig userConfig, List<Language> altLanguages) throws IOException { return Arrays.asList( new CommaWhitespaceRule(messages), new DoublePunctuationRule(messages), new GenericUnpairedBracketsRule(messages, Arrays.asList("[", "(", "{", "„", "»", "«", "\""), Arrays.asList("]", ")", "}", "“", "«", "»", "\"")), new UppercaseSentenceStartRule(messages, this), new WordRepeatRule(messages, this), new MultipleWhitespaceRule(messages, this), // specific to Slovak: new CompoundRule(messages), new MorfologikSlovakSpellerRule(messages, this, userConfig, altLanguages) //new SlovakVesRule(messages) ); }
@Override public List<Rule> getRelevantRules(ResourceBundle messages, UserConfig userConfig, List<Language> altLanguages) { return Arrays.asList( new CommaWhitespaceRule(messages), new DoublePunctuationRule(messages), new GenericUnpairedBracketsRule(messages), new HunspellNoSuggestionRule(messages, this, userConfig, altLanguages), new UppercaseSentenceStartRule(messages, this), new WordRepeatRule(messages, this), new MultipleWhitespaceRule(messages, this), new SentenceWhitespaceRule(messages) ); }
@Override public List<Rule> getRelevantRules(ResourceBundle messages, UserConfig userConfig, List<Language> altLanguages) throws IOException { return Arrays.asList( new CommaWhitespaceRule(messages), new DoublePunctuationRule(messages), new GenericUnpairedBracketsRule(messages), new HunspellRule(messages, this, userConfig, altLanguages), new UppercaseSentenceStartRule(messages, this), new WordRepeatRule(messages, this), new MultipleWhitespaceRule(messages, this), new CompoundRule(messages) ); }
protected List<Rule> getBasicRules(ResourceBundle messages) { return Arrays.asList( new CommaWhitespaceRule(messages, Example.wrong("Није шија<marker> ,</marker> него врат."), Example.fixed("Није шија<marker>,</marker> него врат.")), new DoublePunctuationRule(messages), new GenericUnpairedBracketsRule(messages, Arrays.asList("[", "(", "{", "„", "„", "\""), Arrays.asList("]", ")", "}", "”", "“", "\"")), new UppercaseSentenceStartRule(messages, this, Example.wrong("Почела је школа. <marker>ђаци</marker> су поново сели у клупе."), Example.fixed("Почела је школа. <marker>Ђаци</marker> су поново сели у клупе.")), new MultipleWhitespaceRule(messages, this), new SentenceWhitespaceRule(messages), new WordRepeatRule(messages, this) ); }
@Override public List<Rule> getRelevantRules(ResourceBundle messages, UserConfig userConfig, List<Language> altLanguages) throws IOException { return Arrays.asList( new CommaWhitespaceRule(messages), new DoublePunctuationRule(messages), new GenericUnpairedBracketsRule(messages, Arrays.asList("[", "(", "{", "“", "‹", "“", "„", "\""), Arrays.asList("]", ")", "}", "”", "›", "”", "”", "\"")), new UppercaseSentenceStartRule(messages, this), new MorfologikDutchSpellerRule(messages, this, userConfig, altLanguages), new MultipleWhitespaceRule(messages, this), new CompoundRule(messages), new DutchWrongWordInContextRule(messages), new WordCoherencyRule(messages), new SimpleReplaceRule(messages), new LongSentenceRule(messages, userConfig, -1, true), new PreferredWordRule(messages) ); }
Example.fixed("Tomamos café<marker>,</marker> queixo, bolachas e uvas.")), new DoublePunctuationRule(messages), new GenericUnpairedBracketsRule(messages, Arrays.asList("[", "(", "{", "“", "«", "»", "‘", "\"", "'"), Arrays.asList("]", ")", "}", "”", "»", "«", "’", "\"", "'")),
Example.wrong("Die Partei<marker> ,</marker> die die letzte Wahl gewann."), Example.fixed("Die Partei<marker>,</marker> die die letzte Wahl gewann.")), new GenericUnpairedBracketsRule(messages, Arrays.asList("[", "(", "{", "„", "»", "«", "\""), Arrays.asList("]", ")", "}", "“", "«", "»", "\"")),