public class RuleMatch extends Object implements Comparable<RuleMatch>
ContextTools
for displaying errors in their original text context.Modifier and Type | Class and Description |
---|---|
static class |
RuleMatch.Type
Unlike
Category , this is specific to a RuleMatch, not to a rule. |
Modifier and Type | Field and Description |
---|---|
static RuleMatch[] |
EMPTY_ARRAY |
static String |
SUGGESTION_END_TAG |
static String |
SUGGESTION_START_TAG |
Constructor and Description |
---|
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
|
RuleMatch(Rule rule,
int fromPos,
int toPos,
String message)
Deprecated.
use a constructor that also takes an
AnalyzedSentence parameter (deprecated since 4.0) |
RuleMatch(Rule rule,
int fromPos,
int toPos,
String message,
String shortMessage,
boolean startWithUppercase,
String suggestionsOutMsg)
Deprecated.
use a constructor that also takes an
AnalyzedSentence parameter (deprecated since 4.0) |
RuleMatch(RuleMatch clone) |
RuleMatch(RuleMatch clone,
List<SuggestedReplacement> replacements) |
RuleMatch(RuleMatch clone,
List<SuggestedReplacement> replacements,
boolean ignored) |
Modifier and Type | Method and Description |
---|---|
void |
addSuggestedReplacement(String replacement) |
void |
addSuggestedReplacements(List<String> replacements) |
int |
compareTo(RuleMatch other)
Compare by start position.
|
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.
|
void |
discardLazySuggestedReplacements()
Discard lazy suggested replacements, but keep other suggestions
Useful to enforce time limits on result computation
|
boolean |
equals(Object o) |
int |
getColumn()
Deprecated.
rely on the character-based
getFromPos() instead (deprecated since 3.4) |
int |
getEndColumn()
Deprecated.
rely on
getToPos() instead (deprecated since 3.4) |
int |
getEndLine()
Deprecated.
rely on
getToPos() instead (deprecated since 3.4) |
String |
getErrorLimitLang()
The language that the text might be in if the error limit has been reached.
|
SortedMap<String,Float> |
getFeatures() |
int |
getFromPos()
Position of the start of the error (in characters, zero-based, relative to the original input text).
|
int |
getFromPosSentence()
Position of the start of the error (in characters, zero-based, relative to the original sentence).
|
int |
getLine()
Deprecated.
rely on the character-based
getFromPos() instead (deprecated since 3.4) |
String |
getMessage()
A human-readable explanation describing the error.
|
String |
getOriginalErrorStr()
Get the underlined string in the original sentence.
|
int |
getPatternFromPos()
Position of the start of the pattern (in characters, zero-based, relative to the original input text).
|
int |
getPatternToPos()
Position of the end of the mistake pattern (in characters, zero-based, relative to the original input text).
|
Rule |
getRule() |
AnalyzedSentence |
getSentence() |
String |
getShortMessage()
A shorter human-readable explanation describing the error or an empty string
if no such explanation is available.
|
String |
getSpecificRuleId()
Get the specific rule ID from the RuleMatch to replace getRule().getId() in
the output.
|
List<SuggestedReplacement> |
getSuggestedReplacementObjects() |
List<String> |
getSuggestedReplacements()
The text fragments which might be an appropriate fix for the problem.
|
int |
getToPos()
Position of the end of the error (in characters, zero-based, relative to the original input text).
|
int |
getToPosSentence()
Position of the end of the error (in characters, zero-based, relative to the original sentence).
|
RuleMatch.Type |
getType() |
URL |
getUrl()
A URL that points to a more detailed error description or
null . |
int |
hashCode() |
boolean |
isAutoCorrect() |
void |
setAutoCorrect(boolean autoCorrect) |
void |
setColumn(int column)
Deprecated.
(deprecated since 3.5)
|
void |
setEndColumn(int endColumn)
Deprecated.
(deprecated since 3.5)
|
void |
setEndLine(int endLine)
Set the line number in which the match ends (zero-based).
|
void |
setErrorLimitLang(String langCode)
Call if the error limit is reached for this sentence.
|
void |
setFeatures(SortedMap<String,Float> features) |
void |
setLazySuggestedReplacements(Supplier<List<SuggestedReplacement>> replacements)
Set a lazy supplier that will compute suggested replacements
when
getSuggestedReplacements() or getSuggestedReplacementObjects() is called. |
void |
setLine(int fromLine)
Set the line number in which the match occurs (zero-based).
|
void |
setMessage(String msg) |
void |
setOffsetPosition(int fromPos,
int toPos) |
void |
setOriginalErrorStr(String originalErrorStr)
To store the underlined string in the original sentence.
|
void |
setPatternPosition(int fromPos,
int toPos) |
void |
setSentencePosition(int fromPos,
int toPos) |
void |
setShortMessage(String msg) |
void |
setSpecificRuleId(String ruleId)
Set a new specific rule ID in the RuleMatch to replace getRule().getId() in
the output.
|
void |
setSuggestedReplacement(String replacement) |
void |
setSuggestedReplacementObjects(List<SuggestedReplacement> replacements) |
void |
setSuggestedReplacements(List<String> replacements) |
void |
setType(RuleMatch.Type type) |
void |
setUrl(URL url) |
String |
toString() |
public static final RuleMatch[] EMPTY_ARRAY
public static final String SUGGESTION_START_TAG
public static final String SUGGESTION_END_TAG
public RuleMatch(Rule rule, int fromPos, int toPos, String message)
AnalyzedSentence
parameter (deprecated since 4.0)public RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, String message)
public RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, String message, String shortMessage)
shortMessage
- used for example in OpenOffice/LibreOffice's context menupublic RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, int patternStartPos, int patternEndPos, String message, String shortMessage)
shortMessage
- used for example in OpenOffice/LibreOffice's context menupublic RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, String message, String shortMessage, List<String> suggestions)
public RuleMatch(Rule rule, int fromPos, int toPos, String message, String shortMessage, boolean startWithUppercase, String suggestionsOutMsg)
AnalyzedSentence
parameter (deprecated since 4.0)public RuleMatch(Rule rule, AnalyzedSentence sentence, int fromPos, int toPos, int patternFromPos, int patternToPos, String message, String shortMessage, boolean startWithUppercase, String suggestionsOutMsg)
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)
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 characterpublic RuleMatch(RuleMatch clone)
public RuleMatch(RuleMatch clone, List<SuggestedReplacement> replacements, boolean ignored)
public RuleMatch(RuleMatch clone, List<SuggestedReplacement> replacements)
public boolean isAutoCorrect()
public void setAutoCorrect(boolean autoCorrect)
public Rule getRule()
public int getLine()
getFromPos()
instead (deprecated since 3.4)public void setLine(int fromLine)
public int getEndLine()
getToPos()
instead (deprecated since 3.4)public void setEndLine(int endLine)
public int getColumn()
getFromPos()
instead (deprecated since 3.4)public void setColumn(int column)
public int getEndColumn()
getToPos()
instead (deprecated since 3.4)public void setEndColumn(int endColumn)
public int getPatternFromPos()
public int getPatternToPos()
public void setPatternPosition(int fromPos, int toPos)
public int getFromPos()
public int getToPos()
public int getFromPosSentence()
public int getToPosSentence()
public void setOffsetPosition(int fromPos, int toPos)
public void setSentencePosition(int fromPos, int toPos)
public String getMessage()
getSuggestedReplacements()
,
getShortMessage()
public void setMessage(String msg)
public String getShortMessage()
getMessage()
public void setShortMessage(String msg)
public void setSuggestedReplacement(String replacement)
getSuggestedReplacements()
public void addSuggestedReplacement(String replacement)
public List<String> getSuggestedReplacements()
getFromPos()
to getToPos()
.public void setSuggestedReplacements(List<String> replacements)
getSuggestedReplacements()
public List<SuggestedReplacement> getSuggestedReplacementObjects()
public void setSuggestedReplacementObjects(List<SuggestedReplacement> replacements)
getSuggestedReplacements()
public void setLazySuggestedReplacements(@NotNull Supplier<List<SuggestedReplacement>> replacements)
getSuggestedReplacements()
or getSuggestedReplacementObjects()
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).public void computeLazySuggestedReplacements()
org.languagetool.server.TextChecker
)public void discardLazySuggestedReplacements()
@Nullable public URL getUrl()
null
.
Note that the Rule
itself 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.public void setUrl(URL url)
public AnalyzedSentence getSentence()
public RuleMatch.Type getType()
public void setType(RuleMatch.Type type)
public int compareTo(RuleMatch other)
compareTo
in interface Comparable<RuleMatch>
@Nullable public String getErrorLimitLang()
public void setErrorLimitLang(String langCode)
langCode
- the language this could be insteadpublic void setSpecificRuleId(String ruleId)
public String getSpecificRuleId()
public void setOriginalErrorStr(String originalErrorStr)
public String getOriginalErrorStr()