[pt] Name for rule

Hello @udomai

I am planning to create one more rule to simplify the paragraphs:

Este artigo não tem nome… aparece no ecrã um número. → APARECE UM NÚMERO NO ECRÃ

“V.+” PLUS “na(s)/no(s)” PLUS “NC.+|AQ0.+”
+
“um/uns/uma/umas/vário(s)” PLUS “NC.+|AQ0.+”

What name should I give to it?

Thanks!

Cool! I’d call it something like COLOCACAO_ADVERBIOS_LUGAR or COLOCACAO_ADV_LUGAR :slightly_smiling_face:

@udomai

Sorry to bother you.

I am getting errors in the rule:

	<!-- APARECE NO ECRÃ UM NÚMERO aparece um número no ecrã -->
    <rule id='COLOCACAO_ADVERBIOS_LUGAR' name="Colocação advérbios Lugar">
    <!--      Created by Marco A.G.Pinto, Portuguese rule 2021-05-12 (17-MAR-2021+)      -->
	<!--
Assim aparece no ecrã um número. → Assim aparece um número no ecrã.
	-->
		<pattern>
			<token postag='V.+' postag_regexp='yes'/>
			<marker>
				<token postag='SPS00.+' postag_regexp='yes'>
					<exception regexp='yes'>aos?</exception>
				</token>
				<token postag='NC.+|AQ0.+' postag_regexp='yes'>
					<exception postag_regexp='yes' postag='AO.+'/>
				</token>
				<token postag='DI.+|Z0.+' postag_regexp='yes'/>
				<token min="1" max="3" postag='NC.+|AQ0.+' postag_regexp='yes'/>
			</marker>
			<token negate_pos="yes" postag='SPS00' postag_regexp='no'/>		
		</pattern>		
		<message>Esta perífrase pode ser simplificada.</message>
		<suggestion>\4 \5 \6 \7 \2 \3</suggestion>
		<example correction="um grande número redondo no ecrã">Assim aparece <marker>no ecrã um grande número redondo</marker>.</example>
    </rule>

Errors:

Testing rule 2600…
Skipped 0 rules for variant language to avoid checking rules more than once
2697 rules tested.
Exception in thread “main” org.languagetool.rules.patterns.PatternRuleTest$PatternRuleTestFailure: Test failure for rule COLOCACAO_ADVERBIOS_LUGAR[1] in file /org/languagetool/rules/pt/grammar.xml: Incorrect suggestions: Expected ‘um grande número redondo no ecr?’, got: ‘um redondo . . no ecr?’ on input: ‘Assim aparece no ecr? um grande número redondo.’
at org.languagetool.rules.patterns.PatternRuleTest.addError(PatternRuleTest.java:341)
at org.languagetool.rules.patterns.PatternRuleTest.assertSuggestions(PatternRuleTest.java:589)
at org.languagetool.rules.patterns.PatternRuleTest.testBadSentences(PatternRuleTest.java:481)
at org.languagetool.rules.patterns.PatternRuleTest.lambda$testGrammarRulesFromXML$1(PatternRuleTest.java:370)
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)
Running disambiguator rule tests…
Running disambiguation tests for Portuguese…

I am brain toasted and can’t figure out what is wrong.

Also, what should I write in the suggestion message?

Thanks!

Hi @marcoagpinto!

There seems to be something going wrong with max="3", because if I say “exactly 3”, the given example works fine (provided you specify the suggestion):

	<!-- APARECE NO ECRÃ UM NÚMERO aparece um número no ecrã -->

    <rule id='COLOCACAO_ADVERBIOS_LUGAR' name="Colocação advérbios Lugar">

    <!--      Created by Marco A.G.Pinto, Portuguese rule 2021-05-12 (17-MAR-2021+)      -->

	<!--

Assim aparece no ecrã um número. → Assim aparece um número no ecrã.

	-->

		<pattern>

			<token postag='V.+' postag_regexp='yes'/>

			<marker>

				<token postag='SPS00.+' postag_regexp='yes'>

					<exception regexp='yes'>[ao]s?</exception>

				</token>

				<token postag='NC.+|AQ0.+' postag_regexp='yes'>

					<exception postag_regexp='yes' postag='AO.+'/>

				</token>

				<token postag='DI.+|Z0.+' postag_regexp='yes'/>

				<token postag='NC.+|AQ0.+' postag_regexp='yes'/>
				
				<token postag='NC.+|AQ0.+' postag_regexp='yes'/>
				
				<token postag='NC.+|AQ0.+' postag_regexp='yes'/>

			</marker>
			
			<token postag='SPS00' negate_pos="yes"/>

		</pattern>		

		<message>Esta perífrase pode ser simplificada.</message>

		<suggestion>\4 \5 \6 \7 \2 \3</suggestion>

		<example correction="um grande número redondo no ecrã">Assim aparece <marker>no ecrã um grande número redondo</marker>.</example>

    </rule>

