Skip to content

@PRE conditions can be written on the rule element (#438) (4.2.26) - #782

Merged
ddehilster merged 1 commit into
masterfrom
feature/element-pre-438
Oct 14, 2026
Merged

ddehilster merged 1 commit into
masterfrom
feature/element-pre-438

Conversation

@ddehilster

Copy link
Copy Markdown
Member

Closes #438 (option A, as decided; the comparison syntax pos="noun" can follow later as sugar).

A @PRE action can now be a key on the element it applies to, so its <n,n> range no longer has to be kept in step with element positions. This rule:

_np <- _det _xWILD [plus match=(_noun _adj) vareq=("pos" "noun") varz="num"] @@

means exactly the same as:

@PRE
<2,2> vareq("pos", "noun");
<2,2> varz("num");
@RULES
_np <- _det _xWILD [plus match=(_noun _adj)] @@

Supported actions: every action Pat::preAction knows: var varz vareq varne vargt varlt regexp regexpi uppercase lowercase cap length lengthr numrange unknown debug.

  • A single value is written varz="num", several as a list vareq=("pos" "noun"), and an action with no arguments by name alone, as in [cap].
  • None of these names was an element key before. 4.2.25 reports "Unknown element key" for each.

How it works.

  • Ielt::intern turns the key into an Ipre covering just this element. It sits beside any the rule's @PRE region gives the element, so matching treats both identically, as do wildcards (NLP++: Overly broad @PRE conditions fail #449) and compiled analyzers (genPres).
  • Values arrive as strings. For numrange, length and lengthr, numeric strings become numbers, as they are when written in a @PRE region; the compiled form needs it.

Testing

  • New fixture tests/element-pre, with CI steps for Windows and Linux. Each case runs twice, once with @PRE and once with element keys, and both must match the same text:

    • vareq on an element, and varz on a wildcard;
    • two conditions on one element, and a bare flag (uppercase);
    • cap, numrange, and regexp (a glob);
    • element keys mixed with a rule-level @PRE.

    On 4.2.18 the element-key versions are rejected and fire unconditionally (31 lines instead of 17).

  • I also built the fixture as a compiled analyzer DLL; its output is identical to the interpreted run.

  • All Windows CI fixture steps pass locally, apart from the compiled-bridge step, which needs CI's packaged libraries. The -DEV Full English Test is unchanged, and all 20 analyzers (21 inputs) produce byte-identical output to 4.2.18.

Docs: VisualText/visualtext-files (PR linked below).

🤖 Generated with Claude Code

A @pre action can now be a key on the element it applies to, so its
<n,n> range no longer has to be kept in step with element positions:
    _np <- _det _xWILD [plus match=(_noun _adj) vareq=("pos" "noun") varz="num"] @@
is the same as
    @pre
    <2,2> vareq("pos", "noun");
    <2,2> varz("num");

Ielt::intern turns such a key (any action Pat::preAction knows) into an Ipre
covering just this element, beside the ones its @pre region gives it, so
matching, wildcards (#449) and compiled analyzers treat it exactly as @pre.
Numeric-string values become numbers for numrange/length/lengthr, as they are
from a @pre region; the compiled form needs it. None of these names was an
element key before (4.2.25 reports "Unknown element key").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ddehilster
ddehilster merged commit 048670e into master Oct 14, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NLP++: Attributes in rule element

1 participant