public abstract class RemoteRule extends Rule
Modifier and Type | Class and Description |
---|---|
protected static class |
RemoteRule.RemoteRequest |
Modifier and Type | Field and Description |
---|---|
protected static ConcurrentMap<String,io.github.resilience4j.circuitbreaker.CircuitBreaker> |
circuitBreakers |
protected boolean |
filterMatches |
protected boolean |
fixOffsets |
protected boolean |
inputLogging |
protected JLanguageTool |
lt |
protected boolean |
premium |
protected Language |
ruleLanguage |
protected RemoteRuleConfig |
serviceConfiguration |
protected static List<Runnable> |
shutdownRoutines |
protected Pattern |
suppressMisspelledMatch |
protected Pattern |
suppressMisspelledSuggestions |
protected boolean |
whitespaceNormalisation |
Constructor and Description |
---|
RemoteRule(Language language,
ResourceBundle messages,
RemoteRuleConfig config,
boolean inputLogging) |
RemoteRule(Language language,
ResourceBundle messages,
RemoteRuleConfig config,
boolean inputLogging,
String ruleId) |
Modifier and Type | Method and Description |
---|---|
io.github.resilience4j.circuitbreaker.CircuitBreaker |
circuitBreaker() |
protected io.github.resilience4j.circuitbreaker.CircuitBreaker |
createCircuitBreaker(String id) |
protected abstract Callable<RemoteRuleResult> |
executeRequest(RemoteRule.RemoteRequest request,
long timeoutMilliseconds) |
protected abstract RemoteRuleResult |
fallbackResults(RemoteRule.RemoteRequest request)
fallback if executeRequest times out or throws an error
|
static void |
fixMatchOffsets(AnalyzedSentence sentence,
List<RuleMatch> matches)
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'
|
String |
getId()
A string used to identify the rule in e.g. configuration files.
|
RemoteRuleConfig |
getServiceConfiguration() |
long |
getTimeout(long characters) |
boolean |
isPremium() |
RuleMatch[] |
match(AnalyzedSentence sentence)
Check whether the given sentence matches this error rule, i.e. whether it
contains the error detected by this rule.
|
protected abstract RemoteRule.RemoteRequest |
prepareRequest(List<AnalyzedSentence> sentences,
Long textSessionId)
run local preprocessing steps (or just store sentences)
|
FutureTask<RemoteRuleResult> |
run(List<AnalyzedSentence> sentences) |
FutureTask<RemoteRuleResult> |
run(List<AnalyzedSentence> sentences,
Long textSessionId) |
static void |
shutdown() |
addExamplePair, addTags, addToneTags, cacheAntiPatterns, estimateContextForSureMatch, getAntiPatterns, getCategory, getConfigureText, getCorrectExamples, getDefaultValue, getDescription, getDistanceTokens, getErrorTriggeringExamples, getFullId, getIncorrectExamples, getLocQualityIssueType, getMaxConfigurableValue, getMinConfigurableValue, getMinPrevMatches, getSentenceWithImmunization, getSourceFile, getSubId, getTags, getToneTags, getUrl, hasConfigurableValue, hasTag, hasToneTag, isDefaultOff, isDefaultTempOff, isDictionaryBasedSpellingRule, isGoalSpecific, isOfficeDefaultOff, isOfficeDefaultOn, makeAntiPatterns, setCategory, setCorrectExamples, setDefaultOff, setDefaultOn, setDefaultTempOff, setDistanceTokens, setErrorTriggeringExamples, setExamplePair, setGoalSpecific, setIncorrectExamples, setLocQualityIssueType, setMinPrevMatches, setOfficeDefaultOff, setOfficeDefaultOn, setPremium, setTags, setToneTags, setUrl, supportsLanguage, toRuleMatchArray, useInOffice
protected static final ConcurrentMap<String,io.github.resilience4j.circuitbreaker.CircuitBreaker> circuitBreakers
protected final RemoteRuleConfig serviceConfiguration
protected final boolean premium
protected final boolean inputLogging
protected final boolean filterMatches
protected final boolean fixOffsets
protected final boolean whitespaceNormalisation
protected final Language ruleLanguage
protected final JLanguageTool lt
protected final Pattern suppressMisspelledMatch
protected final Pattern suppressMisspelledSuggestions
public RemoteRule(Language language, ResourceBundle messages, RemoteRuleConfig config, boolean inputLogging, @Nullable String ruleId)
public RemoteRule(Language language, ResourceBundle messages, RemoteRuleConfig config, boolean inputLogging)
public static void shutdown()
public FutureTask<RemoteRuleResult> run(List<AnalyzedSentence> sentences)
protected abstract RemoteRule.RemoteRequest prepareRequest(List<AnalyzedSentence> sentences, @Nullable Long textSessionId)
sentences
- text to processtextSessionId
- session ID for caching, partial rollout, A/B testingprotected abstract Callable<RemoteRuleResult> executeRequest(RemoteRule.RemoteRequest request, long timeoutMilliseconds) throws TimeoutException
request
- returned by prepareRequesttimeoutMilliseconds
- timeout for this operation, <=0 -> unlimitedTimeoutException
- if timeout was exceededprotected abstract RemoteRuleResult fallbackResults(RemoteRule.RemoteRequest request)
request
- returned by prepareRequestprotected io.github.resilience4j.circuitbreaker.CircuitBreaker createCircuitBreaker(String id)
public FutureTask<RemoteRuleResult> run(List<AnalyzedSentence> sentences, @Nullable Long textSessionId)
sentences
- text to checktextSessionId
- ID for texts, should stay constant for a user session; used for A/B tests of experimental rulespublic long getTimeout(long characters)
public io.github.resilience4j.circuitbreaker.CircuitBreaker circuitBreaker()
public String getId()
Rule
A-Z
and the underscore.public RuleMatch[] match(AnalyzedSentence sentence) throws IOException
Rule
match
in class Rule
sentence
- a pre-analyzed sentenceRuleMatch
objectsIOException
public RemoteRuleConfig getServiceConfiguration()
public static void fixMatchOffsets(AnalyzedSentence sentence, List<RuleMatch> matches)