apertium / apertium-recursive

Recursive structural transfer module for Apertium
https://wiki.apertium.org/wiki/Apertium-recursive
GNU General Public License v3.0
6 stars 4 forks source link

Checking variables in rule matching #58

Closed ftyers closed 4 years ago

ftyers commented 4 years ago

It might be a nice idea to be able to have rules which only apply if certain conditions apply, e.g. "only apply this rule if the subject of V¹ agrees with the subject of V²". Potentially something like <assert>?

  <rule comment="V-TV V-TV" firstChunk="SV">
   <pattern>
    <pattern-item n="V-TV"/>
    <pattern-item n="V-TV"/>
   </pattern>
   <assert>
     <equal><clip pos="1" side="tl" part="a_agr_subj"/><clip pos="1" side="tl" part="a_agr_subj"/></equal>
   </assert>
   <action>
      <call-macro n="f_set_chunk_name1"><with-param pos="1"/></call-macro>
      <out>
       <chunk namefrom="chunkName">
        <tags>
         <tag><lit-tag v="SV.tv"/></tag>
         <tag><clip pos="1" side="tl" part="a_agr_subj"/></tag>
         <tag><clip pos="1" side="tl" part="a_agr_obj"/></tag>
        </tags>
        <lu> <clip pos="1" side="tl" part="whole"/> </lu>
        <b/>
        <lu><lit v="que"/><lit-tag v="cnjsub"/></lu>
        <b/>
        <lu> <clip pos="2" side="tl" part="whole"/> </lu>
       </chunk>
      </out>
   </action>
  </rule>
mr-martian commented 4 years ago

Current syntax for that is

<choose>
  <when>
    <test>
      <not>
        <equal><clip pos="1" side="tl" part="a_agr_subj"/><clip pos="1" side="tl" part="a_agr_subj"/></equal>
      </not>
    </test>
    <reject-current-rule/>
  </when>
</choose>

But something like <assert> would definitely be doable.

ftyers commented 4 years ago

Hmm, that syntax is a bit verbose, even for XML and even for me! Also it seems to make something procedural (if then) where I think it should be declarative. Also, it shouldn't be part of the action.

Would it take long to implement it?

mr-martian commented 4 years ago

Would it take long to implement it?

10 minutes, apparently. :)

mr-martian commented 4 years ago

If an <assert> contains multiple clauses or there are multiple <assert>s, they will be ANDed together and they must all precede the <action>.

<assert> may contain anything that could appear in <test>.

ftyers commented 4 years ago

AND and yeah, basically anything in <test>

ftyers commented 4 years ago

  <rule comment="SV SD" firstChunk="S">
   <pattern>
    <pattern-item n="SV"/>
    <pattern-item n="SD"/>
   </pattern>
   <assert>
     <equal><clip pos="1" side="tl" part="a_agr_subj"/><clip pos="2" side="tl" part="a_agr_subj"/></equal>
   </assert>
   <action>
      <call-macro n="f_set_chunk_name1"><with-param pos="1"/></call-macro>
      <call-macro n="f_concord_subj2"><with-param pos="1"/><with-param pos="2"/></call-macro>
      <out>
       <chunk namefrom="chunkName">
        <tags>
         <tag><lit-tag v="S.tv"/></tag>
         <tag><clip pos="1" side="sl" part="a_agr_subj"/></tag>
         <tag><clip pos="1" side="sl" part="a_agr_obj"/></tag>
        </tags>
        <lu> <clip pos="2" side="tl" part="whole"/> </lu>
        <b/>
        <lu> <clip pos="1" side="tl" part="whole"/> </lu>
       </chunk>
      </out>
   </action>
  </rule>

but:

fran@ipek:~/source/apertium/pairs/apertium-quc-spa$ make
trx-comp quc-spa.rtx.bin apertium-quc-spa.quc-spa.rtx
Error in apertium-quc-spa.quc-spa.rtx on line 830: Unrecognized condition 'text'
Makefile:837: recipe for target 'quc-spa.rtx.bin' failed
make: *** [quc-spa.rtx.bin] Error 1

I should be on the latest version:

commit f11e6166afb33807d94e921a935e8ebfbcca2761 (HEAD -> master, origin/master, origin/HEAD)
Author: Daniel Swanson <popcorn.tomato.dude@gmail.com>
Date:   Mon Jul 6 11:27:39 2020 -0400

    add <assert> in trx - #58
mr-martian commented 4 years ago

Typo on my part - trying to skip spaces on the wrong element.