Teach drag-lint Your Domain Words
Concept search in drag-lint is lexical, so a domain word like characteristic cannot find code that spells it Ftr, but one doc-comment line or one wiki topic with aliases fixes that, without AI. The question came from a user on a Delphi 5 code base.
Old code bases name things in the shorthand of whoever wrote them. Micronite, the quality and production-control software we build for manufacturers, has plenty: the business calls something a characteristic, the code says Ftr. A search for the business word finds nothing, and a search for the abbreviation only helps someone who already knows it. This article shows what drag-lint query --concept does with that gap, and the two ways to close it. Every output is from a small demo we built for this article.
Words, not meaning
query --concept "<words>" splits every identifier into words (SaveFtrGridLayout becomes save ftr grid layout) and also searches the /// doc-comment text. It ranks symbols that match. There are no embeddings and no model: a word either occurs in the identifier or the comment, or it does not. The last column of each hit says where the match came from: [tokens] (identifier words), [summary] or [remarks] (comment text).
Three units and a project
A .dpr and .dproj with three units. The relevant declarations:
unit FtrStore;
type
TFtrStore = class
function FtrNameString(pId: Integer): string;
procedure SaveFtrGridLayout(const pName: string);
end;
unit MscUtil;
type
TMscList = class
procedure MscListReload;
function MscCount: Integer;
end;
Indexed into a scratch database with drag-lint index --project Demo.dproj --db demo.sqlite (4 files, 15 symbols).
The domain word finds nothing
drag-lint query --concept characteristic --db demo.sqlite
concept "characteristic": 0 hit(s) (0 match every word)
The abbreviation works, because it is in the identifier:
drag-lint query --concept "ftr name" --db demo.sqlite
concept "ftr name": 4 hit(s) (1 match every word)
1 3.38 method FtrStore.TFtrStore.FtrNameString [tokens]
2 0.66 class FtrStore.TFtrStore [tokens]
3 0.64 unit FtrStore [tokens]
4 0.64 method FtrStore.TFtrStore.SaveFtrGridLayout [tokens]
Note the multi-word case. "characteristic name" does return a hit, but only because of the word name; the header says (0 match every word). Read that figure: it tells you the ranking is partial.
A /// summary on the key routine
Add one DocInsight line, in the words the business uses:
/// <summary>Persists the characteristic grid column layout under a name.</summary>
procedure SaveFtrGridLayout(const pName: string);
Re-index (incremental, 3 files skipped as up to date) and ask again:
drag-lint query --concept characteristic --db demo.sqlite
concept "characteristic": 1 hit(s) (1 match every word)
1 1.72 method FtrStore.TFtrStore.SaveFtrGridLayout [summary]
drag-lint query --concept "characteristic grid layout" --db demo.sqlite
1 6.97 method FtrStore.TFtrStore.SaveFtrGridLayout [tokens,summary]
The tag changed from [tokens] to [tokens,summary], and the single-word query that returned nothing now returns the routine. The limit is visible too: FtrNameString still does not answer to characteristic, because nobody wrote a summary on it. A summary helps exactly the symbol it sits on.
A wiki topic with aliases
When one idea spans several types, write it once as a dl:wiki topic. It lives in a /// comment, here above unit FtrStore; (the recommended place for a concept that several types share):
/// <remarks>
/// dl:wiki Characteristic
/// Aliases: characteristic, characteristics, the characteristic list, Ftr
/// SeeCode: TFtrStore, TFtrStore.FtrNameString, MscUtil.TMscList
/// Body:
/// A measured product property. The code abbreviates it Ftr.
/// </remarks>
unit FtrStore;
Rules from the authoring guide that bite in practice: /// comments only, no blank line between the comment and the declaration, 7-bit ASCII. Aliases are the phrases your team actually says, and matching is case-insensitive. SeeCode entries are checked: an entry that resolves to nothing fails the check. After re-indexing:
drag-lint wiki --check --db demo.sqlite
1 topic(s) checked, 0 problem(s). (exit 0)
drag-lint wiki --term "the characteristic list" --db demo.sqlite
== Characteristic ==
owner : FtrStore (unit)
source: ...\demo\FtrStore.pas:2
aliases: characteristic, characteristics, the characteristic list, Ftr
see: TFtrStore -> ...\FtrStore.pas:13
see: TFtrStore.FtrNameString -> ...\FtrStore.pas:15
see: MscUtil.TMscList -> ...\MscUtil.pas:6
A measured product property. The code abbreviates it Ftr.
1 match(es) of 1 topic(s).
The same answer came back for --term characteristic and --term characteristics. The topic also feeds concept search, since its text is part of the unit's remarks:
drag-lint query --concept characteristic --db demo.sqlite
1 1.95 unit FtrStore [summary,remarks]
2 1.48 method FtrStore.TFtrStore.SaveFtrGridLayout [summary]
And drag-lint context --task "modify FtrStore.TFtrStore.FtrNameString" now carries a ## Wiki section with the topic, its aliases and the see-code list, even though that routine has no comment of its own.
In this run, query --concept points at the owning unit, while wiki --term is the one that lists every participating symbol. Use wiki --term to route a business word to code, and concept search to explore.
A starter glossary
- List the ten to twenty words your business says that the code abbreviates (characteristic/Ftr, miscellaneous/Msc, and so on).
- For each, pick the unit where the concept's central type lives and add one
dl:wikiblock aboveunit X;with the aliases people say, including the abbreviation. - List the participating symbols under
SeeCodeso the topic goes stale loudly. - Re-index, then run
drag-lint wiki --check(must exit 0) anddrag-lint wiki --term "<alias>"for one alias of each topic. A block in a//comment, or separated from its declaration by a blank line, produces no error: it just does not exist, so ask for it back. - Add plain
///summaries on the few routines people look for by name.
Lexical on purpose
- No synonyms by itself. drag-lint will not guess that characteristic means
Ftr. You tell it, once, and the answer is the same every time and checkable bywiki --check. A model-based guess could be wrong in a way you cannot diff. - A summary covers one symbol. A topic covers a concept, but its aliases are only as good as the phrases you thought of.
- Body prose is not checked. Only
SeeCodeentries are resolved. - Plural handling was not measured. We listed
characteristicsas an alias rather than rely on stemming; we did not test whether concept search stems. - Where the authoring guide is. The guide is
docs\wiki\Wiki-Blocks-Authoring.mdin the repository and the GitHub wiki. The release zip and installer do not currently include it (a user on a Delphi 5 project found this); it is filed as a defect.