Add --per-item-disable: change the disabled lexemes (-L) between inputs #2
No response for #DISABLE lines. Nothing is written to stdout or stderr when a directive is consumed. A client that sends one line and then blocks reading one response (e.g. pydelphin's ACE interface, or art with --tsdb-stdout) will hang — and those are the most likely users of a per-item setting. Could we print a short acknowledgement (at least in tsdb-stdout mode), or otherwise clearly document that clients must not wait for a reply?
Prefix check has no word boundary. strncmp(lineptr, "#DISABLE", 8) also matches e.g. #DISABLED items follow: that line is silently not parsed, and D items follow becomes the disabled list for all following sentences. Suggest also requiring lineptr[8] to be '\0' or whitespace (' ', '\t', '\r', '\n').
Minor: this is only checked in the parsing branch of main_input_loop. With --per-item-disable in generation/transfer mode, a #DISABLE line goes to read_mrs_string_or_line and is treated as malformed MRS. Maybe reject the option outside parsing mode, or skip these lines in the generation branch too.
Nit: the trailing trim strips \n, \r and space but not \t, unlike the leading trim above, so #DISABLE foo\t stores foo\t. Harmless with the current strstr matching, but worth making consistent.
Thanks for this — being able to change the disabled lexemes per item without restarting ACE is useful. A few comments inline.
One more point that can't be attached inline because the line isn't in the diff: disabled lexemes are matched in morpho.c (lex_handler, ~line 225) with strstr(disable_signs, lex->word). That tests whether the lexeme name occurs anywhere in the list string, so #DISABLE hotdog_n1 would also disable dog_n1 or hot if such lexemes exist. This predates the PR (-L has always behaved this way), but the PR documents it as "same format and matching as -L" and now lets every input item trigger it. Splitting the list into whole names and comparing exactly would be safer — fine as a follow-up.
Thank you for the review! I've pushed a second commit that addresses the inline comments.
arademaker
olzama
Add --per-item-disable: change the disabled lexemes (-L) between inputs
A new, opt-in command-line option for parsing mode. With
--per-item-disable:#DISABLE <lexemes>sets the lexemes disabled for the inputs that follow it, in the same format and with the same substring matching as-L;#DISABLEline restores the-Lvalue given on the command line;#DISABLEfollowed by the end of the line or whitespace (#DISABLED ...is an ordinary input);NOTE: #DISABLE: ..., followed by two empty lines, the terminator of every item, so a client that reads one response per input line (pydelphin'sACEParser.interact, console or--tsdb-stdout) stays in step;-eor a transfer grammar ACE refuses the option.Without the option nothing changes. The change is confined to
main.c(the option, one branch in the input loop next to the LUI:commands, and the parsing-mode check) plus one line indoc/options.wiki.Motivation
-Lcan only be set once, when ACE starts. A caller that wants a different restriction for every sentence (for example, parsing with only the lexical entries a supertagger proposes for that sentence) has to start ACE once per sentence. Starting ACE and touching the mapped grammar image costs about 30 to 35 ms per sentence with the ERG on our machine, more than the parsing itself for most short sentences. With this option one ACE process serves all sentences.Usage
Testing
Tested with ERG 2025 (compiled with this branch's base, main at 31afda8) and 300 sentences drawn at random (fixed seed) from the Redwoods dev profiles:
1. Two builds from the same commit.
mainas is ("stock") andmainwith this patch ("patched"), same compiler and flags; both report the same version.2. Without the option, nothing changes. Both builds parse the 300 sentences in one process each, first-best (
-1) and 20-best (-n 20), with the same memory limits. We compare the console output item by item: the MRS and the derivation of every result, in rank order (timings excluded).3. With the option, the same parses as restarting ACE. For each sentence we take a restriction list as a real caller would build it: our supertagger's five best lexical types per word (probability at least 0.001) turned into lexical entries, and every other lexeme that could match the sentence's words disabled, about 70 lexemes per sentence on average. Then:
- reference: stock
mainstarted once per sentence with-L <that list>;- patched: one process started with
--per-item-disable, fed#DISABLE <that list>followed by the sentence, for all 300 sentences in turn.We check that every directive is answered by exactly one
NOTE: #DISABLE:block in its place, drop those blocks, and compare item by item as in step 2, for-1and for-n 20.4. The restriction really changes between inputs. In one process: "The dog barked." with
#DISABLE bark_v1, then a bare#DISABLE, then#DISABLE bark_v1again. Withoutbark_v1ACE gives only fragment analyses without the verb's predicate; with it, the ordinary parse. Each of the three outputs equals a separate stock run with the corresponding-L.5. Review fixes.
#DISABLED bark_v1is parsed as a sentence, with the same output as stock;#DISABLE<TAB>bark_v1<TAB>gives the same output as#DISABLE bark_v1;-e --per-item-disableexits with an error. pydelphin 1.11'sACEParser.interact(console and--tsdb-stdout), sent#DISABLElines and sentences in turn, gets one response per line and the expected parses (pydelphin's own option check had to be told about the new flag for this test).6. Timing. Wall-clock time per sentence for step 3's two set-ups, on the same machine in the same session (it was running other jobs, so the absolute numbers are higher than on an idle machine).
| Check | Result |
|---|---|
| Step 2,
-1and-n 20| byte-identical || Step 3,
-1| 300 of 300 identical, one acknowledgement per directive || Step 3,
-n 20| 300 of 300 identical, one acknowledgement per directive || Steps 4 and 5 | pass |
| Step 6, time per sentence, one ACE run per sentence → one process | 178 → 138 ms (
-n 20: 183 → 141 ms) |Time limits: ACE's
--timeoutis wall-clock time (alarm()). The first run of steps 2 and 3 used--timeout=60on a heavily loaded machine, and a few sentences then differed between runs (in step 2's 20-best run and in two items of step 3); rerun without--timeout, all of them are identical. The table reports those reruns for the affected comparisons.The first revision of this change (without the review fixes), applied to the 0.9.34 release, passed the same checks (and a full run over all 2,062 dev sentences with identical results), and is used by our parser and its public demo. The test script is available on request.
License
Contributed under ACE's existing license.