Package org.languagetool.tools
Class Tools
- java.lang.Object
-
- org.languagetool.tools.Tools
-
public final class Tools extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<RuleMatch>
checkBitext(String src, String trg, JLanguageTool srcLt, JLanguageTool trgLt, List<BitextRule> bRules)
Checks the bilingual input (bitext).static String
correctText(String contents, JLanguageTool lt)
Automatically applies suggestions to the text, as suggested by the rules that match.static String
correctTextFromMatches(String contents, List<RuleMatch> matches)
static List<BitextRule>
getBitextRules(Language source, Language target)
Gets default bitext rules for a given pair of languagesstatic List<BitextRule>
getBitextRules(Language source, Language target, File externalBitextRuleFile)
Gets default bitext rules for a given pair of languagesstatic String
getFullStackTrace(Throwable e)
Get a stacktrace as a string.static InputStream
getStream(String path)
Load a file from the classpath usingClass.getResourceAsStream(String)
.static URL
getUrl(String url)
Create a URL object from a string.static String
i18n(ResourceBundle messages, String key, Object... messageArguments)
Translate a text string based on our i18n files.static int
profileRulesOnLine(String contents, JLanguageTool lt, Rule rule)
static List<BitextRule>
selectBitextRules(List<BitextRule> bRules, List<String> disabledRules, List<String> enabledRules, boolean useEnabledOnly)
Enable and disable bitext rules.static void
selectRules(JLanguageTool lt, List<String> disabledRuleIds, List<String> enabledRuleIds, boolean useEnabledOnly)
Enable and disable rules of the given LanguageTool instance.static void
selectRules(JLanguageTool lt, Set<CategoryId> disabledCategories, Set<CategoryId> enabledCategories, Set<String> disabledRules, Set<String> enabledRules, boolean useEnabledOnly)
static void
setPasswordAuthenticator()
CallsAuthenticator.setDefault()
with a password authenticator so that it's possible to use URLs of the formathttp://username:password@server
when loading XML files.
-
-
-
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
-
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
-
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 correctedlt
- 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 usingClass.getResourceAsStream(String)
. Please load files in therules
andresource
directories withResourceDataBroker
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 objectdisabledRuleIds
- ids of the rules to be disabledenabledRuleIds
- ids of the rules to be enableduseEnabledOnly
- if set totrue
, 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 rulesdisabledRules
- ids of rules to be disabledenabledRules
- ids of rules to be enabled (by default all are enabled)useEnabledOnly
- if set totrue
, if set totrue
, disable all rules except those enabled explicitly.- Returns:
- the list of rules to be used.
- Since:
- 2.8
-
setPasswordAuthenticator
public static void setPasswordAuthenticator()
CallsAuthenticator.setDefault()
with a password authenticator so that it's possible to use URLs of the formathttp://username:password@server
when loading XML files. If the password manager doesn't allow callingAuthenticator.setDefault()
, this will be silently ignored and the feature of using these URLs will not be available.- Since:
- 3.0
-
-