[Solved (with workaround)] Antipattern is not working

No, i took Unify_Adj_NN_gender which is the name of the previous rule - it still works…

Huh, but does it have an antipattern that would apply to this rule?

No. I was just working on this :slight_smile: There is a couple of anitpatterns for whole Unify rulegroup.

It looks like I am a first one who tried adding antipatterns to Russian xml :blush:

I don’t really know how matching works on the website but I vaguely remember it was based on text injection into the xml file. Not even sure if unification is supported in the online interface (it wasn’t some time ago).

Maybe @dnaber could confirm? It seems we might have a rare bug here.

Issued this at GitHub Some weird behavior of ruleEditor · Issue #496 · languagetool-org/languagetool · GitHub

The online editor just takes the XML snippet and surrounds it by this to get a valid XML:

<rules lang="..."> <category id="fakeId" name="fakeCategory"> ...... </category> </rules>

So everything defined outside the snippet like unification rules or entities is missing and won’t work.

So any idea why the name of the rule might influence the execution? It’s definitely not a problem with the session or something like this because when I paste Konstantin’s rule, it still fails…

I couldn’t follow the whole thread, are you sure it’s the name, or could it maybe some non-deterministic behavior?

Maybe it’s something non-deterministic, but that’s the only difference between our rules – and changing the name makes the rule go. And you get fairly deterministic non-matching when you use this name… Really very strange (it works in the JUnit test so this is not a problem with LT core, I guess).

One more problem with ruleEditor Another problem with ruleEditor · Issue #497 · languagetool-org/languagetool · GitHub
Could you please verify that it is present at your browser too (the rule passes testrule.sh check locally).

One more antipattern problem

Rule 3

<rule id="testlj">
	<antipattern>
		<token regexp="yes">смел.*</token>
		<marker>
			<token postag="(NN|NNN):.*:Nom"
			       postag_regexp="yes" />
		</marker>
	</antipattern>
	<pattern>
		<marker>
	 	<token postag="ADJ:.*"	postag_regexp="yes"/>
		<token postag="NN:.*" postag_regexp="yes"/>
		</marker>
		<!-- <or> -->
		<!-- 	<token skip="-1"/> -->
		        <token postag="SENT_END" />
		<!-- </or> -->
	</pattern>
	<message>test:</message>
	<example>Смелого пуля.</example> 
	<example correction=""> <marker>хрестоматийное слово</marker>.</example>
</rule>

This a a correct XML rule, that passes testrule.sh if i add this into russian grammar.xml
Running XML pattern tests... Known languages: [English, English (US), English (GB), English (Australian), English (Canadian), English (New Zealand), English (South African), Persian, French, German, German (Germany), German (Austria), German (Swiss), Simple German, Polish, Catalan, Catalan (Valencian), Italian, Breton, Dutch, Portuguese, Portuguese (Portugal), Portuguese (Brazil), Russian, Asturian, Belarusian, Chinese, Danish, Esperanto, Galician, Greek, Icelandic, Japanese, Khmer, Lithuanian, Malayalam, Romanian, Slovak, Slovenian, Spanish, Swedish, Tamil, Tagalog, Ukrainian, Testlanguage] Running XML validation for ru/ru-RU/grammar.xml... No rule file found at /org/languagetool/rules/ru/ru-RU/grammar.xml in classpath Running pattern rule tests for Russian... 537 rules tested. Tests finished! Running disambiguator rule tests... Running disambiguation tests for Russian... 25 rules tested (48ms) Tests successful. Running XML bitext pattern tests... Running tests for Russian... Tests successful. Validating false-friends.xml... Validation successfully finished.

If I remove the <antipattern> block this will match and here is the error log:

Running pattern rule tests for Russian... Exception in thread "main" java.lang.AssertionError: Russian: Did not expect error in: Смелого пуля. Matching Rule: testlj[3] at org.junit.Assert.fail(Assert.java:88) at org.junit.Assert.assertTrue(Assert.java:41) at org.junit.Assert.assertFalse(Assert.java:64) at org.languagetool.rules.patterns.PatternRuleTest.testCorrectSentences(PatternRuleTest.java:472) at org.languagetool.rules.patterns.PatternRuleTest.testGrammarRulesFromXML(PatternRuleTest.java:272) at org.languagetool.rules.patterns.PatternRuleTest.runTestForLanguage(PatternRuleTest.java:198) at org.languagetool.rules.patterns.PatternRuleTest.runGrammarRulesFromXmlTestIgnoringLanguages(PatternRuleTest.java:149) at org.languagetool.rules.patterns.PatternRuleTest.main(PatternRuleTest.java:558) Running disambiguator rule tests...

So basically <antipatterns> seems to work. However, if I uncomment <or> block in Rule 3 this will still give me an error.
The complete example of
#Rule 4

<rule id="testlj">
	<antipattern>
		<token regexp="yes">смел.*</token>
		<marker>
			<token postag="(NN|NNN):.*:Nom"
			       postag_regexp="yes" />
		</marker>
	</antipattern>
	<pattern>
		<marker>
	 	<token postag="ADJ:.*"	postag_regexp="yes"/>
		<token postag="NN:.*" postag_regexp="yes"/>
		</marker>
		<or>
			<token skip="-1"/>
		        <token postag="SENT_END" />
		</or>
	</pattern>
	<message>test:</message>
	<example>Смелого пуля.</example> 
	<example correction=""> <marker>хрестоматийное слово</marker>.</example>
</rule>

the error log (look identical to the previous one)
Running XML validation for ru/ru-RU/grammar.xml... No rule file found at /org/languagetool/rules/ru/ru-RU/grammar.xml in classpath Running pattern rule tests for Russian... Exception in thread "main" java.lang.AssertionError: Russian: Did not expect error in: Смелого пуля. Matching Rule: testlj[3] at org.junit.Assert.fail(Assert.java:88) at org.junit.Assert.assertTrue(Assert.java:41) at org.junit.Assert.assertFalse(Assert.java:64) at org.languagetool.rules.patterns.PatternRuleTest.testCorrectSentences(PatternRuleTest.java:472) at org.languagetool.rules.patterns.PatternRuleTest.testGrammarRulesFromXML(PatternRuleTest.java:272) at org.languagetool.rules.patterns.PatternRuleTest.runTestForLanguage(PatternRuleTest.java:198) at org.languagetool.rules.patterns.PatternRuleTest.runGrammarRulesFromXmlTestIgnoringLanguages(PatternRuleTest.java:149) at org.languagetool.rules.patterns.PatternRuleTest.main(PatternRuleTest.java:558) Running disambiguator rule tests... Running disambiguation tests for Russian... 25 rules tested (49ms) Tests successful. Running XML bitext pattern tests... Running tests for Russian...

Addition: antipattern works for any token of <or> block of rule 4. This way

		<!-- <or> -->
			<token skip="-1"/>
		<!-- 	<token postag="SENT_END" /> -->
		<!-- </or> -->

works fine too.

A new JLanguageTool object is created for each check, and all of its rules are disabled. If the user specifies an ID that already exists, it will also be disabled I guess.

I have tried existing <rule id="Slovosoch_v_proshlom" name="Опечатка «в прошлом/в пошлом»"> - the rule become working… Probably the problem is only for rule with an antipattern.

Dear all, thank you for your help!
I have managed all needed antipatterns after removing <or> part of the pattern.