Package org.languagetool.tools
Class Tools
- java.lang.Object
-
- org.languagetool.tools.Tools
-
public final class Tools extends java.lang.Object
-
-
Constructor Summary
Constructors Modifier Constructor Description private
Tools()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.List<RuleMatch>
checkBitext(java.lang.String src, java.lang.String trg, JLanguageTool srcLt, JLanguageTool trgLt, java.util.List<BitextRule> bRules)
Checks the bilingual input (bitext).static java.lang.String
correctText(java.lang.String contents, JLanguageTool lt)
Automatically applies suggestions to the text, as suggested by the rules that match.static java.lang.String
correctTextFromMatches(java.lang.String contents, java.util.List<RuleMatch> matches)
private static java.util.List<BitextRule>
getAllBuiltinBitextRules(Language language, java.util.ResourceBundle messages)
Use reflection to add bitext rules.static java.util.List<BitextRule>
getBitextRules(Language source, Language target)
Gets default bitext rules for a given pair of languagesstatic java.util.List<BitextRule>
getBitextRules(Language source, Language target, java.io.File externalBitextRuleFile)
Gets default bitext rules for a given pair of languagesstatic java.lang.String
getFullStackTrace(java.lang.Throwable e)
Get a stacktrace as a string.static java.io.InputStream
getStream(java.lang.String path)
Load a file from the classpath usingClass.getResourceAsStream(String)
.static java.net.URL
getUrl(java.lang.String url)
Create a URL object from a string.static java.lang.String
i18n(java.util.ResourceBundle messages, java.lang.String key, java.lang.Object... messageArguments)
Translate a text string based on our i18n files.static int
profileRulesOnLine(java.lang.String contents, JLanguageTool lt, Rule rule)
static java.util.List<BitextRule>
selectBitextRules(java.util.List<BitextRule> bRules, java.util.List<java.lang.String> disabledRules, java.util.List<java.lang.String> enabledRules, boolean useEnabledOnly)
Enable and disable bitext rules.static void
selectRules(JLanguageTool lt, java.util.List<java.lang.String> disabledRuleIds, java.util.List<java.lang.String> enabledRuleIds, boolean useEnabledOnly)
Enable and disable rules of the given LanguageTool instance.static void
selectRules(JLanguageTool lt, java.util.Set<CategoryId> disabledCategories, java.util.Set<CategoryId> enabledCategories, java.util.Set<java.lang.String> disabledRules, java.util.Set<java.lang.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 java.lang.String i18n(java.util.ResourceBundle messages, java.lang.String key, java.lang.Object... messageArguments)
Translate a text string based on our i18n files.- Since:
- 3.1
-
checkBitext
public static java.util.List<RuleMatch> checkBitext(java.lang.String src, java.lang.String trg, JLanguageTool srcLt, JLanguageTool trgLt, java.util.List<BitextRule> bRules) throws java.io.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:
java.io.IOException
- Since:
- 1.0.1
-
getBitextRules
public static java.util.List<BitextRule> getBitextRules(Language source, Language target) throws java.io.IOException, javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException
Gets default bitext rules for a given pair of languages- Parameters:
source
- Source language.target
- Target language.- Returns:
- List of Bitext rules
- Throws:
java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
-
getBitextRules
public static java.util.List<BitextRule> getBitextRules(Language source, Language target, java.io.File externalBitextRuleFile) throws java.io.IOException, javax.xml.parsers.ParserConfigurationException, org.xml.sax.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:
java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
- Since:
- 2.9
-
getAllBuiltinBitextRules
private static java.util.List<BitextRule> getAllBuiltinBitextRules(Language language, java.util.ResourceBundle messages)
Use reflection to add bitext rules.
-
profileRulesOnLine
public static int profileRulesOnLine(java.lang.String contents, JLanguageTool lt, Rule rule) throws java.io.IOException
- Returns:
- the number of rule matches
- Throws:
java.io.IOException
-
correctText
public static java.lang.String correctText(java.lang.String contents, JLanguageTool lt) throws java.io.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:
java.io.IOException
-
correctTextFromMatches
public static java.lang.String correctTextFromMatches(java.lang.String contents, java.util.List<RuleMatch> matches)
- Since:
- 2.3
-
getFullStackTrace
public static java.lang.String getFullStackTrace(java.lang.Throwable e)
Get a stacktrace as a string.
-
getStream
public static java.io.InputStream getStream(java.lang.String path) throws java.io.IOException
Load a file from the classpath usingClass.getResourceAsStream(String)
. Please load files in therules
andresource
directories withResourceDataBroker
instead.- Throws:
java.io.IOException
-
selectRules
public static void selectRules(JLanguageTool lt, java.util.List<java.lang.String> disabledRuleIds, java.util.List<java.lang.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, java.util.Set<CategoryId> disabledCategories, java.util.Set<CategoryId> enabledCategories, java.util.Set<java.lang.String> disabledRules, java.util.Set<java.lang.String> enabledRules, boolean useEnabledOnly)
- Since:
- 3.3
-
selectBitextRules
public static java.util.List<BitextRule> selectBitextRules(java.util.List<BitextRule> bRules, java.util.List<java.lang.String> disabledRules, java.util.List<java.lang.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
-
getUrl
public static java.net.URL getUrl(java.lang.String url)
Create a URL object from a string. Helper method that turns theMalformedURLException
into aRuntimeException
.- Since:
- 4.0
-
-