Repository navigation
Prefix match for keywords ending in * - #190
Conversation
win* finds wins and winning; plain words stay whole-word matches. A lone * or one inside a word is a separator like before.
A21-devs
left a comment
There was a problem hiding this comment.
Checked that keyword_tokens splits exactly like tokens when there's no *: both produce runs of [\w'] minus _ with the apostrophes stripped at the ends, so existing keywords parse the same as before. The transcript side still goes through tokens(), so stars in whisper output aren't wildcards, and the starred phrase string goes through to the reasons and explain.py unchanged (that one is escaped). One real problem, with the length of the prefix.
| for m in _KEY_WORD.finditer(_normalise(text)): | ||
| word = m.group(1).strip("'") | ||
| if word: | ||
| out.append(word + (PREFIX if m.group(2) else "")) |
There was a problem hiding this comment.
Nothing limits how short the prefix can be. On the TTS test transcript (502 words) t* hits 96 times, th* 75 and a* 36. With hits that dense every window reaches KEYWORD_CAP, so the boost is the same for every window: it can't change the pick, and every clip's reasons say said "t*", which looks like it worked. It's an easy thing to type by accident (no way, i*). I'd refuse a prefix under 3 characters with a message saying why, from parse_list, so the CLI, serve and MCP all show it. win* is 3, so the README's example still works.
t* hit 96 of 502 words on a test transcript, so every window reached the keyword cap and every clip said it. The CLI, serve and MCP all show the error.
|
Fixed in 8969e5b.
Full suite: 786 passed, ruff and mypy clean. |
A21-devs
left a comment
There was a problem hiding this comment.
Second pass on 8969e5b. The short-prefix finding is fixed for all three entry points: the CLI returns the message with exit 2, and parse_job gives a 400 (covered by the two new table rows). Since the type check now runs before the try, a non-string list item still gets keywords must be ... and not a re-labelled error. That case is still covered by the ["clutch", 3] row, which passes.
A tradeoff to know about rather than a bug: the limit counts characters, so a real two-letter stem like go* (goes, going) is now refused. I think that's the right default given t*/th*, and goi*/goes written out still work.
| else: | ||
| raise BadRequest("keywords must be a comma separated string or a list of strings") | ||
| try: | ||
| phrases = keywords.parse_list(items) |
There was a problem hiding this comment.
The 500-character size check now runs after parse_list, so an oversized string that also has t* in it reports the prefix error first. The order was the same before this PR (parse, then size), and parsing 500-ish characters is cheap, so this is just a note. Nothing to change.
Closes #123
--keywords winonly matched the word "win", so "wins" and "winning" were missed and the log just said"win" 0x. This adds an opt-in prefix match: a keyword word ending in*matches any transcript word that starts with the rest of it.How:
keywords.keyword_tokens()splits a keyword the same waytokens()does, but keeps a*that directly follows a word.parse/parse_listuse it, so the CLI,serveand the MCP tool all get it.find()compares each phrase word with_matches():startswithfor a starred word,==otherwise. The phrase keeps its*, so the log and the reasons show"win*"the way it was typed.win**iswin*;*on its own (or*, **) has no words, so it's dropped and the usual "needs at least one word" error applies instead of matching everything;*winiswin;wi*nsplits intowi nthe same way any other symbol inside a word would. Transcript text is still tokenized withtokens(), so stars whisper writes (f***ing) aren't treated as wildcards.--keywordshelp mention it.Irregular forms ("won") are still out of scope.
Testing
uv run ruff check src tests,uv run mypy,uv run pytest -q: 780 passed.test_keywords.py:winvswin*on win/wins/Winning!/window/won, a star at the end and in the middle of a phrase (no way*,no* way), parsing ofWIN**,let's*,no-scope*,wi*n,*win, lone stars, and the transcript side ignoring stars.-n 2:--keywords "jump, no way*": log"jump" 3x, "no way*" 3x, clips 101-156s and 174-194s--keywords "jump*, no way*": log"jump*" 6x, "no way*" 3x(the extra three are "jumping"), clip 2 moved to 169-224s to take in more of them, and the reasons readsaid "no way*", "jump*"