Package org.languagetool.rules
Class RuleMatch
- java.lang.Object
-
- org.languagetool.rules.RuleMatch
-
- All Implemented Interfaces:
java.lang.Comparable<RuleMatch>
public class RuleMatch extends java.lang.Object implements java.lang.Comparable<RuleMatch>
Information about an error rule that matches text and the position of the match. SeeContextToolsfor displaying errors in their original text context.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classRuleMatch.ColumnPosition(package private) static classRuleMatch.LinePosition(package private) static classRuleMatch.OffsetPositionstatic classRuleMatch.TypeUnlikeCategory, this is specific to a RuleMatch, not to a rule.
-
Field Summary
Fields Modifier and Type Field Description private booleanautoCorrectprivate RuleMatch.ColumnPositioncolumnPositionprivate java.util.SortedMap<java.lang.String,java.lang.Float>featuresprivate RuleMatch.LinePositionlinePositionprivate java.lang.Stringmessageprivate RuleMatch.OffsetPositionoffsetPositionprivate Ruleruleprivate AnalyzedSentencesentenceprivate java.lang.StringshortMessageprivate java.util.List<SuggestedReplacement>suggestedReplacementsprivate static java.util.regex.PatternSUGGESTION_PATTERNprivate RuleMatch.Typetypeprivate java.net.URLurl
-
Constructor Summary
Constructors Constructor Description RuleMatch(RuleMatch clone)RuleMatch(RuleMatch clone, java.util.List<java.lang.String> replacements)RuleMatch(Rule rule, int fromPos, int toPos, java.lang.String message)Deprecated.use a constructor that also takes anAnalyzedSentenceparameter (deprecated since 4.0)RuleMatch(Rule rule, int fromPos, int toPos, java.lang.String message, java.lang.String shortMessage, boolean startWithUppercase, java.lang.String suggestionsOutMsg)Deprecated.use a constructor that also takes anAnalyzedSentenceparameter (deprecated since 4.0)RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, java.lang.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, java.lang.String message, java.lang.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, java.lang.String message, java.lang.String shortMessage, boolean startWithUppercase, java.lang.String suggestionsOutMsg)Creates a RuleMatch object, taking the rule that triggered this match, position of the match and an explanation message.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddSuggestedReplacement(java.lang.String replacement)voidaddSuggestedReplacements(java.util.List<java.lang.String> replacements)intcompareTo(RuleMatch other)Compare by start position.booleanequals(java.lang.Object o)intgetColumn()Deprecated.rely on the character-basedgetFromPos()instead (deprecated since 3.4)intgetEndColumn()Deprecated.rely ongetToPos()instead (deprecated since 3.4)intgetEndLine()Deprecated.rely ongetToPos()instead (deprecated since 3.4)@NotNull java.util.SortedMap<java.lang.String,java.lang.Float>getFeatures()intgetFromPos()Position of the start of the error (in characters, zero-based, relative to the original input text).intgetLine()Deprecated.rely on the character-basedgetFromPos()instead (deprecated since 3.4)java.lang.StringgetMessage()A human-readable explanation describing the error.RulegetRule()AnalyzedSentencegetSentence()java.lang.StringgetShortMessage()A shorter human-readable explanation describing the error or an empty string if no such explanation is available.java.util.List<SuggestedReplacement>getSuggestedReplacementObjects()java.util.List<java.lang.String>getSuggestedReplacements()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).RuleMatch.TypegetType()@Nullable java.net.URLgetUrl()A URL that points to a more detailed error description ornull.inthashCode()booleanisAutoCorrect()voidsetAutoCorrect(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(@NotNull java.util.SortedMap<java.lang.String,java.lang.Float> features)voidsetLine(int fromLine)Set the line number in which the match occurs (zero-based).voidsetOffsetPosition(int fromPos, int toPos, RuleMatch ruleMatch)voidsetSuggestedReplacement(java.lang.String replacement)voidsetSuggestedReplacementObjects(java.util.List<SuggestedReplacement> replacements)voidsetSuggestedReplacements(java.util.List<java.lang.String> replacements)voidsetType(RuleMatch.Type type)voidsetUrl(java.net.URL url)java.lang.StringtoString()
-
-
-
Field Detail
-
SUGGESTION_PATTERN
private static final java.util.regex.Pattern SUGGESTION_PATTERN
-
rule
private final Rule rule
-
message
private final java.lang.String message
-
shortMessage
private final java.lang.String shortMessage
-
sentence
private final AnalyzedSentence sentence
-
offsetPosition
private RuleMatch.OffsetPosition offsetPosition
-
linePosition
private RuleMatch.LinePosition linePosition
-
columnPosition
private RuleMatch.ColumnPosition columnPosition
-
suggestedReplacements
private java.util.List<SuggestedReplacement> suggestedReplacements
-
url
private java.net.URL url
-
type
private RuleMatch.Type type
-
features
private java.util.SortedMap<java.lang.String,java.lang.Float> features
-
autoCorrect
private boolean autoCorrect
-
-
Constructor Detail
-
RuleMatch
public RuleMatch(Rule rule, int fromPos, int toPos, java.lang.String message)
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
public RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, java.lang.String message)
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, java.lang.String message, java.lang.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, int fromPos, int toPos, java.lang.String message, java.lang.String shortMessage, boolean startWithUppercase, java.lang.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, java.lang.String message, java.lang.String shortMessage, boolean startWithUppercase, java.lang.String suggestionsOutMsg)
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
public RuleMatch(RuleMatch clone)
-
RuleMatch
public RuleMatch(RuleMatch clone, java.util.List<java.lang.String> replacements)
-
-
Method Detail
-
getFeatures
@NotNull public @NotNull java.util.SortedMap<java.lang.String,java.lang.Float> getFeatures()
-
setFeatures
public void setFeatures(@NotNull @NotNull java.util.SortedMap<java.lang.String,java.lang.Float> features)
-
isAutoCorrect
public boolean isAutoCorrect()
-
setAutoCorrect
public void setAutoCorrect(boolean autoCorrect)
-
getRule
public Rule 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).
-
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).
-
setOffsetPosition
public void setOffsetPosition(int fromPos, int toPos, RuleMatch ruleMatch)
-
getMessage
public java.lang.String getMessage()
A human-readable explanation describing the error. This may contain one or more corrections marked up with <suggestion>...</suggestion>.- See Also:
getSuggestedReplacements(),getShortMessage()
-
getShortMessage
public java.lang.String getShortMessage()
A shorter human-readable explanation describing the error or an empty string if no such explanation is available.- See Also:
getMessage()
-
setSuggestedReplacement
public void setSuggestedReplacement(java.lang.String replacement)
- See Also:
getSuggestedReplacements()
-
addSuggestedReplacement
public void addSuggestedReplacement(java.lang.String replacement)
-
addSuggestedReplacements
public void addSuggestedReplacements(java.util.List<java.lang.String> replacements)
-
getSuggestedReplacements
public java.util.List<java.lang.String> 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
public void setSuggestedReplacements(java.util.List<java.lang.String> replacements)
- See Also:
getSuggestedReplacements()
-
getSuggestedReplacementObjects
public java.util.List<SuggestedReplacement> getSuggestedReplacementObjects()
-
setSuggestedReplacementObjects
public void setSuggestedReplacementObjects(java.util.List<SuggestedReplacement> replacements)
- See Also:
getSuggestedReplacements()
-
getUrl
@Nullable public @Nullable java.net.URL 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
public void setUrl(java.net.URL url)
- Since:
- 4.0
-
getSentence
public AnalyzedSentence getSentence()
- Since:
- 4.0
-
getType
@Experimental public RuleMatch.Type getType()
- Since:
- 4.3
-
setType
@Experimental public void setType(RuleMatch.Type type)
- Since:
- 4.3
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
compareTo
public int compareTo(RuleMatch other)
Compare by start position.- Specified by:
compareToin interfacejava.lang.Comparable<RuleMatch>
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-