Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new filter to merge suggestions before CleanOverlappingFilter rem… #9188

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,7 @@ private List<RuleMatch> filterMatches(AnnotatedText annotatedText, RuleSet rules

ruleMatches = new SameRuleGroupFilter().filter(ruleMatches);
// no sorting: SameRuleGroupFilter sorts rule matches already
ruleMatches = new LanguageDependentMergeSuggestionFilter(language, rules).filter(ruleMatches, annotatedText);
if (cleanOverlappingMatches) {
ruleMatches = new CleanOverlappingFilter(language, userConfig.getHidePremiumMatches()).filter(ruleMatches);
}
Expand Down
13 changes: 13 additions & 0 deletions languagetool-core/src/main/java/org/languagetool/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.languagetool.language.Contributor;
import org.languagetool.languagemodel.LanguageModel;
import org.languagetool.languagemodel.LuceneLanguageModel;
import org.languagetool.markup.AnnotatedText;
import org.languagetool.rules.*;
import org.languagetool.rules.patterns.AbstractPatternRule;
import org.languagetool.rules.patterns.PatternRuleLoader;
Expand Down Expand Up @@ -941,4 +942,16 @@ public String getConsistencyRulePrefix() {
public RuleMatch adjustMatch(RuleMatch rm, List<String> features) {
return rm;
}

/**
* This function is called by JLanguageTool before CleanOverlappingFilter removes overlapping ruleMatches
*
* @param ruleMatches
* @param text
* @param enabledRules
* @return filtered ruleMatches
*/
public List<RuleMatch> mergeSuggestions(List<RuleMatch> ruleMatches, AnnotatedText text, Set<String> enabledRules) {
return ruleMatches;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* LanguageTool, a natural language style checker
* Copyright (c) 2023. Stefan Viol (https://stevio.de)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
* USA
*/

package org.languagetool.rules;

import org.languagetool.Language;
import org.languagetool.markup.AnnotatedText;
import org.languagetool.rules.patterns.RuleSet;

import java.util.List;
import java.util.Set;

public class LanguageDependentMergeSuggestionFilter implements RuleMatchFilter {

private final Language language;
private final Set<String> enabledRules;
public LanguageDependentMergeSuggestionFilter(Language language, RuleSet rules) {
this.language = language;
this.enabledRules = rules.allRuleIds();
}

@Override
public List<RuleMatch> filter(List<RuleMatch> ruleMatches, AnnotatedText text) {
return language.mergeSuggestions(ruleMatches, text, enabledRules);
}
}