@seanmozeik/yake-ts
v0.1.0
Published
Fast, dependency-free YAKE keyword extraction for TypeScript
Maintainers
Readme
@seanmozeik/yake-ts
Fast, dependency-free keyword extraction for TypeScript, based on YAKE's unsupervised single-document method. It uses only standard JavaScript in the emitted library and runs in Bun, Deno, browsers, Node, and edge runtimes.
Install
bun add @seanmozeik/yake-tsimport { extractKeywords } from '@seanmozeik/yake-ts';
const keywords = extractKeywords(document, { language: 'en', maxNgramSize: 3, top: 10 });Each result has { keyword, score }. Lower scores are stronger. Results sort by score, then by first candidate appearance when scores tie, so repeated calls are deterministic.
Options
languageselects a bundled stop-word pack and defaults toen.maxNgramSizebounds generated phrases from 1 through 10 tokens and defaults to 3.windowSizecontrols the previous-token context radius from 1 through 10 and defaults to 1.topbounds results from 1 through 1,000 and defaults to 20.deduplicationThresholdis from 0 through 1 and defaults to 0.9. A lower-ranked phrase is removed when its character-bigram similarity to an accepted phrase is greater than the threshold.1disables suppression.stopWordsaccepts a readonly array or set. It replaces, rather than extends, the selected language pack for that call. Matching is case-insensitive.
Every option is validated before extraction. Empty or punctuation-only strings return an empty array.
Languages
The package adapts all useful stop-word packs shipped by the pinned upstream YAKE source:
ar, bg, br, cz, da, de, el, en, es, et, fa, fi, fr, hi, hr, hu, hy, id, it, ja, lt, lv, nl, no, pl, pt, ro, ru, sk, sl, sv, tr, uk, and zh.
Tokenization is Unicode-aware and treats punctuation as a phrase boundary. CJK characters are scanned as compact tokens so unspaced Chinese and Japanese text can form phrases without inserted spaces. The implementation intentionally follows the YAKE paper's statistical intent rather than Python tokenization or floating-point quirks.
Development
Use Bun 1.4 or newer:
bun install
bun run verify
bun run benchverify never rewrites source files; it recreates only the ignored dist build output. Its Bun consumer resolves the package root through the export map and typechecks the emitted declarations; the Deno consumer checks and runs the same browser artifact. The benchmark uses diverse deterministic short, medium, and long corpora, rejects invalid or nondeterministic output, and reports raw samples, latency statistics, throughput, and machine metadata. See benchmarks/README.md.
Method and license
YAKE combines document-local frequency, casing, first position, sentence dispersion, and directed context statistics. Candidate n-grams combine their constituent term scores and use contextual weights for internal stop words. No model, dictionary, native binding, runtime dependency, or external corpus is used.
This package is licensed under AGPL-3.0-or-later. See THIRD_PARTY_NOTICES.md for the pinned YAKE source, modification notice, and citation.
Corresponding source
The complete source for every npm release is available from the matching public Git tag at github.com/seanmozeik/yake-ts. The source for npm version 0.1.0 is tag v0.1.0. It includes the TypeScript source, tests, build scripts, configuration, and lockfile needed to rebuild the package.
The npm package contains the compiled library and legal notices. GitHub is the designated no-charge source location for AGPL section 6(d).
