Class AbstractDateCheckWithSuggestionsFilter

java.lang.Object
org.languagetool.rules.patterns.RuleFilter
org.languagetool.rules.AbstractDateCheckWithSuggestionsFilter
Direct Known Subclasses:
DateCheckFilter, DateCheckFilter, DateCheckFilter, DateCheckFilter, DateCheckFilter, DateCheckFilter, DateCheckFilter

public abstract class AbstractDateCheckWithSuggestionsFilter extends RuleFilter
Accepts rule matches if a date doesn't match the accompanying weekday, e.g. if Monday, 8 November 2003 isn't actually a Monday. Replaces {realDay} with the real day of the date in the rule's message, and {day} with the claimed day from the text (might be useful in case the text uses an abbreviation).
Since:
2.7
  • Field Details

    • DAY_OF_MONTH_PATTERN

      protected static final Pattern DAY_OF_MONTH_PATTERN
  • Constructor Details

    • AbstractDateCheckWithSuggestionsFilter

      public AbstractDateCheckWithSuggestionsFilter()
  • Method Details

    • getDayOfWeek

      protected abstract int getDayOfWeek(String localizedWeekDayString)
      Implement so that Sunday returns 1, Monday 2 etc.
      Parameters:
      localizedWeekDayString - a week day name or abbreviation thereof
    • getDayOfWeek

      protected abstract String getDayOfWeek(Calendar date)
      Get the localized name of the day of week for the given date.
    • getDayOfMonth

      protected int getDayOfMonth(String localizedDayOfMonth)
      Implement so that "first" returns 1, second returns 2 etc.
      Parameters:
      localizedDayOfMonth - name of day of the month or abbreviation thereof
    • getMonth

      protected abstract int getMonth(String localizedMonth)
      Implement so that January returns 1, February 2 etc.
      Parameters:
      localizedMonth - name of a month or abbreviation thereof
    • getCalendar

      protected abstract Calendar getCalendar()
    • getErrorMessageWrongYear

      protected abstract String getErrorMessageWrongYear()
    • acceptRuleMatch

      public RuleMatch acceptRuleMatch(RuleMatch match, Map<String,String> args, int patternTokenPos, AnalyzedTokenReadings[] patternTokens, List<Integer> tokenPositions)
      Description copied from class: RuleFilter
      Returns the original rule match or a modified one, or null if the rule match is filtered out.
      Specified by:
      acceptRuleMatch in class RuleFilter
      Parameters:
      args - a map with values for year, month, day (day of month), weekDay
      patternTokens - those tokens of the text that correspond the matched pattern
      Returns:
      null if this rule match should be removed, or any other RuleMatch (e.g. the one from the arguments) that properly describes the detected error
    • findNewDayOfMonth

      private String findNewDayOfMonth(int day, int month, int year, int dayOfWeekFromString)
    • getDayOfWeekFromDate

      private int getDayOfWeekFromDate(Calendar dateFromDate)
    • getDate

      protected Calendar getDate(int dayOfMonth, int month, int year)
    • getYearFromStr

      private int getYearFromStr(String yearArg)
    • getDayOfMonthFromStr

      private int getDayOfMonthFromStr(String dayOfMonthString)
    • getMonthFromStr

      private int getMonthFromStr(String monthStr)
    • getDayStrLikeOriginal

      protected String getDayStrLikeOriginal(String day, String original)
    • adjustSuggestion

      protected String adjustSuggestion(String sugg)