Class Tools

java.lang.Object
org.languagetool.tools.Tools

public final class Tools extends Object
  • Constructor Details

    • Tools

      private Tools()
  • Method Details

    • i18n

      public static String i18n(ResourceBundle messages, String key, Object... messageArguments)
      Translate a text string based on our i18n files.
      Since:
      3.1
    • checkBitext

      public static List<RuleMatch> checkBitext(String src, String trg, JLanguageTool srcLt, JLanguageTool trgLt, List<BitextRule> bRules) throws IOException
      Checks the bilingual input (bitext).
      Parameters:
      src - Source text.
      trg - Target text.
      srcLt - Source JLanguageTool (used to analyze the text).
      trgLt - Target JLanguageTool (used to analyze the text).
      bRules - Bilingual rules used in addition to target standard rules.
      Returns:
      The list of rule matches on the bitext.
      Throws:
      IOException
      Since:
      1.0.1
    • getBitextRules

      public static List<BitextRule> getBitextRules(Language source, Language target) throws IOException, ParserConfigurationException, SAXException
      Gets default bitext rules for a given pair of languages
      Parameters:
      source - Source language.
      target - Target language.
      Returns:
      List of Bitext rules
      Throws:
      IOException
      ParserConfigurationException
      SAXException
    • getBitextRules

      public static List<BitextRule> getBitextRules(Language source, Language target, File externalBitextRuleFile) throws IOException, ParserConfigurationException, SAXException
      Gets default bitext rules for a given pair of languages
      Parameters:
      source - Source language.
      target - Target language.
      externalBitextRuleFile - external file with bitext rules
      Returns:
      List of Bitext rules
      Throws:
      IOException
      ParserConfigurationException
      SAXException
      Since:
      2.9
    • getAllBuiltinBitextRules

      private static List<BitextRule> getAllBuiltinBitextRules(Language language, ResourceBundle messages)
      Use reflection to add bitext rules.
    • profileRulesOnLine

      public static int profileRulesOnLine(String contents, JLanguageTool lt, Rule rule) throws IOException
      Returns:
      the number of rule matches
      Throws:
      IOException
    • correctText

      public static String correctText(String contents, JLanguageTool lt) throws IOException
      Automatically applies suggestions to the text, as suggested by the rules that match. Note: if there is more than one suggestion, always the first one is applied, and others are ignored silently.
      Parameters:
      contents - String to be corrected
      lt - Initialized LanguageTool object
      Returns:
      Corrected text as String.
      Throws:
      IOException
    • correctTextFromMatches

      public static String correctTextFromMatches(String contents, List<RuleMatch> matches)
      Since:
      2.3
    • getFullStackTrace

      public static String getFullStackTrace(Throwable e)
      Get a stacktrace as a string.
    • getStream

      public static InputStream getStream(String path) throws IOException
      Load a file from the classpath using Class.getResourceAsStream(String). Please load files in the rules and resource directories with ResourceDataBroker instead.
      Throws:
      IOException
    • selectRules

      public static void selectRules(JLanguageTool lt, List<String> disabledRuleIds, List<String> enabledRuleIds, boolean useEnabledOnly)
      Enable and disable rules of the given LanguageTool instance.
      Parameters:
      lt - LanguageTool object
      disabledRuleIds - ids of the rules to be disabled
      enabledRuleIds - ids of the rules to be enabled
      useEnabledOnly - if set to true, disable all rules except those enabled explicitly
    • selectRules

      public static void selectRules(JLanguageTool lt, Set<CategoryId> disabledCategories, Set<CategoryId> enabledCategories, Set<String> disabledRules, Set<String> enabledRules, boolean useEnabledOnly)
      Since:
      3.3
    • selectBitextRules

      public static List<BitextRule> selectBitextRules(List<BitextRule> bRules, List<String> disabledRules, List<String> enabledRules, boolean useEnabledOnly)
      Enable and disable bitext rules.
      Parameters:
      bRules - List of all bitext rules
      disabledRules - ids of rules to be disabled
      enabledRules - ids of rules to be enabled (by default all are enabled)
      useEnabledOnly - if set to true, if set to true, disable all rules except those enabled explicitly.
      Returns:
      the list of rules to be used.
      Since:
      2.8
    • setPasswordAuthenticator

      public static void setPasswordAuthenticator()
      Calls Authenticator.setDefault() with a password authenticator so that it's possible to use URLs of the format http://username:password@server when loading XML files. If the password manager doesn't allow calling Authenticator.setDefault(), this will be silently ignored and the feature of using these URLs will not be available.
      Since:
      3.0
    • getUrl

      public static URL getUrl(String url)
      Create a URL object from a string. Helper method that turns the MalformedURLException into a RuntimeException.
      Since:
      4.0