Message-wise… something like “O ritmo da sua frase resultaria mais natural se colocar o adverbio depois do objeto.”?

Fixed!

I am about to test it.

Thanks!

Buaaaaaaaaaaaaaa…

	<!-- APARECE NO ECRÃ UM NÚMERO aparece um número no ecrã -->
    <rule id='COLOCACAO_ADVERBIOS_LUGAR' name="Colocação advérbios Lugar">
    <!--      Created by Marco A.G.Pinto, Portuguese rule 2021-05-12 (17-MAR-2021+)      -->
	<!--
Assim aparece no ecrã um número. → Assim aparece um número no ecrã.
	-->
		<pattern>
			<token postag='V.+' postag_regexp='yes'/>
			<marker>
				<token postag='SPS00.+' postag_regexp='yes'>
					<exception regexp='yes'>aos?</exception>
				</token>
				<token postag='NC.+|AQ0.+' postag_regexp='yes'>
					<exception postag_regexp='yes' postag='AO.+'/>
				</token>
				<token postag='DI.+|Z0.+' postag_regexp='yes'/>
				<token max="3" postag='NC.+|AQ0.+' postag_regexp='yes'/>
			</marker>
			<token negate_pos="yes" postag='SPS00' postag_regexp='no'/>		
		</pattern>		
		<message>O ritmo desta frase resultaria mais natural se colocar o advérbio depois do objeto.</message>
		<suggestion>\4 \5 \6 \7 \2 \3</suggestion>
		<example correction="um número no ecrã">Assim aparece <marker>no ecrã um número</marker>.</example>
    </rule>

It flags:

Assim aparece no ecrã um número vaso bonito.

But in the suggestion it gives:

Assim aparece um bonito . . no ecrã.

Yes, if you use max=“3”, there are no \6 and \7 :slight_smile:

yes, but if:

	<!-- APARECE NO ECRÃ UM NÚMERO aparece um número no ecrã -->
    <rule id='COLOCACAO_ADVERBIOS_LUGAR' name="Colocação advérbios Lugar">
    <!--      Created by Marco A.G.Pinto, Portuguese rule 2021-05-12 (17-MAR-2021+)      -->
	<!--
Assim aparece no ecrã um número. → Assim aparece um número no ecrã.
	-->
		<pattern>
			<token postag='V.+' postag_regexp='yes'/>
			<marker>
				<token postag='SPS00.+' postag_regexp='yes'>
					<exception regexp='yes'>aos?</exception>
				</token>
				<token postag='NC.+|AQ0.+' postag_regexp='yes'>
					<exception postag_regexp='yes' postag='AO.+'/>
				</token>
				<token postag='DI.+|Z0.+' postag_regexp='yes'/>
				<token max="3" postag='NC.+|AQ0.+' postag_regexp='yes'/>
			</marker>
			<token negate_pos="yes" postag='SPS00' postag_regexp='no'/>		
		</pattern>		
		<message>O ritmo desta frase resultaria mais natural se colocar o advérbio depois do objeto.</message>
		<suggestion>\4 \5 \2 \3</suggestion>
		<example correction="um número no ecrã">Assim aparece <marker>no ecrã um número</marker>.</example>
    </rule>

I tried in the stand-alone tool:

Assim aparece um número no ecrã.
Assim aparece no ecrã um número vaso bonito.

and the second turns to:

Assim aparece um bonito no ecrã.

What could be wrong?

Thanks!

I am so stressed :slightly_frowning_face:

Dont be! :slightly_smiling_face: we’ll find a solution

I think this is a bug in the max function in PT. I think @jaumeortola or I will find a solution (just give us some time to look into the matter).

The problem here is that invoking \5 in the suggestion does not reproduce all of the up to three words.

There is no immediate solution for this kind of rules. Perhaps it could be done with skip and include_skipped. But It becomes too complex. I would say that it is better to write 3 different rules for different numbers of tokens (1 to 3).

@jaumeortola

Great idea to write three rules.

:slight_smile:

Thanks both of you for the help.

I will do it tomorrow at 5am as usual.

Done!