<!-- QUE TER COMO OBJETIVO cujo objetivo ser -->
<rule id='QUE_TINHA_COMO_OBJETIVO' name="cujo objetivo era">
<!-- Created by Marco A.G.Pinto, Portuguese rule 2021-03-19 (Enhanced) (17-MAR-2021+) -->
<pattern>
<token>que</token>
<and>
<token inflected='yes'>ter</token>
<token postag='VMII3S0|VMIP3S0' postag_regexp='yes'/>
</and>
<token regexp='yes'>como|por</token>
<token>objetivo</token>
</pattern>
<message>Melhore a redação.</message>
<suggestion>cujo objetivo <match no='2' postag="VMII3S0" postag_regexp="no" postag_replace="VMIP3S0">é</match></suggestion>
<suggestion>cujo objetivo <match no='2' postag="VMIP3S0" postag_regexp="no" postag_replace="VMII3S0">era</match></suggestion>
<example correction="cujo objetivo é|cujo objetivo era">Assim surgiu o Estado Islâmico <marker>que tinha como objetivo</marker> criar um califado mundial.</example>
</rule>
It throws errors in TESTRULES PT:
Testing rule 2600…
Skipped 0 rules for variant language to avoid checking rules more than once
2685 rules tested.
Exception in thread “main” org.languagetool.rules.patterns.PatternRuleTest$PatternRuleTestFailure: Test failure for rule QUE_TINHA_COMO_OBJETIVO[1] in file /org/languagetool/rules/pt/grammar.xml: Incorrect suggestions: Expected ‘cujo objetivo é|cujo objetivo era’, got: ‘cujo objetivo (é)|cujo objetivo (era)’ on input: ‘Assim surgiu o Estado Islâmico que tinha como objetivo criar um califado mundial.’
at org.languagetool.rules.patterns.PatternRuleTest.addError(PatternRuleTest.java:313)
at org.languagetool.rules.patterns.PatternRuleTest.assertSuggestions(PatternRuleTest.java:561)
at org.languagetool.rules.patterns.PatternRuleTest.testBadSentences(PatternRuleTest.java:453)
at org.languagetool.rules.patterns.PatternRuleTest.lambda$testGrammarRulesFromXML$1(PatternRuleTest.java:342)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Later, I will replace “objetivo” with “NC.+|AQ0.+”
The main problem here was that the verb “ser” needed to be in the infinitive form in the <match> inside the suggestion. Also, you can simplify the code a little, which makes it less prone to bugs. Especially the <and> isn’t necessary.
This way, it should work fine:
<!-- QUE TER COMO OBJETIVO cujo objetivo ser -->
<rule id='QUE_TINHA_COMO_OBJETIVO' name="cujo objetivo era">
<!-- Created by Marco A.G.Pinto, Portuguese rule 2021-03-19 (Enhanced) (17-MAR-2021+) -->
<pattern>
<token>que</token>
<token postag='VMII3S0|VMIP3S0' postag_regexp='yes' inflected='yes'>ter</token>
<token regexp='yes'>como|por</token>
<token>objetivo</token>
</pattern>
<message>Melhore a redação.</message>
<suggestion>cujo objetivo <match no='2' postag="VMIP3S0">ser</match></suggestion>
<suggestion>cujo objetivo <match no='2' postag="VMII3S0">ser</match></suggestion>
<example correction="cujo objetivo é|cujo objetivo era">Assim surgiu o Estado Islâmico <marker>que tinha como objetivo</marker> criar um califado mundial.</example>
</rule>
P.S.: Could you make the message more helpful? Something along the lines (please correct my formulation, it is probably not native-sounding) of “Com o pronome ‘cujo’, seu texto poderia ficar mais elegante.”
<!-- QUE TER COMO/POR NOME/ADJETIVO cujo(a) Nome/Adjetivo ser -->
<rulegroup id='QUE_TER_COMO_POR_NOME_ADJ' name="cujo(a) Nome/Adjetivo é/era">
<!-- Created by Marco A.G.Pinto, Portuguese rule 2021-03-19 (Enhanced) (17-MAR-2021+) -->
<rule>
<pattern>
<token>que</token>
<token inflected='yes'>ter</token>
<token regexp='yes'>como|por</token>
<token postag='AQ0MS0|NCMS000' postag_regexp='yes'/>
</pattern>
<message>Com o pronome ‘cujo’, o seu texto poderia ficar mais claro e elegante.</message>
<suggestion>cujo \4 <match no='2' postag=".*" postag_regexp="yes">ser</match></suggestion>
<example correction="cujo objetivo era">Assim surgiu o Estado Islâmico <marker>que tinha como objetivo</marker> criar um califado mundial.</example>
</rule>
<rule>
<pattern>
<token>que</token>
<token inflected='yes'>ter</token>
<token regexp='yes'>como|por</token>
<token postag='AQ0FS0|NCFS000' postag_regexp='yes'/>
</pattern>
<message>Com o pronome ‘cuja’, o seu texto poderia ficar mais claro e elegante.</message>
<suggestion>cuja \4 <match no='2' postag=".*" postag_regexp="yes">ser</match></suggestion>
<example correction="cuja meta era">Assim surgiu o Estado Islâmico <marker>que tinha como meta</marker> criar um califado mundial.</example>
</rule>
</rulegroup>
It is a very powerful rule once it is working properly
Oh yeah, that’s right. It will take any postag “tem” can get and transfer it to “ser”. We need to specify the possible postags in the suggestion as well. Here a reviewed version:
<!-- QUE TER COMO OBJETIVO cujo objetivo ser -->
<rule id='QUE_TINHA_COMO_OBJETIVO' name="cujo objetivo era">
<!-- Created by Marco A.G.Pinto, Portuguese rule 2021-03-19 (Enhanced) (17-MAR-2021+) -->
<pattern>
<token>que</token>
<token postag='VM[IS][IPFSCM]3S0' postag_regexp='yes' inflected='yes'>ter</token>
<token regexp='yes'>como|por</token>
<token postag='AQ0MS0|NCMS000' postag_regexp='yes'/>
</pattern>
<message>Com o pronome ‘cujo’, seu texto poderia ficar mais claro e elegante.</message>
<suggestion>cujo objetivo <match no='2' postag="VM[IS][IPFSCM]3S0" postag_regexp="yes">ser</match></suggestion>
<example correction="cujo objetivo era">Assim surgiu o Estado Islâmico <marker>que tinha como objetivo</marker> criar um califado mundial.</example>
<example correction="cujo objetivo é">Precisamos de uma iniciativa <marker>que tem como objetivo</marker> diminuir o número de mortos no trânsito.</example>
</rule>
I would limit it to a defined set of forms of “ter”, so we can avoid the mess with “seja|sê”.