[pt] Help creating rule - 2021-03-19

Hello @jaumeortola

Can you help?

I don’t know what is wrong with this rule:

<!-- 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.+”

Thanks!

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.”

Ahhhh… I am going to test it soon.

The idea of this rule is to simplify the grammar.

So, instead of a big sentence, it becomes smaller and clearer to read.

What would be the best to replace the “Improve your redaction”?

Thanks!

Something along the lines of “Com o pronome ‘cujo’, seu texto poderia ficar mais claro e elegante.”?

ahhhhh… thanks!

I still have an issue. It suggests both verbs:

How do I make it suggest only one and the proper one?

Thanks!

If you only want it to give “ser” in the same form as “ter”, only make this one suggestion:

<suggestion>cujo objetivo <match no='2' postag=".*" postag_regexp="yes">ser</match></suggestion>

This way, it will pick up any postag “ter” has in token \2 and transfer it to “ser”.

You could also add other postags to token \2. How about VMSP3S0?

Precisamos de uma iniciativa que tenha como objetivo diminuir o número de mortos no trânsito. → cujo objetivo seja

And how about VMSI3S0?

Precisávamos de uma iniciativa que tivesse como objetivo diminuir o número de mortos no trânsito. → cujo objetivo fosse

@udomai

The problem with “tem” is that it doesn’t suggest “é”:

The rule is now:

<!-- 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 :slight_smile:

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ê”.

@udomai

Thank you!

It is implemented and tested against a 200 000 corpora and it works like planned:

1 Like