Package org.languagetool.rules
Class RuleMatch
java.lang.Object
org.languagetool.rules.RuleMatch
- All Implemented Interfaces:
Comparable<RuleMatch>
Information about an error rule that matches text and the position of the match.
See
ContextTools for displaying errors in their original text context.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class(package private) static class(package private) static class(package private) static class(package private) static classstatic enumUnlikeCategory, this is specific to a RuleMatch, not to a rule. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate RuleMatch.ColumnPositionstatic final RuleMatch[]private RuleMatch.LinePositionprivate Stringprivate RuleMatch.OffsetPositionprivate Stringprivate RuleMatch.PatternPositionprivate final Ruleprivate final AnalyzedSentenceprivate RuleMatch.SentencePositionprivate Stringprivate Stringprivate Supplier<List<SuggestedReplacement>> static final Stringstatic final Stringprivate booleanprivate RuleMatch.Typeprivate URL -
Constructor Summary
ConstructorsConstructorDescriptionRuleMatch(RuleMatch clone, List<SuggestedReplacement> replacements) RuleMatch(RuleMatch clone, List<SuggestedReplacement> replacements, boolean ignored) Deprecated.RuleMatch(Rule rule, int fromPos, int toPos, String message, String shortMessage, boolean startWithUppercase, String suggestionsOutMsg) Deprecated.use a constructor that also takes anAnalyzedSentenceparameter (deprecated since 4.0)RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, int patternStartPos, int patternEndPos, String message, String shortMessage) Creates a RuleMatch object, taking the rule that triggered this match, position of the match and an explanation message.RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, int patternFromPos, int patternToPos, String message, String shortMessage, boolean startWithUppercase, boolean isAllUppercase, String suggestionsOutMsg, boolean setOriginalErrorStr) Creates a RuleMatch object, taking the rule that triggered this match, position of the match and an explanation message.RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, int patternFromPos, int patternToPos, String message, String shortMessage, boolean startWithUppercase, String suggestionsOutMsg) RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, String message) Creates a RuleMatch object, taking the rule that triggered this match, position of the match and an explanation message.RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, String message, String shortMessage) Creates a RuleMatch object, taking the rule that triggered this match, position of the match and an explanation message.RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, String message, String shortMessage, List<String> suggestions) Create a rule match with any suggestions in the message overridden by the given suggestions -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSuggestedReplacement(String replacement) voidaddSuggestedReplacements(List<String> replacements) intCompare by start position.voidForce computing replacements, e.g.voidDiscard lazy suggested replacements, but keep other suggestions Useful to enforce time limits on result computationbooleanintDeprecated.rely on the character-basedgetFromPos()instead (deprecated since 3.4)intDeprecated.rely ongetToPos()instead (deprecated since 3.4)intDeprecated.rely ongetToPos()instead (deprecated since 3.4)intPosition of the start of the error (in characters, zero-based, relative to the original input text).intPosition of the start of the error (in characters, zero-based, relative to the original sentence).intgetLine()Deprecated.rely on the character-basedgetFromPos()instead (deprecated since 3.4)A human-readable explanation describing the error.The language that the text might be in if the error limit has been reached.Get the underlined string in the original sentence.intPosition of the start of the pattern (in characters, zero-based, relative to the original input text).intPosition of the end of the mistake pattern (in characters, zero-based, relative to the original input text).getRule()A shorter human-readable explanation describing the error or an empty string if no such explanation is available.Get the specific rule ID from the RuleMatch to replace getRule().getId() in the output.The text fragments which might be an appropriate fix for the problem.intgetToPos()Position of the end of the error (in characters, zero-based, relative to the original input text).intPosition of the end of the error (in characters, zero-based, relative to the original sentence).getType()getUrl()A URL that points to a more detailed error description ornull.inthashCode()booleanvoidsetAutoCorrect(boolean autoCorrect) voidsetColumn(int column) Deprecated.(deprecated since 3.5)voidsetEndColumn(int endColumn) Deprecated.(deprecated since 3.5)voidsetEndLine(int endLine) Set the line number in which the match ends (zero-based).voidsetFeatures(SortedMap<String, Float> features) voidsetLazySuggestedReplacements(Supplier<List<SuggestedReplacement>> replacements) Set a lazy supplier that will compute suggested replacements whengetSuggestedReplacements()orgetSuggestedReplacementObjects()is called.voidsetLine(int fromLine) Set the line number in which the match occurs (zero-based).voidsetMessage(String msg) voidsetNewLanguageMatches(Map<String, Float> newLanguageMatches) Call if the error limit is reached for this sentence.voidsetOffsetPosition(int fromPos, int toPos) voidvoidsetOriginalErrorStr(String originalErrorStr) To store the underlined string in the original sentence.voidsetPatternPosition(int fromPos, int toPos) voidsetSentencePosition(int fromPos, int toPos) voidsetShortMessage(String msg) voidsetSpecificRuleId(String ruleId) Set a new specific rule ID in the RuleMatch to replace getRule().getId() in the output.voidsetSuggestedReplacement(String replacement) voidsetSuggestedReplacementObjects(List<SuggestedReplacement> replacements) voidsetSuggestedReplacements(List<String> replacements) voidsetType(RuleMatch.Type type) voidtoString()
-
Field Details
-
EMPTY_ARRAY
-
SUGGESTION_START_TAG
- See Also:
-
SUGGESTION_END_TAG
- See Also:
-
rule
-
message
-
shortMessage
-
sentence
-
patternPosition
-
offsetPosition
-
sentencePosition
-
linePosition
-
columnPosition
-
suggestedReplacements
-
suggestionsComputed
private boolean suggestionsComputed -
url
-
type
-
features
-
autoCorrect
private boolean autoCorrect -
newLanguageMatches
-
specificRuleId
-
originalErrorStr
-
-
Constructor Details
-
RuleMatch
Deprecated.use a constructor that also takes anAnalyzedSentenceparameter (deprecated since 4.0)Creates a RuleMatch object, taking the rule that triggered this match, position of the match and an explanation message. This message is scanned for <suggestion>...</suggestion> to get suggested fixes for the problem detected by this rule. -
RuleMatch
Creates a RuleMatch object, taking the rule that triggered this match, position of the match and an explanation message. This message is scanned for <suggestion>...</suggestion> to get suggested fixes for the problem detected by this rule.- Since:
- 4.0
-
RuleMatch
public RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, String message, String shortMessage) Creates a RuleMatch object, taking the rule that triggered this match, position of the match and an explanation message. This message is scanned for <suggestion>...</suggestion> to get suggested fixes for the problem detected by this rule.- Parameters:
shortMessage- used for example in OpenOffice/LibreOffice's context menu- Since:
- 4.0
-
RuleMatch
public RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, int patternStartPos, int patternEndPos, String message, String shortMessage) Creates a RuleMatch object, taking the rule that triggered this match, position of the match and an explanation message. This message is scanned for <suggestion>...</suggestion> to get suggested fixes for the problem detected by this rule.- Parameters:
shortMessage- used for example in OpenOffice/LibreOffice's context menu- Since:
- 4.9
-
RuleMatch
public RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, String message, String shortMessage, List<String> suggestions) Create a rule match with any suggestions in the message overridden by the given suggestions- Since:
- 4.7
-
RuleMatch
public RuleMatch(Rule rule, int fromPos, int toPos, String message, String shortMessage, boolean startWithUppercase, String suggestionsOutMsg) Deprecated.use a constructor that also takes anAnalyzedSentenceparameter (deprecated since 4.0) -
RuleMatch
public RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, int patternFromPos, int patternToPos, String message, String shortMessage, boolean startWithUppercase, String suggestionsOutMsg) -
RuleMatch
public RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, int patternFromPos, int patternToPos, String message, String shortMessage, boolean startWithUppercase, boolean isAllUppercase, String suggestionsOutMsg, boolean setOriginalErrorStr) Creates a RuleMatch object, taking the rule that triggered this match, position of the match and an explanation message. This message is scanned for <suggestion>...</suggestion> to get suggested fixes for the problem detected by this rule.- Parameters:
fromPos- error start position in original texttoPos- error end position in original textshortMessage- used for example in OpenOffice/LibreOffice's context menu (may be null)startWithUppercase- whether the original text at the position of the match starts with an uppercase character- Since:
- 4.0
-
RuleMatch
-
RuleMatch
-
RuleMatch
-
-
Method Details
-
getFeatures
-
setFeatures
-
isAutoCorrect
public boolean isAutoCorrect() -
setAutoCorrect
public void setAutoCorrect(boolean autoCorrect) -
getRule
-
getLine
public int getLine()Deprecated.rely on the character-basedgetFromPos()instead (deprecated since 3.4)Get the line number in which the match occurs (zero-based). -
setLine
public void setLine(int fromLine) Set the line number in which the match occurs (zero-based). -
getEndLine
public int getEndLine()Deprecated.rely ongetToPos()instead (deprecated since 3.4)Get the line number in which the match ends (zero-based). -
setEndLine
public void setEndLine(int endLine) Set the line number in which the match ends (zero-based). -
getColumn
public int getColumn()Deprecated.rely on the character-basedgetFromPos()instead (deprecated since 3.4)Get the column number in which the match occurs (zero-based). -
setColumn
public void setColumn(int column) Deprecated.(deprecated since 3.5)Set the column number in which the match occurs (zero-based). -
getEndColumn
public int getEndColumn()Deprecated.rely ongetToPos()instead (deprecated since 3.4)Get the column number in which the match ends (zero-based). -
setEndColumn
public void setEndColumn(int endColumn) Deprecated.(deprecated since 3.5)Set the column number in which the match ends (zero-based). -
getPatternFromPos
public int getPatternFromPos()Position of the start of the pattern (in characters, zero-based, relative to the original input text). -
getPatternToPos
public int getPatternToPos()Position of the end of the mistake pattern (in characters, zero-based, relative to the original input text). -
setPatternPosition
public void setPatternPosition(int fromPos, int toPos) -
getFromPos
public int getFromPos()Position of the start of the error (in characters, zero-based, relative to the original input text). -
getToPos
public int getToPos()Position of the end of the error (in characters, zero-based, relative to the original input text). -
getFromPosSentence
public int getFromPosSentence()Position of the start of the error (in characters, zero-based, relative to the original sentence). This value is used to keep the position in the sentence when the offsetPosition is adjusted to the whole text -
getToPosSentence
public int getToPosSentence()Position of the end of the error (in characters, zero-based, relative to the original sentence). This value is used to keep the position in the sentence when the offsetPosition is adjusted to the whole text -
setOffsetPosition
public void setOffsetPosition(int fromPos, int toPos) -
setSentencePosition
public void setSentencePosition(int fromPos, int toPos) -
getMessage
A human-readable explanation describing the error. This may contain one or more corrections marked up with <suggestion>...</suggestion>.- See Also:
-
setMessage
-
getShortMessage
A shorter human-readable explanation describing the error or an empty string if no such explanation is available.- See Also:
-
setShortMessage
-
setSuggestedReplacement
- See Also:
-
addSuggestedReplacement
-
addSuggestedReplacements
-
getSuggestedReplacements
The text fragments which might be an appropriate fix for the problem. One of these fragments can be used to replace the old text betweengetFromPos()togetToPos().- Returns:
- unmodifiable list of String objects or an empty List
-
setSuggestedReplacements
- See Also:
-
getSuggestedReplacementObjects
-
setSuggestedReplacementObjects
- See Also:
-
setLazySuggestedReplacements
public void setLazySuggestedReplacements(@NotNull Supplier<List<SuggestedReplacement>> replacements) Set a lazy supplier that will compute suggested replacements whengetSuggestedReplacements()orgetSuggestedReplacementObjects()is called. This can be used to speed up sentence analysis in cases when computationally expensive replacements won't necessarily be needed (e.g. for an IDE in the same process). -
computeLazySuggestedReplacements
public void computeLazySuggestedReplacements()Force computing replacements, e.g. for accurate metrics for computation time and to set timeouts for this process Used in server use case (i.e.org.languagetool.server.TextChecker) -
discardLazySuggestedReplacements
public void discardLazySuggestedReplacements()Discard lazy suggested replacements, but keep other suggestions Useful to enforce time limits on result computation -
getUrl
A URL that points to a more detailed error description ornull. Note that theRuleitself might also have an URL, which is usually a less specific one than this. This one will overwrite the rule's URL in the JSON output.- Since:
- 4.0
-
setUrl
- Since:
- 4.0
-
getSentence
- Since:
- 4.0
-
getType
- Since:
- 4.3
-
setType
- Since:
- 4.3
-
toString
-
compareTo
Compare by start position.- Specified by:
compareToin interfaceComparable<RuleMatch>
-
equals
-
hashCode
public int hashCode() -
getNewLanguageMatches
The language that the text might be in if the error limit has been reached.- Since:
- 6.4
-
setNewLanguageMatches
Call if the error limit is reached for this sentence. The caller will then get text ranges for the sentence and can ignore errors there. Note: will not have an effect for text-level rules.- Parameters:
newLanguageMatches- a map of possible languages this could be instead- Since:
- 6.4
-
setSpecificRuleId
Set a new specific rule ID in the RuleMatch to replace getRule().getId() in the output. Used for statistical purposes.- Since:
- 5.6
-
getSpecificRuleId
Get the specific rule ID from the RuleMatch to replace getRule().getId() in the output. Used for statistical purposes.- Since:
- 5.6
-
setOriginalErrorStr
public void setOriginalErrorStr() -
setOriginalErrorStr
To store the underlined string in the original sentence. -
getOriginalErrorStr
Get the underlined string in the original sentence. Only available for sentence-level pattern rules. Returns an empty string if not available. For other rules, use setOriginalErrorStr(String originalErrorStr)- Since:
- 6.3
-
AnalyzedSentenceparameter (deprecated since 4.0)