Class JLanguageTool

java.lang.Object
org.languagetool.JLanguageTool
Direct Known Subclasses:
MultiThreadedJLanguageTool, Pipeline

public class JLanguageTool extends Object
The main class used for checking text against different rules:
  • built-in Java rules (for English: a vs. an, whitespace after commas, ...)
  • built-in pattern rules loaded from external XML files (usually called grammar.xml)
  • your own implementation of the abstract Rule classes added with addRule(Rule)

You will probably want to use the sub class MultiThreadedJLanguageTool for best performance.

Thread-safety: this class is not thread safe. Create one instance per thread, but create the language only once (e.g. new AmericanEnglish) and use it for all instances of JLanguageTool.

See Also:
  • Field Details

    • logger

      private static final org.slf4j.Logger logger
    • ZERO_WIDTH_NBSP

      private static final Pattern ZERO_WIDTH_NBSP
    • VERSION

      @Nullable @Deprecated public static final String VERSION
      Deprecated.
      Please use LtBuildInfo.OS.getVersion() instead.
      LanguageTool version as a string like 2.3 or 2.4-SNAPSHOT.
    • BUILD_DATE

      @Nullable @Deprecated public static final String BUILD_DATE
      Deprecated.
      Please use LtBuildInfo.OS.getBuildDate() instead.
      LanguageTool build date and time like 2013-10-17 16:10 or null if not run from JAR.
    • GIT_SHORT_ID

      @Nullable @Deprecated public static final String GIT_SHORT_ID
      Deprecated.
      Please use LtBuildInfo.OS.getShortGitId() instead.
      Abbreviated git id or null if not available.
      Since:
      4.5
    • PATTERN_FILE

      public static final String PATTERN_FILE
      The name of the file with error patterns.
      See Also:
    • STYLE_FILE

      public static final String STYLE_FILE
      The name of the file with style patterns.
      See Also:
    • CUSTOM_PATTERN_FILE

      public static final String CUSTOM_PATTERN_FILE
      The name of the file with error patterns.
      See Also:
    • FALSE_FRIEND_FILE

      public static final String FALSE_FRIEND_FILE
      The name of the file with false friend information.
      See Also:
    • SENTENCE_START_TAGNAME

      public static final String SENTENCE_START_TAGNAME
      The internal tag used to mark the beginning of a sentence.
      See Also:
    • SENTENCE_END_TAGNAME

      public static final String SENTENCE_END_TAGNAME
      The internal tag used to mark the end of a sentence.
      See Also:
    • PARAGRAPH_END_TAGNAME

      public static final String PARAGRAPH_END_TAGNAME
      The internal tag used to mark the end of a paragraph.
      See Also:
    • MESSAGE_BUNDLE

      public static final String MESSAGE_BUNDLE
      Name of the message bundle for translations.
      See Also:
    • DICTIONARY_FILENAME_EXTENSION

      public static final String DICTIONARY_FILENAME_EXTENSION
      Extension of dictionary files read by Spellers
      See Also:
    • cache

      private final ResultCache cache
    • userConfig

      private final UserConfig userConfig
    • globalConfig

      private final GlobalConfig globalConfig
    • descProvider

      private final ShortDescriptionProvider descProvider
    • maxErrorsPerWordRate

      private float maxErrorsPerWordRate
    • dataBroker

      private static ResourceDataBroker dataBroker
    • classBroker

      private static ClassBroker classBroker
    • useCustomPasswordAuthenticator

      private static volatile boolean useCustomPasswordAuthenticator
    • builtinRules

      private final List<Rule> builtinRules
    • userRules

      private final List<Rule> userRules
    • optionalLanguageModelRules

      private final Set<String> optionalLanguageModelRules
    • disabledRules

      private final Set<String> disabledRules
    • disabledRuleCategories

      private final Set<CategoryId> disabledRuleCategories
    • enabledRules

      private final Set<String> enabledRules
    • enabledRuleCategories

      private final Set<CategoryId> enabledRuleCategories
    • language

      private final Language language
    • altLanguages

      private final List<Language> altLanguages
    • motherTongue

      private final Language motherTongue
    • inputLogging

      private final boolean inputLogging
    • matchFilters

      private final List<RuleMatchFilter> matchFilters
    • checkCancelledCallback

      private JLanguageTool.CheckCancelledCallback checkCancelledCallback
    • printStream

      private PrintStream printStream
    • listUnknownWords

      private boolean listUnknownWords
    • unknownWords

      private Set<String> unknownWords
    • cleanOverlappingMatches

      private boolean cleanOverlappingMatches
    • temporaryFiles

      private static final List<File> temporaryFiles
    • ruleSetCache

      private final Map<LevelToneTagCacheKey,RuleSet> ruleSetCache
  • Constructor Details

    • JLanguageTool

      public JLanguageTool(Language lang, Language motherTongue)
      Create a JLanguageTool and setup the built-in rules for the given language and false friend rules for the text language / mother tongue pair.
      Parameters:
      lang - the language of the text to be checked
      motherTongue - the user's mother tongue, used for false friend rules, or null. The mother tongue may also be used as a source language for checking bilingual texts.
    • JLanguageTool

      public JLanguageTool(Language language)
      Create a JLanguageTool and setup the built-in Java rules for the given language.
      Parameters:
      language - the language of the text to be checked
    • JLanguageTool

      public JLanguageTool(Language language, Language motherTongue, ResultCache cache)
      Create a JLanguageTool and setup the built-in rules for the given language and false friend rules for the text language / mother tongue pair.
      Parameters:
      language - the language of the text to be checked
      motherTongue - the user's mother tongue, used for false friend rules, or null. The mother tongue may also be used as a source language for checking bilingual texts.
      cache - a cache to speed up checking if the same sentences get checked more than once, e.g. when LT is running as a server and texts are re-checked due to changes
      Since:
      3.7
    • JLanguageTool

      public JLanguageTool(Language language, ResultCache cache, UserConfig userConfig)
      Create a JLanguageTool and setup the built-in rules for the given language and false friend rules for the text language / mother tongue pair.
      Parameters:
      language - the language of the text to be checked
      cache - a cache to speed up checking if the same sentences get checked more than once, e.g. when LT is running as a server and texts are re-checked due to changes. Use null to deactivate the cache.
      Since:
      4.2
    • JLanguageTool

      public JLanguageTool(Language language, List<Language> altLanguages, Language motherTongue, ResultCache cache, GlobalConfig globalConfig, UserConfig userConfig)
    • JLanguageTool

      public JLanguageTool(Language language, List<Language> altLanguages, Language motherTongue, ResultCache cache, GlobalConfig globalConfig, UserConfig userConfig, boolean inputLogging)
      Create a JLanguageTool and setup the built-in rules for the given language and false friend rules for the text language / mother tongue pair.
      Parameters:
      language - the language of the text to be checked
      altLanguages - The languages that are accepted as alternative languages - currently this means words are accepted if they are in an alternative language and not similar to a word from language. If there's a similar word in language, there will be an error of type RuleMatch.Type.Hint (EXPERIMENTAL)
      motherTongue - the user's mother tongue, used for false friend rules, or null. The mother tongue may also be used as a source language for checking bilingual texts.
      cache - a cache to speed up checking if the same sentences get checked more than once, e.g. when LT is running as a server and texts are re-checked due to changes
      inputLogging - allow inclusion of input in logs on exceptions
      Since:
      4.3
    • JLanguageTool

      public JLanguageTool(Language language, List<Language> altLanguages, Language motherTongue, ResultCache cache, GlobalConfig globalConfig, UserConfig userConfig, boolean inputLogging, boolean withLanguageModel)
      Create a JLanguageTool and setup the built-in rules for the given language and false friend rules for the text language / mother tongue pair.
      Parameters:
      language - the language of the text to be checked
      altLanguages - The languages that are accepted as alternative languages - currently this means words are accepted if they are in an alternative language and not similar to a word from language. If there's a similar word in language, there will be an error of type RuleMatch.Type.Hint (EXPERIMENTAL)
      motherTongue - the user's mother tongue, used for false friend rules, or null. The mother tongue may also be used as a source language for checking bilingual texts.
      cache - a cache to speed up checking if the same sentences get checked more than once, e.g. when LT is running as a server and texts are re-checked due to changes
      inputLogging - allow inclusion of input in logs on exceptions
      withLanguageModel - will not call updateOptionalLanguageModelRules(null) if this is true
      Since:
      6.6
    • JLanguageTool

      public JLanguageTool(Language language, Language motherTongue, ResultCache cache, UserConfig userConfig)
      Create a JLanguageTool and setup the built-in rules for the given language and false friend rules for the text language / mother tongue pair.
      Parameters:
      language - the language of the text to be checked
      motherTongue - the user's mother tongue, used for false friend rules, or null. The mother tongue may also be used as a source language for checking bilingual texts.
      cache - a cache to speed up checking if the same sentences get checked more than once, e.g. when LT is running as a server and texts are re-checked due to changes
      Since:
      4.2
  • Method Details