Class Tools


  • public final class Tools
    extends Object
    • Method Detail

      • 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
      • 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.
      • 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
      • 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