Draft: builtins: Add Z6832 find-lexemes-by-lemma
Adds the built-in find lexemes by lemma (Z6832, implementation Z6932)
that takes a lemma string (Z6) and a natural language (Z60) and returns
a list of Wikidata lexeme references (Z6095). Reverse of the existing
Z6830 ("find lexemes for a Wikidata item"), backing the CirrusSearch
haslemma: keyword (productionised via T271776) as a first-class
Wikifunctions primitive.
Motivating use case: pure-composition Wikifunctions functions that need
to go from a string to a Wikidata lexeme. E.g. Z26184 (solfege to
sargam), whose current code implementation Z29517 uses a hardcoded
Python dict mapping each solfège syllable to a sense ID. With this
primitive in place that function becomes a pure composition and new
solfège variants become Wikidata-side edits rather than code changes.
What this MR contains
-
src/fetchObject.js— newfindLexemesByLemma,
findLexemesByLemmaQuery,fetchLexemesByLemma(s), and
keyForWikidataLemmaSearchIDmethods onReferenceResolver,
parallel to the Z6830 path. Shares theWIKIDATA_SEARCHcache
namespace via anL:-prefixed key to keep lemma and statement
lookups disjoint. -
src/builtins.js(v1) —BUILTIN_FIND_LEXEMES_BY_LEMMA_handler;
registered inbuiltinFunctionsand added toimplementationZIDs
/functionZIDs. -
src/transpilation/builtins.js(v2) —builtinFindLexemesByLemma
handler. Note: usesgetNestedValueOrThrow(Z6, ['Z6K1'], ...), not
realizeStringMemberOrThrow, because the latter assumes the
two-level nesting of Z6091/Z6092-style wrappers and throws Z516 on
a bare Z6 argument. Worth flagging as a subtle pitfall for anyone
adding bare-Z6 builtins in future. -
test/utils/mockUtils.js— extendsWikidataQueryStubwith
lemma-keyed set/has/get helpers, and extendsmockWikidataActionAPI
to dispatchhaslemma:"<lemma>"searches alongside the existing
haswbstatement:pattern. - Tests: 5 new unit tests in
test/src/fetchObjectTest.js, 4 new v1
end-to-end tests in
test/features/v1/mockedServicesOrchestrateTest/wikidataTests.js,
and 2 new v2 tests intest/src/transpilation/wikidataTests.js,
all paralleling the existing Z6830 suite. Plus a
Z6832_Z500_expected.jsonfixture for the 404 case. - Bump of
function-schematasubmodule to pick up the matching
Z6832 / Z6932 definition files.
Baseline 816 → 827 passing locally (11 new), 0 regressions, npm test
clean (includes lint under the zero-warning policy).
Why this is a Draft
Depends on the companion MR against function-schemata which adds the
Z6832 / Z6932 definition files:
function-schemata!339
This MR's submodule pointer currently references the HEAD of that
schemata branch on my fork (SHA 37f3909) so local tests see the new
definitions. CI in this repo will fail on the submodule clone because
that SHA isn't reachable from upstream function-schemata yet — once
!339 (merged) merges, I will re-point this submodule at the merged SHA and
mark Ready.
ZID allocation
Z6832 (function) and Z6932 (implementation) are picked as the next
unused slots after Z6830/Z6930 and Z6831/Z6931. Happy to reassign if
the team prefers a different range — see T423781 for the allocation
discussion.
Bug: T423781
(This was all done with Claude Code 4.7)