{"id":16533835,"url":"https://github.com/kchapelier/ngram-word-generator","last_synced_at":"2025-09-22T01:31:49.842Z","repository":{"id":57145641,"uuid":"65195286","full_name":"kchapelier/ngram-word-generator","owner":"kchapelier","description":"Word generation based on n-gram models, and a cli utility to generate said models.","archived":false,"fork":false,"pushed_at":"2016-09-01T19:51:37.000Z","size":20,"stargazers_count":17,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-08-28T09:13:28.152Z","etag":null,"topics":["javascript","ngrams","procedural-generation","text"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kchapelier.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-08T10:26:51.000Z","updated_at":"2024-12-24T02:17:42.000Z","dependencies_parsed_at":"2022-09-05T22:31:14.495Z","dependency_job_id":null,"html_url":"https://github.com/kchapelier/ngram-word-generator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/kchapelier/ngram-word-generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fngram-word-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fngram-word-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fngram-word-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fngram-word-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kchapelier","download_url":"https://codeload.github.com/kchapelier/ngram-word-generator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kchapelier%2Fngram-word-generator/sbom","scorecard":{"id":552818,"data":{"date":"2025-08-11","repo":{"name":"github.com/kchapelier/ngram-word-generator","commit":"0d013e8dab4fe6687214abf8590d7345ba925efe"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 0/17 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-20T11:22:31.972Z","repository_id":57145641,"created_at":"2025-08-20T11:22:31.972Z","updated_at":"2025-08-20T11:22:31.972Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276333879,"owners_count":25624045,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-21T02:00:07.055Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","ngrams","procedural-generation","text"],"created_at":"2024-10-11T18:15:58.747Z","updated_at":"2025-09-22T01:31:49.545Z","avatar_url":"https://github.com/kchapelier.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ngram-word-generator\n\nWord generation based on n-gram models, and a cli utility to generate said models.\n\nN-gram models (see on [wikipedia](https://en.wikipedia.org/wiki/N-gram)) are often used among other things to generate sentences and can produce satisfying results, though the inherent lack of context tracking and actual grammar checking is a severe shortcoming.\nWhen used as a word generator this simple algorithm really shines at producing new, imaginary words. For example here are few names generated based on French firstnames - *Mélaïde, Hadrigue, Laudence, Vestine, Pasien, Eulalisse* - and on Irish firstnames - *Ceallán, Muiríne, Toirdre, Finnbhach, Dáirtín, Éannailís*.\n\nA previous version of the project can be seen in use in [Stochastèmes](http://www.kchapelier.com/stochastemes/), a word generator based on poetic corpora.\n\n## Features\n\n - Works in node and in browsers\n - A cli utility to do the heavy-lifting of generating n-gram models from text files\n - The generated models are standard json files, optimized for web transfer\n - Porting the client code to other languages should be trivial, the generated n-gram models can thus be used virtually anywhere\n\n## Installing and testing\n\nWith [npm](http://npmjs.org) do:\n\n```\nnpm install ngram-word-generator\n```\n\nIt can also be installed globally to simplify the access to the cli utility:\n\n```\nnpm install ngram-word-generator -g\n```\n\n## Basic example\n\n```js\nvar makeGenerator = require('ngram-word-generator'),\n    ngramModel = require('./irish-firstnames.json'); //generated with the cli utility\n\nvar generator = makeGenerator(ngramModel);\n\nconsole.log(generator(10));\n```\n\n## Public API\n\n### makeGenerator(ngramModel)\n\nCreate a generator based on a given n-gram model.\n\n**Options**\n\n - *ngramModel :* An n-gram model as generated by the cli utility.\n\n### generator(lengthHint, rngFunction)\n\nGenerate a word based on the n-gram model.\n\n**Options**\n\n - *lengthHint :* Suggest the desired word length. The nature of the algorithm makes it impossible to ensure the exact length of the result (except through brute-force).\n - *rngFunction :* Random number generator function. Default to Math.random.\n\n### generator.dictionary(lengthMin, lengthMax)\n\nGenerate a comprehensive dictionary (list) of all the generated words included in the given length range.\n\n**Options**\n\n - *lengthMin :* Minimum length of the words included in the dictionary.\n - *lengthMax :* Maximum length of the words included in the dictionary. Default to lengthMin.\n\n## CLI\n\nThe cli utility is used to generate the n-gram models\n\n`ngram-word-generator source.txt \u003e model.json`\n\nIn Unix-like environment, the cli utility can also be piped into :\n\n`cat source.txt | ngram-word-generator \u003e model.json`\n\n### ngram-word-generator sourceFile [options]\n\n*sourceFile* must be an utf8 text file. No specific structure is required.\n\n**Options**\n\n - name: A name for the model, not directly used.\n - n: The order of the model (1: unigram, 2: bigram, 3: trigram, etc.). Default to 3.\n - minLength: The minimum length of the word considered in the generation of the model. Default to 4.\n - unique: Usually if multiple instances of a specific word is included in the source file, the model will be skewed toward generating similar words. Setting this option ensure this doesn't happen.\n - compress: Reduce the size of the model file, making it less readable and slightly less accurate.\n - excludeOriginal: The model will include the full list of the words included in the source file so that the generation can blacklist them.\n - filter: Character filtering option, either one the filters listed below or a regex. Default to 'extended'.\n\n**Filters**\n\n - none: All non-whitespace characters\n - alphabetical: A to Z\n - numerical: 0 to 9\n - alphaNumerical: A to Z and 0 to 9\n - extended: A to Z and éèëêęėēúüûùūçàáäâæãåāíïìîįīóöôòõœøōñńß\n - extendedNumerical: A to Z, 0 to 9 and éèëêęėēúüûùūçàáäâæãåāíïìîįīóöôòõœøōñńß\n - french: A to Z and éèëêúüûùœàáäâæíïìîóöôòç\n - english: A to Z and œæ\n - oldEnglish: A to Z and þðƿȝæœ\n - chinese: All the Chinese characters\n - japanese: All the Japanese (and Chinese) characters\n - noSymbols: Exclude all symbols and punctuation from Latin unicode blocks and specific punctuation, symbols and dingbats unicode blocks.\n\n**Full example**\n\n```\nngram-word-generator source.txt --n=3 --minLength=4 --filter=noSymbols --compress --unique --excludeOriginal \u003e model.json\n```\n\nWith a custom regular expressions as filter (all characters out of the A-U range will be filtered out) :\n\n```\nngram-word-generator source.txt --n=3 --minLength=4 --filter=/[^a-u]+/ig --compress --unique --excludeOriginal \u003e model.json\n```\n\n## Model generation without the CLI utility\n\nThe model generation being a costly process, it is recommended to use the cli utility described above.\n\n```js\nvar generateModel = require('ngram-word-generator/model-generation'); // specific entry point\n\nvar textData = ...; // retrieve a large text as a single string somehow\n\nvar ngramModel = generateModel(textData, {\n    name: 'My n-gram model',\n    filter: 'noSymbols',\n    n: 3,\n    minLength: 4,\n    unique: false,\n    excludeOriginal: true,\n    compress: true\n});\n\nconsole.log(ngramModel);\n\n// generate a word with the model\n\nvar makeGenerator = require('ngram-word-generator');\n\nvar generator = makeGenerator(ngramModel);\n\nconsole.log(generator(10));\n```\n\n### generateModel(textData, options)\n\nGenerate an n-gram model based on a given text.\n\n - *textData:* Text corpus as a single, preferably large, string.\n - *options.name:* Name of the n-gram model, not directly used.\n - *options.n:* Order of the model (1: unigram, 2: bigram, 3: trigram, ...). Default to 3.\n - *options.minLength:* Minimum length of the word considered in the generation of the model. Default to options.n. Must be larger than or equal to options.n, an error will be thrown otherwise.\n - *options.unique:* Avoid skewing the generation toward the most repeated words in the text corpus. Default to false.\n - *options.compress:* Reduce the size of the model file, making it slightly less accurate. Default to false.\n - *options.excludeOriginal:* Include the full list of the words considered in the generation so they can be blacklisted. Default to false.\n - *options.filter:* Character filtering option, either one the existing filters (see CLI) or a RegExp object. Default to 'extended'.\n\n## Changemap\n\n### [1.2.0](https://github.com/kchapelier/ngram-word-generator/tree/1.2.0) (2016-09-01) :\n\n * Allow and document how to generate n-gram models without the cli utility.\n\n### [1.1.0](https://github.com/kchapelier/ngram-word-generator/tree/1.1.0) (2016-08-19) :\n\n * Add built-in filters (french, english, oldEnglish, chinese, japanese and noSymbols).\n * Allow a custom regular expression as filter for the cli utility.\n * Add a dictionary method to generate a comprehensive list of words.\n\n### [1.0.0](https://github.com/kchapelier/ngram-word-generator/tree/1.0.0) (2016-08-12) :\n\n * First publication.\n\n## Roadmap\n\n - Fix issue where a model with exclude could lead to an infinite loop with a text corpus of poor quality\n - Make an online tool to generate the n-gram models\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkchapelier%2Fngram-word-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkchapelier%2Fngram-word-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkchapelier%2Fngram-word-generator/lists"}