I've found a bug in the matcher postag replacement: if I have 2 out
match suggestions and first one uses postag_replace in match element,
but second one just uses simple match no=N/ the matcher in the
second suggestion also gets first postag replacement applied.
If I put the suggestion with non-replacing matcher first everything is good.
Here's the test that shows the problem, first test passes: it
generates 1 simple match for v1 text and 3 (via postag replacment) for
v2. The only difference in the second test is the order of the
matchers - replacing ones go first and now we get 3 versions of v1 and
3 versions of v2 which is wrong (as v1 should have stayed with 1
version).
Note: I could not easily reproduce it in the core module test as I
needed a postag_replace and Demo language does not have tags so this
test uses Ukrainian but to create PatternRuleMatcher I had to put it
in org.languagetool.rules.patterns
Regards,
Andriy
package org.languagetool.rules.patterns;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import org.junit.BeforeClass;
import org.junit.Test;
import org.languagetool.JLanguageTool;
import org.languagetool.language.Ukrainian;
import org.languagetool.rules.RuleMatch;
import org.languagetool.rules.patterns.Match.CaseConversion;
import org.languagetool.rules.patterns.Match.IncludeRange;
public class SpecialMatcherTest {
private static JLanguageTool langTool;
@BeforeClass
public static void setup() {
langTool = new JLanguageTool(new Ukrainian());
}
@Test
public void testSuggestionWithPostagReplace1() throws Exception {
ListPatternToken patternTokens = Arrays.asList(makeElement(тактичний), makeElement(узгодження));
String suggestionsOutMsg = suggestionv1: \\1 \\2/suggestionsuggestionv2: \\1 \\2/suggestion;
PatternRule rule = new PatternRule(, langTool.getLanguage(), patternTokens, my description, my message, short message, suggestionsOutMsg);
PatternRuleMatcher matcher = new PatternRuleMatcher(rule, false);
rule.addSuggestionMatchOutMsg(new Match(null, null, false, null, null, CaseConversion.NONE, false, false, IncludeRange.NONE));
rule.addSuggestionMatchOutMsg(new Match(null, null, false, null, null, CaseConversion.NONE, false, false, IncludeRange.NONE));
rule.addSuggestionMatchOutMsg(new Match((adj.*)v_rod(.*), $1v_zna$2, true, null, null, CaseConversion.NONE, false, false, IncludeRange.NONE));
rule.addSuggestionMatchOutMsg(new Match((noun.*)v_rod(.*), $1v_zna$2, true, null, null, CaseConversion.NONE, false, false, IncludeRange.NONE));
RuleMatch[] matches = getMatches(тактичного узгодження, matcher);
System.out.println(matches[0].getSuggestedReplacements());
assertEquals(Arrays.asList(v1: тактичного узгодження, v2: тактичне узгодження, v2: тактичний узгодження, v2: тактичного узгодження), matches[0].getSuggestedReplacements());
}
@Test
public void testSuggestionWithPostagReplace2() throws Exception {
ListPatternToken patternTokens = Arrays.asList(makeElement(тактичний), makeElement(узгодження));
String suggestionsOutMsg = suggestionv1: \\1 \\2/suggestionsuggestionv2: \\1 \\2/suggestion;
PatternRule rule = new PatternRule(, langTool.getLanguage(), patternTokens, my description, my message, short message, suggestionsOutMsg);
PatternRuleMatcher matcher = new PatternRuleMatcher(rule, false);
rule.addSuggestionMatchOutMsg(new Match((adj.*)v_rod(.*), $1v_zna$2, true, null, null, CaseConversion.NONE, false, false, IncludeRange.NONE));
rule.addSuggestionMatchOutMsg(new Match((noun.*)v_rod(.*), $1v_zna$2, true, null, null, CaseConversion.NONE, false, false, IncludeRange.NONE));
rule.addSuggestionMatchOutMsg(new Match(null, null, false, null, null, CaseConversion.NONE, false, false, IncludeRange.NONE));
rule.addSuggestionMatchOutMsg(new Match(null, null, false, null, null, CaseConversion.NONE, false, false, IncludeRange.NONE));
RuleMatch[] matches = getMatches(тактичного узгодження, matcher);
System.out.println(matches[0].getSuggestedReplacements());
assertEquals(Arrays.asList(v2: тактичне узгодження, v2: тактичний узгодження, v2: тактичного узгодження, v1: тактичного узгодження), matches[0].getSuggestedReplacements());
}
private PatternToken makeElement(String token) {
return new PatternToken(token, false, false, true);
}
private RuleMatch[] getMatches(String input, PatternRuleMatcher matcher) throws IOException {
return matcher.match(langTool.getAnalyzedSentence(input));
}
}
--
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.