class UpperCaseNgramRule extends Rule {

  private static final int THRESHOLD = 50;
  private static final Set<String> relevantWords = new HashSet<>(Arrays.asList(
    "tage", "tagen",
    "Tage", "Tagen"
  ));

  private final LanguageModel lm;

  public UpperCaseNgramRule(ResourceBundle messages, LanguageModel lm, Language lang) {
    super(messages);
    /*
    TODO: potential extension - too many false alarms for now...
    String path = "/de/ambiguous_case.txt";
    List<String> lines = JLanguageTool.getDataBroker().getFromResourceDirAsLines(path);
    for (String line : lines) {
      if (line.isEmpty() || line.startsWith("#")) {
        continue;
      }
      if (startsWithLowercase(line)) {
        throw new RuntimeException("Only entries with uppercase first chars expected in " + path + ": " + line);
      }
      relevantWords.add(line);
      relevantWords.add(lowercaseFirstChar(line));
    }*/
    super.setCategory(Categories.CASING.getCategory(messages));
    this.lm = Objects.requireNonNull(lm);
    setDefaultTempOff();  // TODO
    setLocQualityIssueType(ITSIssueType.Misspelling);
    addExamplePair(Example.wrong("Die Suche endete nach 15 <marker>tagen</marker>."),
                   Example.fixed("Die Suche endete nach 15 <marker>Tagen</marker>."));
  }

  @Override
  public final String getId() {
    return "DE_UPPER_CASE_NGRAM";
  }

  @Override
  public String getDescription() {
    return "Prüft Wörter, ob sie fälschlich groß- oder fälschlich kleingeschrieben sind";
  }

  @Override
  public RuleMatch[] match(AnalyzedSentence sentence) {<FILL_FUNCTION_BODY>}

}

    List<RuleMatch> matches = new ArrayList<>();
    AnalyzedTokenReadings[] tokens = getSentenceWithImmunization(sentence).getTokensWithoutWhitespace();
    for (int i = 1; i < tokens.length; i++) {
      AnalyzedTokenReadings token = tokens[i];
      String tokenStr = token.getToken();
      if (i + 1 < tokens.length && relevantWords.contains(tokenStr) && !isAllUppercase(tokenStr)) {
        String ucToken = uppercaseFirstChar(tokenStr);
        String lcToken = lowercaseFirstChar(tokenStr);
        List<String> ucList = Arrays.asList(tokens[i - 1].getToken(), ucToken, tokens[i + 1].getToken());
        List<String> lcList = Arrays.asList(tokens[i - 1].getToken(), lcToken, tokens[i + 1].getToken());
        Probability ucProb = lm.getPseudoProbability(ucList);
        Probability lcProb = lm.getPseudoProbability(lcList);
        if (startsWithUppercase(tokenStr)) {
          double ratio = lcProb.getProb() / ucProb.getProb();
          if (ratio > THRESHOLD) {
            String msg = "Meinten Sie das Verb '" + lcToken + "'? Nur Nomen und Eigennamen werden großgeschrieben.";
            RuleMatch match = new RuleMatch(this, sentence, token.getStartPos(), token.getEndPos(), msg);
            match.setSuggestedReplacement(lcToken);
            matches.add(match);
          }
        } else {
          double ratio = ucProb.getProb() / lcProb.getProb();
          if (ratio > THRESHOLD) {
            String msg = "Meinten Sie das Nomen '" + ucToken + "'? Nomen und Eigennamen werden großgeschrieben.";
            RuleMatch match = new RuleMatch(this, sentence, token.getStartPos(), token.getEndPos(), msg);
            match.setSuggestedReplacement(ucToken);
            matches.add(match);
          }
        }
      }
    }
    return toRuleMatchArray(matches);
  
<methods>public void <init>() ,public void <init>(java.util.ResourceBundle) ,public void addTags(List<java.lang.String>) ,public void addToneTags(List<java.lang.String>) ,public int estimateContextForSureMatch() ,public List<org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule> getAntiPatterns() ,public org.languagetool.rules.Category getCategory() ,public java.lang.String getConfigureText() ,public final List<org.languagetool.rules.CorrectExample> getCorrectExamples() ,public int getDefaultValue() ,public abstract java.lang.String getDescription() ,public int getDistanceTokens() ,public final List<org.languagetool.rules.ErrorTriggeringExample> getErrorTriggeringExamples() ,public java.lang.String getFullId() ,public abstract java.lang.String getId() ,public final List<org.languagetool.rules.IncorrectExample> getIncorrectExamples() ,public org.languagetool.rules.ITSIssueType getLocQualityIssueType() ,public int getMaxConfigurableValue() ,public int getMinConfigurableValue() ,public int getMinPrevMatches() ,public int getPriority() ,public java.lang.String getSourceFile() ,public java.lang.String getSubId() ,public List<org.languagetool.Tag> getTags() ,public List<org.languagetool.ToneTag> getToneTags() ,public java.net.URL getUrl() ,public boolean hasConfigurableValue() ,public boolean hasTag(org.languagetool.Tag) ,public boolean hasToneTag(org.languagetool.ToneTag) ,public final boolean isDefaultOff() ,public final boolean isDefaultTempOff() ,public boolean isDictionaryBasedSpellingRule() ,public boolean isGoalSpecific() ,public final boolean isOfficeDefaultOff() ,public final boolean isOfficeDefaultOn() ,public boolean isPremium() ,public abstract org.languagetool.rules.RuleMatch[] match(org.languagetool.AnalyzedSentence) throws java.io.IOException,public final void setCategory(org.languagetool.rules.Category) ,public final void setCorrectExamples(List<org.languagetool.rules.CorrectExample>) ,public final void setDefaultOff() ,public final void setDefaultOn() ,public final void setDefaultTempOff() ,public void setDistanceTokens(int) ,public final void setErrorTriggeringExamples(List<org.languagetool.rules.ErrorTriggeringExample>) ,public void setGoalSpecific(boolean) ,public final void setIncorrectExamples(List<org.languagetool.rules.IncorrectExample>) ,public void setLocQualityIssueType(org.languagetool.rules.ITSIssueType) ,public void setMinPrevMatches(int) ,public final void setOfficeDefaultOff() ,public final void setOfficeDefaultOn() ,public void setPremium(boolean) ,public void setPriority(int) ,public void setTags(List<org.languagetool.Tag>) ,public void setToneTags(List<org.languagetool.ToneTag>) ,public void setUrl(java.net.URL) ,public boolean supportsLanguage(org.languagetool.Language) ,public boolean useInOffice() <variables>private static final org.languagetool.rules.Category MISC,private org.languagetool.rules.Category category,private List<org.languagetool.rules.CorrectExample> correctExamples,private boolean defaultOff,private boolean defaultTempOff,private int distanceTokens,private List<org.languagetool.rules.ErrorTriggeringExample> errorTriggeringExamples,private List<org.languagetool.rules.IncorrectExample> incorrectExamples,private boolean isGoalSpecific,private boolean isPremium,private org.languagetool.rules.ITSIssueType locQualityIssueType,protected final non-sealed java.util.ResourceBundle messages,private int minPrevMatches,private boolean officeDefaultOff,private boolean officeDefaultOn,private int priority,private List<org.languagetool.Tag> tags,private List<org.languagetool.ToneTag> toneTags,private java.net.URL url