From 22d346b746c6136a878c84f85acbcd69900016e5 Mon Sep 17 00:00:00 2001 From: OfficialAbhinavSingh Date: Thu, 12 Nov 2026 19:10:02 +0530 Subject: [PATCH] fix(sql-optim-env): match -ly and doubled-consonant keyword endings Matching issue keywords as whole words (#1006) stopped `explicitly`, `implicitly`, `full scanning` and `zone mapping` from matching the `explicit`, `implicit`, `full scan` and `zone map` keywords, which the earlier substring matcher accepted. Allow a `-ly` ending, and let a final consonant double before -ing/-ed. Every form this re-allows was also matched by the substring matcher, and the fragments the whole-word change rejected (`star` in `started`, `cast` in `forecast`, `join` in `joint`) stay rejected. --- envs/sql_optim_env/server/graders.py | 18 +++++++++++++----- tests/envs/test_sql_optim_environment.py | 10 ++++++++-- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/envs/sql_optim_env/server/graders.py b/envs/sql_optim_env/server/graders.py index aafa75721..9c73d2da0 100644 --- a/envs/sql_optim_env/server/graders.py +++ b/envs/sql_optim_env/server/graders.py @@ -52,15 +52,17 @@ class GradeMask: # Endings a keyword may carry and still name the same thing: plurals, tenses, -# and the -ate/-ation family that the deliberate stems (`aggreg`, `concatenat`) -# are written to reach. Any other letter or digit after a keyword means it is -# only the start of a different word (`star` in `started`, `join` in `joint`). +# `-ly` adverbs (`explicitly`), and the -ate/-ation family that the deliberate +# stems (`aggreg`, `concatenat`) are written to reach. Any other letter or digit +# after a keyword means it is only the start of a different word (`star` in +# `started`, `join` in `joint`). _KW_SUFFIXES = ( "s", "es", "d", "ed", "e", + "ly", "ing", "ion", "ions", @@ -71,11 +73,14 @@ class GradeMask: "ated", "ating", ) +# A final consonant can double before -ing/-ed (`scan` -> `scanning`, +# `map` -> `mapped`). +_KW_CONSONANTS = frozenset("bcdfghjklmnpqrstvz") @functools.lru_cache(maxsize=None) def _kw_pattern(keyword: str) -> "re.Pattern[str]": - """Compile *keyword* to match as a whole word, allowing `_KW_SUFFIXES`. + """Compile *keyword* to match as a whole word, allowing its usual endings. The boundary is a letter or digit, not `\\w`: an underscore separates words here, so a structured `issue_type` such as `select_star` still matches @@ -87,7 +92,10 @@ def _kw_pattern(keyword: str) -> "re.Pattern[str]": if kw[:1].isalnum(): pattern = r"(?