Class AbstractSimpleReplaceRule2

java.lang.Object
org.languagetool.rules.Rule
org.languagetool.rules.AbstractSimpleReplaceRule2
Direct Known Subclasses:
AbstractCheckCaseRule, AmericanReplaceRule, ArabicDarjaRule, ArabicDiacriticsRule, ArabicHomophonesRule, ArabicInflectedOneWordReplaceRule, ArabicRedundancyRule, ArabicSimpleReplaceRule, ArabicTransVerbRule, ArabicWordinessRule, BrazilianPortugueseReplaceRule, BritishReplaceRule, EnglishDiacriticsRule, EnglishPlainEnglishRule, EnglishRedundancyRule, GalicianBarbarismsRule, GalicianRedundancyRule, GalicianWikipediaRule, GalicianWordinessRule, GreekRedundancyRule, KhmerSimpleReplaceRule, NewZealandReplaceRule, PortugalPortugueseReplaceRule, PortugueseArchaismsRule, PortugueseBarbarismsRule, PortugueseClicheRule, PortugueseDiacriticsRule, PortugueseRedundancyRule, PortugueseWeaselWordsRule, PortugueseWikipediaRule, PortugueseWordinessRule, ReplaceHomonymsRule, RussianSimpleReplaceRule, SimpleReplaceAnglicism, SimpleReplaceMultiwordsRule, SimpleReplaceProfanityRule, SimpleReplaceRule, SimpleReplaceRule, SimpleReplaceRule, SimpleReplaceRule, SimpleReplaceRule, SpanishWikipediaRule

public abstract class AbstractSimpleReplaceRule2 extends Rule
A rule that matches words which should not be used and suggests correct ones instead.

Unlike AbstractSimpleReplaceRule, it supports phrases (Ex: "aqua forte" -> "acvaforte"). Note: Merge this into AbstractSimpleReplaceRule

  • Field Details

    • initialized

      private volatile boolean initialized
    • mStartSpace

      private Map<String,Integer> mStartSpace
    • mStartNoSpace

      private Map<String,Integer> mStartNoSpace
    • mFullSpace

      private Map<String,SuggestionWithMessage> mFullSpace
    • mFullNoSpace

      private Map<String,SuggestionWithMessage> mFullNoSpace
    • MAX_TOKENS_IN_MULTIWORD

      private static final int MAX_TOKENS_IN_MULTIWORD
      See Also:
    • ignoreShortUppercaseWords

      private boolean ignoreShortUppercaseWords
    • MAX_LENGTH_SHORT_WORDS

      private int MAX_LENGTH_SHORT_WORDS
    • ruleHasSuggestions

      private boolean ruleHasSuggestions
    • language

      protected final Language language
    • subRuleSpecificIds

      protected boolean subRuleSpecificIds
  • Constructor Details

  • Method Details

    • isCheckingCase

      protected boolean isCheckingCase()
    • getFileNames

      public abstract List<String> getFileNames()
    • getFilePaths

      public List<URL> getFilePaths()
    • getId

      public abstract String getId()
      Description copied from class: Rule
      A string used to identify the rule in e.g. configuration files. This string is supposed to be unique and to stay the same in all upcoming versions of LanguageTool. It's supposed to contain only the characters A-Z and the underscore.
      Specified by:
      getId in class Rule
    • getDescription

      public abstract String getDescription()
      Description copied from class: Rule
      A short description of the error this rule can detect, usually in the language of the text that is checked.
      Specified by:
      getDescription in class Rule
      Returns:
      A string where $match will be replaced with the matching word.
    • getShort

      public abstract String getShort()
    • getMessage

      public abstract String getMessage()
      Returns:
      A string where $match will be replaced with the matching word and $suggestions will be replaced with the alternatives. This is the string shown to the user.
    • getSuggestionsSeparator

      public String getSuggestionsSeparator()
      Returns:
      the word used to separate multiple suggestions; used only before last suggestion, the rest are comma-separated.
    • getLocale

      public abstract Locale getLocale()
      locale used on case-conversion
    • useSubRuleSpecificIds

      public void useSubRuleSpecificIds()
      If this is set, each replacement pair will have its own rule ID, making rule deactivations more specific.
      Since:
      5.1
    • getCaseSensitivy

      public AbstractSimpleReplaceRule2.CaseSensitivy getCaseSensitivy()
    • getDescription

      public String getDescription(String details)
      Used if each input form the replacement file has its specific id.
    • match

      public RuleMatch[] match(AnalyzedSentence sentence)
      Description copied from class: Rule
      Check whether the given sentence matches this error rule, i.e. whether it contains the error detected by this rule. Note that the order in which this method is called is not always guaranteed, i.e. the sentence order in the text may be different from the order in which you get the sentences (this may be the case when LanguageTool is used as a LibreOffice/OpenOffice add-on, for example). In other words, implementations must be stateless, so that a previous call to this method has no influence on later calls.
      Specified by:
      match in class Rule
      Parameters:
      sentence - a pre-analyzed sentence
      Returns:
      an array of RuleMatch objects
    • createMatch

      private void createMatch(List<RuleMatch> ruleMatches, SuggestionWithMessage suggestionWithMessage, int startIndex, int endIndex, String originalStr, AnalyzedTokenReadings[] tokens, AnalyzedSentence sentence, int sentStart, int[] checkCaseCoveredUpto)
    • isRuleMatchException

      protected boolean isRuleMatchException(RuleMatch ruleMatch)
    • isException

      protected boolean isException(String matchedText)
    • isTokenException

      protected boolean isTokenException(AnalyzedTokenReadings atr)
    • checkKeyWordsAreKnownToSpeller

      public boolean checkKeyWordsAreKnownToSpeller()
      Create a warning if a key word of the replacement rule is not allowed by the speller rule.
    • checkKeyWordsAreUnknownToSpeller

      public boolean checkKeyWordsAreUnknownToSpeller()
      Create a warning if a key word of the replacement rule is allowed by the speller rule.
    • separateKeyWordsBySpeller

      public boolean separateKeyWordsBySpeller()
    • isPunctuationStart

      protected boolean isPunctuationStart(String word)
    • lazyInit

      private void lazyInit()
    • fillMaps

      private void fillMaps(Map<String,Integer> mStartSpace, Map<String,Integer> mStartNoSpace, Map<String,SuggestionWithMessage> mFullSpace, Map<String,SuggestionWithMessage> mFullNoSpace)
    • getAllFilePaths

      private List<URL> getAllFilePaths()
    • getWrongWords

      public List<Map<String,SuggestionWithMessage>> getWrongWords()
    • isIgnoreShortUppercaseWords

      protected boolean isIgnoreShortUppercaseWords()
    • setIgnoreShortUppercaseWords

      protected void setIgnoreShortUppercaseWords(boolean value)
    • setRuleHasSuggestions

      protected void setRuleHasSuggestions(boolean value)