Package org.languagetool.tools
Class Tools
java.lang.Object
org.languagetool.tools.Tools
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncheckBitext
(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) private static List<BitextRule>
getAllBuiltinBitextRules
(Language language, ResourceBundle messages) Use reflection to add bitext rules.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
Get a stacktrace as a string.static InputStream
Load a file from the classpath usingClass.getResourceAsStream(String)
.static 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
CallsAuthenticator.setDefault()
with a password authenticator so that it's possible to use URLs of the formathttp://username:password@server
when loading XML files.
-
Constructor Details
-
Tools
private Tools()
-
-
Method Details
-
i18n
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
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
- Since:
- 2.3
-
getFullStackTrace
Get a stacktrace as a string. -
getStream
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
-
getUrl
Create a URL object from a string. Helper method that turns theMalformedURLException
into aRuntimeException
.- Since:
- 4.0
-