Class AbstractSimpleReplaceRule


  • public abstract class AbstractSimpleReplaceRule
    extends Rule
    A rule that matches words which should not be used and suggests correct ones instead. Loads the relevant words from rules/XX/replace.txt, where XX is a code of the language.
    • Field Detail

      • ignoreTaggedWords

        protected boolean ignoreTaggedWords
      • checkLemmas

        private boolean checkLemmas
    • Constructor Detail

      • AbstractSimpleReplaceRule

        public AbstractSimpleReplaceRule​(java.util.ResourceBundle messages)
    • Method Detail

      • getWrongWords

        protected abstract java.util.Map<java.lang.String,​java.util.List<java.lang.String>> getWrongWords()
      • loadFromPath

        protected static java.util.Map<java.lang.String,​java.util.List<java.lang.String>> loadFromPath​(java.lang.String path)
      • isCaseSensitive

        public boolean isCaseSensitive()
        Indicates if the rule is case-sensitive. Default value is true.
        Returns:
        true if the rule is case-sensitive, false otherwise.
      • getLocale

        public java.util.Locale getLocale()
        Returns:
        the locale used for case conversion when isCaseSensitive() is set to false.
      • setIgnoreTaggedWords

        public void setIgnoreTaggedWords()
        Skip words that are known in the POS tagging dictionary, assuming they cannot be incorrect.
        Since:
        2.3
      • getId

        public java.lang.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 java.lang.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
      • getMessage

        public java.lang.String getMessage​(java.lang.String tokenStr,
                                           java.util.List<java.lang.String> replacements)
      • getShort

        public java.lang.String getShort()
      • cleanup

        private java.lang.String cleanup​(java.lang.String word)
      • 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 than 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).
        Specified by:
        match in class Rule
        Parameters:
        sentence - a pre-analyzed sentence
        Returns:
        an array of RuleMatch objects
      • isTagged

        protected boolean isTagged​(AnalyzedTokenReadings tokenReadings)
        This method allows to override which tags will mark token as tagged
        Returns:
        returns true if token has valid tag
      • isCheckLemmas

        public boolean isCheckLemmas()
        Since:
        2.5
      • setCheckLemmas

        public void setCheckLemmas​(boolean checkLemmas)
        Used to disable matching lemmas.
        Since:
        2.5