Package org.languagetool.server
Class Pipeline
java.lang.Object
org.languagetool.JLanguageTool
org.languagetool.server.Pipeline
Wrapper for JLanguageTool instances that can be made immutable.
Use case: Setup instances once (ahead of time or on demand), cache and use when matching queries come in;
work around thread safety issues by only giving out one reference at a time.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classNested classes/interfaces inherited from class org.languagetool.JLanguageTool
JLanguageTool.CheckCancelledCallback, JLanguageTool.Level, JLanguageTool.Mode, JLanguageTool.ParagraphHandling -
Field Summary
FieldsFields inherited from class org.languagetool.JLanguageTool
BUILD_DATE, CUSTOM_PATTERN_FILE, DICTIONARY_FILENAME_EXTENSION, FALSE_FRIEND_FILE, GIT_SHORT_ID, MESSAGE_BUNDLE, PARAGRAPH_END_TAGNAME, PATTERN_FILE, SENTENCE_END_TAGNAME, SENTENCE_START_TAGNAME, STYLE_FILE, VERSION -
Constructor Summary
ConstructorsConstructorDescriptionPipeline(Language language, List<Language> altLanguages, Language motherTongue, ResultCache cache, GlobalConfig globalConfig, UserConfig userConfig, boolean inputLogging) Pipeline(Language language, List<Language> altLanguages, Language motherTongue, ResultCache cache, GlobalConfig globalConfig, UserConfig userConfig, boolean inputLogging, boolean withLanguageModel) -
Method Summary
Modifier and TypeMethodDescriptionvoidactivateLanguageModelRules(File indexDir) Activate rules that depend on a language model.voidactivateRemoteRules(File configFile) voidactivateRemoteRules(List<RemoteRuleConfig> configs) voidaddMatchFilter(RuleMatchFilter filter) Add aRuleMatchFilterfor post-processing of rule matches Filters are called sequentially in the same order as addedvoidAdd a rule to be used by the next call to the check methods likeJLanguageTool.check(String).(package private) CheckResultscheckAnalyzedSentences(List<AnalyzedSentence> analyzed, RuleMatchListener listener) exposed here for GRPCServervoidDisable the given rule category so the check methods likeJLanguageTool.check(String)won't use it.voiddisableRule(String ruleId) Disable a given rule so the check methods likeJLanguageTool.check(String)won't use it.voiddisableRules(List<String> ruleIds) Disable the given rules so the check methods likeJLanguageTool.check(String)won't use them.voidenableRule(String ruleId) Enable a given rule so the check methods likeJLanguageTool.check(String)will use it.voidEnable all rules of the given category so the check methods likeJLanguageTool.check(String)will use it.Works like getAllActiveRules but overrides defaults by office defaultsGet all active (not disabled) rules for the current language that are built-in or that have been added using e.g.Get all rules for the current language that are built-in or that have been added usingJLanguageTool.addRule(Rule).Get all rule categories for the current language.Get rule ids of the rules that have been explicitly disabled.getPatternRulesByIdAndSubId(String Id, String subId) Get pattern rules by Id and SubId.Get the alphabetically sorted list of unknown words in the latest run of one of theJLanguageTool.check(String)methods.loadFalseFriendRules(String filename) Load false friend rules from an XML file.loadPatternRules(String filename) Load pattern rules from an XML file.private voidvoidsetCleanOverlappingMatches(boolean cleanOverlappingMatches) Whether theJLanguageTool.check(String)methods return overlapping errors.voidsetConfigValues(Map<String, Object[]> v) voidsetMaxErrorsPerWordRate(float maxErrorsPerWordRate) Maximum errors per word rate, checking will stop with an exception if the rate is higher.voidsetOutput(PrintStream printStream) Set a PrintStream that will receive verbose output.(package private) voidPrevents any further changes after this method was called.Methods inherited from class org.languagetool.JLanguageTool
addTemporaryFile, adjustRuleMatchPos, analyzeSentences, analyzeText, applyCustomFilters, check, check, check, check, check, check, check, check, check, check, check, check, check2, check2, checkAnalyzedSentence, checkAnalyzedSentence, checkInternal, checkInternal, computeSentenceData, fetchRemoteRuleResults, getAllSpellingCheckRules, getAnalyzedSentence, getClassBroker, getDataBroker, getLanguage, getMessageBundle, getMessageBundle, getRawAnalyzedSentence, isCategoryDisabled, isCustomPasswordAuthenticatorUsed, performCheck, printIfVerbose, printSentenceInfo, rememberUnknownWords, removeTemporaryFiles, sentenceTokenize, setCheckCancelledCallback, setClassBrokerBroker, setDataBroker, setListUnknownWords, useCustomPasswordAuthenticator
-
Field Details
-
setup
private boolean setup
-
-
Constructor Details
-
Pipeline
Pipeline(Language language, List<Language> altLanguages, Language motherTongue, ResultCache cache, GlobalConfig globalConfig, UserConfig userConfig, boolean inputLogging) -
Pipeline
Pipeline(Language language, List<Language> altLanguages, Language motherTongue, ResultCache cache, GlobalConfig globalConfig, UserConfig userConfig, boolean inputLogging, boolean withLanguageModel)
-
-
Method Details
-
setupFinished
void setupFinished()Prevents any further changes after this method was called. -
setCleanOverlappingMatches
public void setCleanOverlappingMatches(boolean cleanOverlappingMatches) Description copied from class:JLanguageToolWhether theJLanguageTool.check(String)methods return overlapping errors. If set totrue(default: true), it removes overlapping errors according to the priorities established for the language.- Overrides:
setCleanOverlappingMatchesin classJLanguageTool
-
preventModificationAfterSetup
private void preventModificationAfterSetup() -
setMaxErrorsPerWordRate
public void setMaxErrorsPerWordRate(float maxErrorsPerWordRate) Description copied from class:JLanguageToolMaximum errors per word rate, checking will stop with an exception if the rate is higher. For example, with a rate of 0.33, the checking would stop if the user's text has so many errors that more than every 3rd word causes a rule match. Note that this may not apply for very short texts.- Overrides:
setMaxErrorsPerWordRatein classJLanguageTool
-
setOutput
Description copied from class:JLanguageToolSet a PrintStream that will receive verbose output. Set tonull(which is the default) to disable verbose output.- Overrides:
setOutputin classJLanguageTool
-
loadPatternRules
Description copied from class:JLanguageToolLoad pattern rules from an XML file. UseJLanguageTool.addRule(Rule)to add these rules to the checking process.- Overrides:
loadPatternRulesin classJLanguageTool- Parameters:
filename- path to an XML file in the classpath or in the filesystem - the classpath is checked first- Returns:
- a List of
PatternRuleobjects - Throws:
IOException
-
loadFalseFriendRules
public List<AbstractPatternRule> loadFalseFriendRules(String filename) throws ParserConfigurationException, SAXException, IOException Description copied from class:JLanguageToolLoad false friend rules from an XML file. Only those pairs will be loaded that match the current text language and the mother tongue specified in the JLanguageTool constructor. UseJLanguageTool.addRule(Rule)to add these rules to the checking process.- Overrides:
loadFalseFriendRulesin classJLanguageTool- Parameters:
filename- path to an XML file in the classpath or in the filesystem - the classpath is checked first- Returns:
- a List of
PatternRuleobjects, or an empty list if mother tongue is not set - Throws:
ParserConfigurationExceptionSAXExceptionIOException
-
activateLanguageModelRules
Description copied from class:JLanguageToolActivate rules that depend on a language model. The language model currently consists of Lucene indexes with ngram occurrence counts.- Overrides:
activateLanguageModelRulesin classJLanguageTool- Parameters:
indexDir- directory with a '3grams' sub directory which contains a Lucene index with 3gram occurrence counts- Throws:
IOException
-
activateRemoteRules
- Overrides:
activateRemoteRulesin classJLanguageTool- Throws:
IOException
-
activateRemoteRules
- Overrides:
activateRemoteRulesin classJLanguageTool- Throws:
IOException
-
addMatchFilter
Description copied from class:JLanguageToolAdd aRuleMatchFilterfor post-processing of rule matches Filters are called sequentially in the same order as added- Overrides:
addMatchFilterin classJLanguageTool- Parameters:
filter- filter to add
-
addRule
Description copied from class:JLanguageToolAdd a rule to be used by the next call to the check methods likeJLanguageTool.check(String).- Overrides:
addRulein classJLanguageTool
-
disableRule
Description copied from class:JLanguageToolDisable a given rule so the check methods likeJLanguageTool.check(String)won't use it.- Overrides:
disableRulein classJLanguageTool- Parameters:
ruleId- the id of the rule to disable - no error will be thrown if the id does not exist- See Also:
-
disableRules
Description copied from class:JLanguageToolDisable the given rules so the check methods likeJLanguageTool.check(String)won't use them.- Overrides:
disableRulesin classJLanguageTool- Parameters:
ruleIds- the ids of the rules to disable - no error will be thrown if the id does not exist
-
disableCategory
Description copied from class:JLanguageToolDisable the given rule category so the check methods likeJLanguageTool.check(String)won't use it.- Overrides:
disableCategoryin classJLanguageTool- Parameters:
id- the id of the category to disable - no error will be thrown if the id does not exist- See Also:
-
getDisabledRules
Description copied from class:JLanguageToolGet rule ids of the rules that have been explicitly disabled.- Overrides:
getDisabledRulesin classJLanguageTool
-
enableRule
Description copied from class:JLanguageToolEnable a given rule so the check methods likeJLanguageTool.check(String)will use it. This will not throw an exception if the given rule id doesn't exist.- Overrides:
enableRulein classJLanguageTool- Parameters:
ruleId- the id of the rule to enable- See Also:
-
enableRuleCategory
Description copied from class:JLanguageToolEnable all rules of the given category so the check methods likeJLanguageTool.check(String)will use it. This will not throw an exception if the given rule id doesn't exist.- Overrides:
enableRuleCategoryin classJLanguageTool- See Also:
-
getUnknownWords
Description copied from class:JLanguageToolGet the alphabetically sorted list of unknown words in the latest run of one of theJLanguageTool.check(String)methods.- Overrides:
getUnknownWordsin classJLanguageTool
-
getCategories
Description copied from class:JLanguageToolGet all rule categories for the current language.- Overrides:
getCategoriesin classJLanguageTool- Returns:
- a map of
Categories, keyed by theirid.
-
getAllRules
Description copied from class:JLanguageToolGet all rules for the current language that are built-in or that have been added usingJLanguageTool.addRule(Rule). Please note that XML rules that are grouped will appear as multiple rules with the same id. To tell them apart, check if they are of typeAbstractPatternRule, cast them to that type and call theirAbstractPatternRule.getSubId()method.- Overrides:
getAllRulesin classJLanguageTool- Returns:
- a List of
Ruleobjects
-
getAllActiveRules
Description copied from class:JLanguageToolGet all active (not disabled) rules for the current language that are built-in or that have been added using e.g.JLanguageTool.addRule(Rule). SeeJLanguageTool.getAllRules()for hints about rule ids.- Overrides:
getAllActiveRulesin classJLanguageTool- Returns:
- a List of
Ruleobjects
-
getAllActiveOfficeRules
Description copied from class:JLanguageToolWorks like getAllActiveRules but overrides defaults by office defaults- Overrides:
getAllActiveOfficeRulesin classJLanguageTool- Returns:
- a List of
Ruleobjects
-
getPatternRulesByIdAndSubId
Description copied from class:JLanguageToolGet pattern rules by Id and SubId. This returns a list because rules that use<or>...</or>are internally expanded into several rules.- Overrides:
getPatternRulesByIdAndSubIdin classJLanguageTool- Returns:
- a List of
Ruleobjects
-
setConfigValues
- Overrides:
setConfigValuesin classJLanguageTool
-
checkAnalyzedSentences
CheckResults checkAnalyzedSentences(List<AnalyzedSentence> analyzed, RuleMatchListener listener) throws Exception exposed here for GRPCServer- Throws:
Exception
-