public abstract class AbstractUnitConversionRule extends Rule
Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractUnitConversionRule.Message |
Modifier and Type | Field and Description |
---|---|
protected List<Pattern> |
convertedPatterns |
protected static javax.measure.Unit<javax.measure.quantity.Temperature> |
FAHRENHEIT |
protected static javax.measure.Unit<javax.measure.quantity.Length> |
FEET |
protected static javax.measure.Unit<javax.measure.quantity.Volume> |
IMP_FL_OUNCE |
protected static javax.measure.Unit<javax.measure.quantity.Volume> |
IMP_GALLON |
protected static javax.measure.Unit<javax.measure.quantity.Volume> |
IMP_PINT |
protected static javax.measure.Unit<javax.measure.quantity.Volume> |
IMP_QUART |
protected static javax.measure.Unit<javax.measure.quantity.Length> |
INCH |
protected List<javax.measure.Unit> |
metricUnits |
protected static javax.measure.Unit<javax.measure.quantity.Length> |
MILE |
protected static String |
NUMBER_REGEX |
protected static String |
NUMBER_REGEX_WITH_BOUNDARY |
protected Pattern |
numberRangePart |
protected static javax.measure.Unit<javax.measure.quantity.Mass> |
OUNCE |
protected static javax.measure.Unit<javax.measure.quantity.Mass> |
POUND |
protected Map<Pattern,Map.Entry<javax.measure.Unit,Function<MatchResult,Double>>> |
specialPatterns |
protected Map<Pattern,javax.measure.Unit> |
unitPatterns |
protected Map<javax.measure.Unit,List<String>> |
unitSymbols |
protected static javax.measure.Unit<javax.measure.quantity.Volume> |
US_CUP |
protected static javax.measure.Unit<javax.measure.quantity.Volume> |
US_FL_OUNCE |
protected static javax.measure.Unit<javax.measure.quantity.Volume> |
US_GALLON |
protected static javax.measure.Unit<javax.measure.quantity.Volume> |
US_PINT |
protected static javax.measure.Unit<javax.measure.quantity.Volume> |
US_QUART |
protected static javax.measure.Unit<javax.measure.quantity.Length> |
YARD |
Modifier | Constructor and Description |
---|---|
protected |
AbstractUnitConversionRule(ResourceBundle messages) |
Modifier and Type | Method and Description |
---|---|
protected void |
addUnit(String pattern,
javax.measure.Unit base,
String symbol,
double factor,
boolean metric)
Associate a notation with a given unit.
|
protected boolean |
detectNumberRange(AnalyzedSentence sentence,
Matcher matcher) |
protected List<String> |
formatMeasurement(double value,
javax.measure.Unit unit) |
protected String |
formatRounded(String s)
Override in subclasses.
|
protected String |
getMessage(AbstractUnitConversionRule.Message message)
Override in subclasses
|
protected List<Map.Entry<javax.measure.Unit,Double>> |
getMetricEquivalent(double value,
javax.measure.Unit unit) |
protected NumberFormat |
getNumberFormat()
Override in subclasses
|
protected String |
getShortMessage(AbstractUnitConversionRule.Message message)
Override in subclasses
|
protected String |
getSuggestion(String original,
String converted)
Format suggestion.
|
RuleMatch[] |
match(AnalyzedSentence sentence)
Check whether the given sentence matches this error rule, i.e. whether it
contains the error detected by this rule.
|
addExamplePair, addTags, addToneTags, cacheAntiPatterns, estimateContextForSureMatch, getAntiPatterns, getCategory, getConfigureText, getCorrectExamples, getDefaultValue, getDescription, getDistanceTokens, getErrorTriggeringExamples, getFullId, getId, getIncorrectExamples, getLocQualityIssueType, getMaxConfigurableValue, getMinConfigurableValue, getMinPrevMatches, getSentenceWithImmunization, getSourceFile, getSubId, getTags, getToneTags, getUrl, hasConfigurableValue, hasTag, hasToneTag, isDefaultOff, isDefaultTempOff, isDictionaryBasedSpellingRule, isGoalSpecific, isOfficeDefaultOff, isOfficeDefaultOn, isPremium, 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 javax.measure.Unit<javax.measure.quantity.Mass> POUND
protected static final javax.measure.Unit<javax.measure.quantity.Mass> OUNCE
protected static final javax.measure.Unit<javax.measure.quantity.Length> FEET
protected static final javax.measure.Unit<javax.measure.quantity.Length> YARD
protected static final javax.measure.Unit<javax.measure.quantity.Length> INCH
protected static final javax.measure.Unit<javax.measure.quantity.Length> MILE
protected static final javax.measure.Unit<javax.measure.quantity.Volume> US_QUART
protected static final javax.measure.Unit<javax.measure.quantity.Volume> US_GALLON
protected static final javax.measure.Unit<javax.measure.quantity.Volume> US_PINT
protected static final javax.measure.Unit<javax.measure.quantity.Volume> US_CUP
protected static final javax.measure.Unit<javax.measure.quantity.Volume> US_FL_OUNCE
protected static final javax.measure.Unit<javax.measure.quantity.Volume> IMP_PINT
protected static final javax.measure.Unit<javax.measure.quantity.Volume> IMP_QUART
protected static final javax.measure.Unit<javax.measure.quantity.Volume> IMP_GALLON
protected static final javax.measure.Unit<javax.measure.quantity.Volume> IMP_FL_OUNCE
protected static final javax.measure.Unit<javax.measure.quantity.Temperature> FAHRENHEIT
protected static final String NUMBER_REGEX
protected static final String NUMBER_REGEX_WITH_BOUNDARY
protected final Pattern numberRangePart
protected Map<Pattern,Map.Entry<javax.measure.Unit,Function<MatchResult,Double>>> specialPatterns
protected final List<javax.measure.Unit> metricUnits
protected AbstractUnitConversionRule(ResourceBundle messages)
protected NumberFormat getNumberFormat()
protected String getMessage(AbstractUnitConversionRule.Message message)
protected String getShortMessage(AbstractUnitConversionRule.Message message)
protected String getSuggestion(String original, String converted)
original
- matched in the textconverted
- computed by this ruleprotected String formatRounded(String s)
protected void addUnit(String pattern, javax.measure.Unit base, String symbol, double factor, boolean metric)
pattern
- Regex for recognizing the unit. Word boundaries and numbers are added to this pattern by addUnit itself.base
- Unit to associate with the patternsymbol
- Suffix used for suggestion.factor
- Convenience parameter for prefixes for metric units, unit is multiplied with this. Defaults to 1 if not used.metric
- Register this notation for suggestion.@Nullable protected List<Map.Entry<javax.measure.Unit,Double>> getMetricEquivalent(double value, @NotNull javax.measure.Unit unit)
value
- number to convertunit
- unit used in text@Nullable protected List<String> formatMeasurement(double value, @NotNull javax.measure.Unit unit)
protected boolean detectNumberRange(AnalyzedSentence sentence, Matcher matcher)
public RuleMatch[] match(AnalyzedSentence sentence) throws IOException
Rule
match
in class Rule
sentence
- a pre-analyzed sentenceRuleMatch
objectsIOException