{"id":25631571,"url":"https://github.com/wandalen/wvocabulary","last_synced_at":"2025-04-14T17:05:23.878Z","repository":{"id":48921716,"uuid":"135583714","full_name":"Wandalen/wVocabulary","owner":"Wandalen","description":"Vocabulary of phrases, primarily for CLI.","archived":false,"fork":false,"pushed_at":"2022-06-18T02:50:44.000Z","size":437,"stargazers_count":3,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T17:03:46.680Z","etag":null,"topics":["cli","vocabulary"],"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/Wandalen.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":"2018-05-31T12:56:09.000Z","updated_at":"2022-03-01T17:44:27.000Z","dependencies_parsed_at":"2022-09-13T05:12:20.218Z","dependency_job_id":null,"html_url":"https://github.com/Wandalen/wVocabulary","commit_stats":null,"previous_names":[],"tags_count":300,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wandalen%2FwVocabulary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wandalen%2FwVocabulary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wandalen%2FwVocabulary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Wandalen%2FwVocabulary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Wandalen","download_url":"https://codeload.github.com/Wandalen/wVocabulary/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248923767,"owners_count":21183953,"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","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":["cli","vocabulary"],"created_at":"2025-02-22T20:22:54.535Z","updated_at":"2025-04-14T17:05:23.851Z","avatar_url":"https://github.com/Wandalen.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# module::Vocabulary  [![status](https://github.com/Wandalen/wVocabulary/actions/workflows/StandardPublish.yml/badge.svg)](https://github.com/Wandalen/wVocabulary/actions/workflows/StandardPublish.yml) [![stable](https://img.shields.io/badge/stability-stable-brightgreen.svg)](https://github.com/emersion/stability-badges#stable)\n\nVocabulary of phrases, primarily for CLI. Implements class to operate phrases. Vocabulary enables the design of CLI based on phrases instead of words. Also, Vocabulary makes it possible to group phrases by similarity, powering partial match search.\n\n[Module::CommandsAggregator](https://github.com/Wandalen/wCommandsAggregator) uses the module to expose CLI for many utilities. Use it to make your CLI more user-friendly.\n\n### Try out from the repository\n\n```\ngit clone https://github.com/Wandalen/wVocabulary\ncd wVocabulary\nwill .npm.install\nnode sample/trivial/Sample.s\n```\n\nMake sure you have utility `willbe` installed. To install willbe: `npm i -g willbe@stable`. Willbe is required to build of the module.\n\n### To add to your project\n\n```\nnpm add 'wvocabulary@stable'\n```\n\n`Willbe` is not required to use the module in your project as submodule.\n\n### Concepts\n\n[Phrase](./doc/concept/All.md#phrase) - sequence of words. \\\n[Word](./doc/concept/All.md#word) - string which does not contain delimeter. \\\n[Delimeter](./doc/concept/All.md#delimeter) - by default, both dot `.` and space ` ` represents delimeter. \\\n[Subphrase](./doc/concept/All.md#subphrase) - phrase with sequence of words removed from it. \\\n[Vocabulary](./doc/concept/All.md#vocabulary) - collection of phrases and related data.\n\n\u003c!-- xxx : qqq : duplicate in doc/* and make links working --\u003e\n\n### Basics\n\nVocabulary collects a set of prases and satisfies search requests. A request could include all words the phrase consists of a subphrase.\n\n```js\nvar voc = new _.Vocabulary();\nvoc.phrasesAdd([ 'do this', 'do that', 'that is' ]);\n\nvar found = voc.withPhrase( 'do this' );\nconsole.log( found.phrase );\nconsole.log( found.words );\n\n/* optput:\ndo this\n[ 'do', 'this' ]\n*/\n```\nIn this example, vocabulary is created and filled with 3 phrases. Method `voc.withPhrase` returns phrase descriptor. The trivial version phrase descriptor has 2 fields: `phrase` and `words`. Field `words` is the array of words in the phrase. By default, vocabulary accepts both dot `.`  and space ` ` as delimiter between words.\n\n### Search by subphrase\n\nTo find phrases by subphrases use the method `withSubphrase`.\n\n```js\nvar voc = new _.Vocabulary();\nvoc.phrasesAdd([ 'do.this', 'do.that', 'that.is' ]);\n\nvar found = voc.withSubphrase( 'do' );\nconsole.log( found.map( ( e ) =\u003e e.phrase ) );\n/* optput:\n[ 'do.this', 'do.that' ]\n*/\n\nvar found = voc.withSubphrase( 'that' );\nconsole.log( found.map( ( e ) =\u003e e.phrase ) );\n/* optput:\n[ 'do.that', 'that.is' ]\n*/\n\nvar found = voc.withSubphrase( '' );\nconsole.log( found.map( ( e ) =\u003e e.phrase ) );\n/* optput:\n[ 'do.this', 'do.that', 'that.is' ]\n*/\n\nvar found = voc.withSubphrase( 'do.this' );\nconsole.log( found.map( ( e ) =\u003e e.phrase ) );\n/* optput:\n[ 'do.this' ]\n*/\n```\n\nA partial match of a phrase is enough to get in in the array `found`. If any subsequence of words match with the\n\n### Custom phrase descriptor\n\nTo use a custom phrase descriptor pass your implementation of routines `onPhraseDescriptorFrom` and `onPhraseDescriptorIs` to the constructor of the vocabulary.\n\n```js\nvar voc = new _.Vocabulary({ onPhraseDescriptorFrom, onPhraseDescriptorIs });\n\nvoc.phraseAdd( 'do this' );\nvoc.phraseAdd( 'do that' );\nvoc.phraseAdd( 'that is' );\n\nvar found = voc.withPhrase( 'do this' );\nconsole.log( found.phrase );\nconsole.log( found.words );\nconsole.log( found.type );\n\n/* optput:\ndo this\n[ 'do', 'this' ]\ncustom.phrase.descriptor\n*/\n\nfunction onPhraseDescriptorFrom( src, phrase )\n{\n  if( src.phrase )\n  src.phrase = this.phraseNormalize( src.phrase );\n  phrase = phrase || src.phrase || src;\n  if( _.strIs( src ) )\n  src = Object.create( null );\n  src.phrase = phrase;\n  src.type = 'custom.phrase.descriptor';\n  return src;\n}\n\nfunction onPhraseDescriptorIs( phraseDescriptor )\n{\n  return phraseDescriptor.type === 'custom.phrase.descriptor'\n}\n```\n\nCallback `onPhraseDescriptorFrom` accepts 2 arguments, argument phrase either null or phrase of the descriptor. Callback `onPhraseDescriptorIs` answer the question: \"is that phrase descriptor?\".\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwandalen%2Fwvocabulary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwandalen%2Fwvocabulary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwandalen%2Fwvocabulary/lists"}