[pt] "HÁ n TEMPO ATRÁS" rule improvement

@Yakov @tiagosantos

This rule used to be:

    <!-- HÁ n SEGUNDOS/MINUTOS/HORAS/DIAS/SEMANAS/MESES/ANOS ATRÁS (remove "ATRÁS") -->
    <rule id="HÁ-ATRÁS" name="há n tempo atrás">
      <pattern>
        <token skip="-1">há</token>
        <token regexp="yes">segundos?|minutos?|horas?|dias?|semanas?|mês|meses|anos?</token>
        <token>atrás</token>
      </pattern>
      <message>Com o verbo haver não é necessário usar "atrás": <suggestion><match no="1" include_skipped="all"/> <match no="2"/></suggestion>.</message>
      <example correction="Há n segundos"><marker>Há n segundos atrás</marker>.</example>
    </rule>

Tiago improved it to:

    <!-- HÁ n SEGUNDOS/MINUTOS/HORAS/DIAS/SEMANAS/MESES/ANOS ATRÁS (remove "ATRÁS") -->
    <rule id="HÁ-ATRÁS" name="há n tempo atrás">
      <pattern>
          <token>há</token>
      <token min="0" regexp="yes">quase|poucos?|alguns|cerca</token>
      <token skip="4"><exception scope="next" postag='VM[CIS][CFIMPS][0123][SP]0' postag_regexp='yes'></exception></token>
        <token regexp="yes">segundos?|minutos?|horas?|dias?|semanas?|mês|meses|anos?|tempos?</token>
      <marker>
        <token>atrás</token>
      </marker>
      </pattern>
      <message>Com o verbo haver não é necessário usar "atrás": <suggestion></suggestion>.</message>
      <example correction="">Há n segundos <marker>atrás</marker>.</example>
    </rule>

But it doesn’t show a correction example/suggestion now.

I tried changing it to the following but TESTRULES PT gives errors:

    <!-- HÁ n SEGUNDOS/MINUTOS/HORAS/DIAS/SEMANAS/MESES/ANOS ATRÁS (remove "ATRÁS") -->
    <rule id="HÁ-ATRÁS" name="há n tempo atrás">
      <pattern>
            <token>há</token>
            <token min="0" regexp="yes">quase|poucos?|alguns|cerca</token>
            <token skip="4"><exception scope="next" postag='VM[CIS][CFIMPS][0123][SP]0' postag_regexp='yes'></exception></token>
            <token regexp="yes">segundos?|minutos?|horas?|dias?|semanas?|mês|meses|anos?|tempos?</token>
            <token>atrás</token>
      </pattern>
      <message>Com o verbo haver não é necessário usar "atrás": <suggestion><match no="1" include_skipped="all"/> <match no="2"/></suggestion>.</message>
      <example correction="Há n segundos"><marker>Há n segundos atrás</marker>.</example>
    </rule>

@Yakov
You are the brain so I would like to ask you what needs to be changed.

Thanks!

Kind regards,

It does suggest a blank space (""). There is a minor issue though, it creates a double space that is recognized afterwards.
Try replacing <token>atrás</token> with <token spacebefore="yes">atrás</token> and see if it works.

@tiagosantos

My idea was that it should show the full words to be replaced without the “atrás”, just like it used to do in the first version of the rule.
“há 10 horas atrás”
should suggest:
“há 10 horas”
just like it did before.

That would be ideal but I still do not know how to insert optional tokens on the suggestions (the ones with token min=‘0’).

My next project is to localize all rules from Spanish, Galician, French and Italian grammar.xml that apply to Portuguese. It is a low hanging fruit that allows hundreds of rules to be ported before the next release and it allows to learn while doing. I prefer not to be side tracked until that is done.

If you figure out how to do it tell me, because that would make suggestions for other rules viable.

I still do not know how to insert optional tokens on the suggestions

You can use include_skipped="all"

like this:

<suggestion><match no="1" include_skipped="all" ></match> <match no="2" include_skipped="all" ></match></suggestion>

http://wiki.languagetool.org/tips-and-tricks#toc17

@Yakov

It still doesn’t work with TESTRULES PT :frowning:

    <!-- HÁ n SEGUNDOS/MINUTOS/HORAS/DIAS/SEMANAS/MESES/ANOS ATRÁS (remove "ATRÁS") -->
    <rule id="HÁ-ATRÁS" name="há n tempo atrás">
      <pattern>
        <token>há</token>
        <token min="0" regexp="yes">quase|poucos?|alguns|cerca</token>
        <token skip="4"><exception scope="next" postag='VM[CIS][CFIMPS][0123][SP]0' postag_regexp='yes'></exception></token>
        <token regexp="yes">segundos?|minutos?|horas?|dias?|semanas?|mês|meses|anos?|tempos?</token>
        <token>atrás</token>
      </pattern>
      <message>Com o verbo haver não é necessário usar "atrás": <suggestion><match no="1" include_skipped="all" ></match> <match no="2" include_skipped="all" ></match></suggestion>.</message>
      <example correction="Há n segundos"><marker>Há n segundos atrás</marker>.</example>
    </rule>

@Yakov

Thank you very much Yakov.
I was not aware that it would work for token min=‘’ too. I will play with it in the next week.

Try:
<suggestion>\1 <match no="2" include_skipped="all" ></match> <match no="3" include_skipped="all" ></match></suggestion>

I have not tested it. Tell me if it works.

No, it still doesn’t work :frowning: :frowning: :frowning:

This variant is work correct:

 <rule id="HÁ-ATRÁS" name="há n tempo atrás">
      <pattern>
        <token>há</token>
        <token min="0" regexp="yes">quase|poucos?|alguns|cerca</token>
        <token skip="4"><exception scope="next" postag='VM[CIS][CFIMPS][0123][SP]0' postag_regexp='yes'></exception></token>
        <token regexp="yes">segundos?|minutos?|horas?|dias?|semanas?|mês|meses|anos?|tempos?</token>
        <token>atrás</token>
      </pattern>
      <message>Com o verbo haver não é necessário usar "atrás": <suggestion><match no="1" include_skipped="all" ></match> <match no="2" include_skipped="all" ></match> <match no="3" include_skipped="all" ></match> <match no="4" include_skipped="all" ></match></suggestion>.</message>
      <example correction="Há n segundos"><marker>Há n segundos atrás</marker>.</example>
    </rule>

@Yakov

Thanks, it is working and I have committed it.

@tiagosantos
It is now working 100%