Package org.languagetool.rules
Class RemoteRule
java.lang.Object
org.languagetool.rules.Rule
org.languagetool.rules.RemoteRule
- Direct Known Subclasses:
BERTSuggestionRanking,GRPCRule,TestRemoteRule
- Since:
- 4.9
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final ConcurrentMap<String, io.github.resilience4j.circuitbreaker.CircuitBreaker> protected final booleanprotected final booleanprotected final booleanprivate static final org.slf4j.Loggerprotected final JLanguageToolprotected final booleanprotected final Languageprotected final RemoteRuleConfigprotected final Patternprotected final Patternprotected final boolean -
Constructor Summary
ConstructorsConstructorDescriptionRemoteRule(Language language, ResourceBundle messages, RemoteRuleConfig config, boolean inputLogging) RemoteRule(Language language, ResourceBundle messages, RemoteRuleConfig config, boolean inputLogging, String ruleId) -
Method Summary
Modifier and TypeMethodDescriptionio.github.resilience4j.circuitbreaker.CircuitBreaker(package private) static int[]Helper forfixMatchOffsets(org.languagetool.AnalyzedSentence, java.util.List<org.languagetool.rules.RuleMatch>)lookup table, find shifted index for i at shifts[i];protected io.github.resilience4j.circuitbreaker.CircuitBreakerprotected abstract Callable<RemoteRuleResult> executeRequest(RemoteRule.RemoteRequest request, long timeoutMilliseconds) protected abstract RemoteRuleResultfallbackResults(RemoteRule.RemoteRequest request) fallback if executeRequest times out or throws an errorstatic voidfixMatchOffsets(AnalyzedSentence sentence, List<RuleMatch> matches) Adapt match positions so that results from languages that thread emojis, etc.(package private) static io.github.resilience4j.circuitbreaker.CircuitBreakerConfiggetId()A string used to identify the rule in e.g.longgetTimeout(long characters) (package private) static longgetTimeout(RemoteRuleConfig serviceConfiguration, long characters) booleanmatch(AnalyzedSentence sentence) Check whether the given sentence matches this error rule, i.e.protected abstract RemoteRule.RemoteRequestprepareRequest(List<AnalyzedSentence> sentences, Long textSessionId) run local preprocessing steps (or just store sentences)run(List<AnalyzedSentence> sentences) run(List<AnalyzedSentence> sentences, Long textSessionId) static voidshutdown()suppressMisspelled(List<RuleMatch> sentenceMatches) Methods inherited from class org.languagetool.rules.Rule
addExamplePair, addTags, addToneTags, cacheAntiPatterns, estimateContextForSureMatch, getAntiPatterns, getCategory, getCorrectExamples, getDescription, getDistanceTokens, getErrorTriggeringExamples, getFullId, getIncorrectExamples, getLocQualityIssueType, getMinPrevMatches, getPriority, getRuleOptions, getSentenceWithImmunization, getSourceFile, getSubId, getTags, getToneTags, getUrl, hasTag, hasToneTag, isDefaultOff, isDefaultTempOff, isDictionaryBasedSpellingRule, isGoalSpecific, isIncludedInHiddenMatches, isOfficeDefaultOff, isOfficeDefaultOn, makeAntiPatterns, setCategory, setCorrectExamples, setDefaultOff, setDefaultOn, setDefaultTempOff, setDistanceTokens, setErrorTriggeringExamples, setExamplePair, setGoalSpecific, setIncludedInHiddenMatches, setIncorrectExamples, setLocQualityIssueType, setMinPrevMatches, setOfficeDefaultOff, setOfficeDefaultOn, setPremium, setPriority, setTags, setToneTags, setUrl, supportsLanguage, toRuleMatchArray, useInOffice
-
Field Details
-
logger
private static final org.slf4j.Logger logger -
shutdownRoutines
-
circuitBreakers
protected static final ConcurrentMap<String,io.github.resilience4j.circuitbreaker.CircuitBreaker> circuitBreakers -
serviceConfiguration
-
inputLogging
protected final boolean inputLogging -
filterMatches
protected final boolean filterMatches -
fixOffsets
protected final boolean fixOffsets -
whitespaceNormalisation
protected final boolean whitespaceNormalisation -
ruleLanguage
-
lt
-
suppressMisspelledMatch
-
suppressMisspelledSuggestions
-
-
Constructor Details
-
RemoteRule
public RemoteRule(Language language, ResourceBundle messages, RemoteRuleConfig config, boolean inputLogging, @Nullable String ruleId) -
RemoteRule
public RemoteRule(Language language, ResourceBundle messages, RemoteRuleConfig config, boolean inputLogging)
-
-
Method Details
-
shutdown
public static void shutdown() -
run
-
prepareRequest
protected abstract RemoteRule.RemoteRequest prepareRequest(List<AnalyzedSentence> sentences, @Nullable Long textSessionId) run local preprocessing steps (or just store sentences)- Parameters:
sentences- text to processtextSessionId- session ID for caching, partial rollout, A/B testing- Returns:
- parameter for executeRequest/fallbackResults
-
executeRequest
protected abstract Callable<RemoteRuleResult> executeRequest(RemoteRule.RemoteRequest request, long timeoutMilliseconds) throws TimeoutException - Parameters:
request- returned by prepareRequesttimeoutMilliseconds- timeout for this operation, <=0 -> unlimited- Returns:
- callable that sends request, parses and returns result for this remote rule
- Throws:
TimeoutException- if timeout was exceeded
-
fallbackResults
fallback if executeRequest times out or throws an error- Parameters:
request- returned by prepareRequest- Returns:
- local results for this rule
-
createCircuitBreaker
-
getCircuitBreakerConfig
@NotNull static io.github.resilience4j.circuitbreaker.CircuitBreakerConfig getCircuitBreakerConfig(RemoteRuleConfig c, String id) -
isPremium
public boolean isPremium() -
run
public FutureTask<RemoteRuleResult> run(List<AnalyzedSentence> sentences, @Nullable Long textSessionId) - Parameters:
sentences- text to checktextSessionId- ID for texts, should stay constant for a user session; used for A/B tests of experimental rules- Returns:
- Future with result
-
getTimeout
-
getTimeout
public long getTimeout(long characters) -
circuitBreaker
public io.github.resilience4j.circuitbreaker.CircuitBreaker circuitBreaker() -
suppressMisspelled
-
getId
Description copied from class:RuleA string used to identify the rule in e.g. configuration files. This string is supposed to be unique and to stay the same in all upcoming versions of LanguageTool. It's supposed to contain only the charactersA-Zand the underscore. -
match
Description copied from class:RuleCheck whether the given sentence matches this error rule, i.e. whether it contains the error detected by this rule. Note that the order in which this method is called is not always guaranteed, i.e. the sentence order in the text may be different from the order in which you get the sentences (this may be the case when LanguageTool is used as a LibreOffice/OpenOffice add-on, for example). In other words, implementations must be stateless, so that a previous call to this method has no influence on later calls.- Specified by:
matchin classRule- Parameters:
sentence- a pre-analyzed sentence- Returns:
- an array of
RuleMatchobjects - Throws:
IOException
-
getServiceConfiguration
-
computeOffsetShifts
Helper forfixMatchOffsets(org.languagetool.AnalyzedSentence, java.util.List<org.languagetool.rules.RuleMatch>)lookup table, find shifted index for i at shifts[i]; -
fixMatchOffsets
Adapt match positions so that results from languages that thread emojis, etc. as length 1 work for Java and match the normal offsets we use JavaScript also behaves like Java, so most clients will expect this behavior; but servers used for RemoteRules will often be written in Python (e.g. to access ML frameworks) based on offsetByCodePoints since codePointCount can be confusing, e.g. "👪".codePointCount(0,2) == 1, but length is 2 Java substring methods use this length (which can be >1 for a single character) whereas Python 3 indexing/slicing and len() in strings treat them as a single character so "😁foo".length() == 5, but len("😁foo") == 4; "😁foo".substring(2,5) == "foo" but "😁foo"[1:4] == 'foo'
-