Back to LanguageTool Homepage - Privacy - Imprint

How do I match the tense of a previous verb?

Hello! I am trying to figure out a solution to a suggestion when I want to inflect a verb to match the tense of a verb I am replacing. Here’s a pattern and example:

<token inflected="yes">proceed<exception>proceeding</exception></token>
<token>to</token>
<token postag="VB"/>

This pattern will flag the following:

He proceeded to schedule an interview.

Suppose I wish to change the sentence to “He went on to schedule an interview.” This is straightforward:

<suggestion><match no="1" postag="(V.*)" postag_regexp="yes" postag_replace="$1">go</match> on to \3</suggestion>

My question is: What happens when I want to change the sentence to “He scheduled an interview.”? The issue is that the verb is detected as a VB so I do not have it at the time I am writing the rule. It’s “dynamic” in the sense that I don’t know it until a sentence is run. Is there a way to accomplish this?

I naively tried the following, which doesn’t do anything:

<match no="1" postag="(V.*)" postag_regexp="yes" postag_replace="$1">\3</match>

And this naive pattern creates “He scheduleed an interview.” (incorrect):

<suggestion>\3<match no="1" regexp_match="proceed(.*)" regexp_replace="$1"/></suggestion>

Any suggestions would be helpful. Thank you!

Here is the rule I am trying to work with:

	<rule id="PROCEED_TO_VB" name="proceed to VB">
		<pattern>
			<token inflected="yes">proceed<exception>proceeding</exception></token>
			<token>to</token>
			<token postag="VB">
			</token>
		</pattern>
		<message>Shortening this sentence may make it clearer.</message>
		<suggestion>\3<match no="1" regexp_match="proceed(.*)" regexp_replace="$1"/></suggestion>
		<suggestion>then \3</suggestion>
		<suggestion><match no="1" postag="(V.*)" postag_regexp="yes" postag_replace="$1">go</match> on to \3</suggestion>
		<example correction="scheduled|then scheduled|went on to schedule">He <marker>proceeded to schedule</marker> an interview.</example>
	</rule>

The first suggestion fails because I’m trying to get “to schedule” to conjugate against “He”. Any insights are appreciated. Thanks!

Hi @Tyler!

Without having tried it, here is a general tip: The regexp_match and replace can sometimes be prone to bugs. I suggest working with the postags instead:

So, does it work if instead of this:

<match no="1" regexp_match="proceed(.*)" regexp_replace="$1"/>

you do this:

<match no="1" postag="VBP"/>

?

Hi @udomai

Yes, this is a fantastic start. However, when we declare:

<match no="1" postag="VBP"/>

What we are actually trying to do is conjugate “schedule” into the same form as “proceed” when we don’t know the form of “proceed” until runtime. When we declare VBP, we are assuming that match 1 is non-3rd person singular present, but it might not be if “proceed” is a different form.

The only workaround I can think of right now is to create at least three different rules targeting the different forms of “proceed” and using the correct postag explicitly.

Hi @Tyler,

I see! You need to transfer the postag of \1 (any form of proceed, but it needs to be a verb form) to the verb in \3.

In the suggestion, if you want a matching form of the verb in \3, you can use our AdvancedSynthesizerFilter which was made exactly for this kind of situation. This way, you only need one rule:

	<rule id="PROCEED_TO_VB" name="proceed to VB">
		<pattern>
			<token postag="V.*" postag_regexp="yes" inflected="yes">proceed<exception>proceeding</exception></token>
			<token>to</token>
			<token postag="VB"/>
		</pattern>
        <filter class="org.languagetool.rules.en.AdvancedSynthesizerFilter" args="lemmaFrom:3 lemmaSelect:V.* postagFrom:1 postagSelect:V.*"/>
		<message>Shortening this sentence may make it clearer.</message>
		<suggestion>{suggestion}</suggestion>
		<suggestion>then {suggestion}</suggestion>
		<suggestion><match no="1" postag="(V.*)" postag_regexp="yes" postag_replace="$1">go</match> on to \3</suggestion>
		<example correction="scheduled|then scheduled|went on to schedule">He <marker>proceeded to schedule</marker> an interview.</example>
	</rule>

The documentation about this filter can be found here.

This is incredible! Great, I will dig into this documentation. I appreciate your help! :smile:

1 Like

Hi @udomai! I have a follow-up question.

Suppose now the rule works but could be improved for sentences in this form:

He proceeded to prepare and bake a cookie.

Is there a way to improve our rule such that we can leverage multiple {suggestion} tags?

For example, can we do something along the lines of this?

<rule id="PROCEED_TO_VB" name="proceed to VB">
    <pattern>
        <token postag="V.*" postag_regexp="yes" inflected="yes">proceed<exception>proceeding</exception></token>
        <token>to</token>
        <token postag="VB"/>
        <token>and</token>
        <token postag="VB"/>
    </pattern>
    <filter class="org.languagetool.rules.en.AdvancedSynthesizerFilter" args="lemmaFrom:3 lemmaSelect:V.* postagFrom:1 postagSelect:V.*"/>
    <filter class="org.languagetool.rules.en.AdvancedSynthesizerFilter" args="lemmaFrom:5 lemmaSelect:V.* postagFrom:1 postagSelect:V.*"/> <!-- Can we do this? -->
    <message>Shortening this sentence may make it clearer.</message>
    <suggestion>{suggestion} and {suggestion2}</suggestion> <!-- Unsure. -->
    <suggestion>then {suggestion} and {suggestion2}</suggestion> <!-- Unsure. -->
    <suggestion><match no="1" postag="(V.*)" postag_regexp="yes" postag_replace="$1">go</match> on to \3 and \5</suggestion>
    <example correction="prepared and baked|then prepared and baked|went on to prepare and bake">He <marker>proceeded to prepare and bake</marker> a cookie.</example>
</rule>

Obviously, if the two rules could be a single rule with the last two tokens as optionals, that would be great, but two rules can work as well. Any insights help!

Thanks! I appreciate all your help. :slight_smile:

Hi @Tyler!

Sorry for making you wait, I have been out of the office for a while.

I like your idea! For now, we cannot combine two filters, but your case is a good example for why that would be quite useful.

I’ll have a chat with the team to see if we can implement this right away. If it requires lots of changes, it could take a while, though.

1 Like