npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

vsm-dictionary-local

v2.6.3

Published

Local (in-memory), full implementation of a VSM-dictionary

Downloads

46

Readme

vsm-dictionary-local

Summary

vsm-dictionary-local is a full, local (=in-memory) implementation of the 'VsmDictionary' parent-class/interface (from the package vsm-dictionary).

Background

  • VSM-sentences are built from terms that are linked to identifiers.
  • The 'vsm-dictionary' package defines a standardized interface, for VSM-related tools to communicate with services that provide terms+IDs (e.g. a webserver API).
  • That packages also includes the 'VsmDictionary' parent class that provides some shared functionality for concrete subclasses (like this package).

A local implementation of a VsmDictionary

This is VsmDictionaryLocal:

  • It extends the VsmDictionary parent class, and provides a concrete implementation that fully implements the vsm-dictionary specification.
    • i.e. it has the complete Create, Read, Update, Delete, search, sort, filter, etc. functionality for terms, subdictionary-info objects, etc.
  • It does not use an online server for data storage or lookup. Instead, it stores all data in-memory, as long as the application is running.

When to use VsmDictionaryLocal

Because of the above:

  • During the development of new tools that depend on a VsmDictionary, this module can be used as a fully functional placeholder that does not need an online server.
  • Or, it could provide mock terms+ids while running standalone demos of VSM-sentence building tools.
  • The many automated tests in VsmDictionaryLocal can give inspiration for testing future, webserver-connecting implementations.

Specification

Apart from following the parent class specification, VsmDictionaryLocal follows the additional the spec described in DictionaryLocal.spec.md.
(Note: we simply use the name 'DictionaryLocal' for VsmDictionaryLocal, in the spec & source code).

Installation

Node.js

npm install vsm-dictionary-local
const VsmDictionaryLocal = require('vsm-dictionary-local');

Browsers

<script src="https://unpkg.com/vsm-dictionary-local@^2.0.0/dist/vsm-dictionary-local.min.js"></script>

after which it is accessible as the global variable VsmDictionaryLocal.

Example use in Node.js

Example that (only):
 • adds one subdictionary (by adding a dictionary-info object),
 • adds entries to it (=concepts/IDs + terms),
 • string-searches for matching terms:

const VsmDictionaryLocal = require('vsm-dictionary-local');

var dict = new VsmDictionaryLocal();
var dictInfos = [ { id: 'DictID_12', name: 'Example subdictionary' } ];
var entries = [
  { id: 'URI:001', dictID: 'DictID_12', terms: [{str: 'aaa'}, {str: 'synonym'}] },
  { id: 'URI:002', dictID: 'DictID_12', terms: [{str: 'aab'}] },
  { id: 'URI:003', dictID: 'DictID_12', terms: [{str: 'abc'}], descr: 'description' }
];

dict.addDictInfos(dictInfos, (err) => {  // Add 1 subdictionary-info object.
  dict.addEntries(entries, (err) => {    // Add 3 entries.
    dict.getMatchesForString('ab', {}, (err, res) => {  // Query for string 'ab'.
      console.dir(res.items, { depth: 3 });
    });
  });
});

This gives the output:

[ { id: 'URI:003',         // Concept-ID.
    dictID: 'DictID_12',   // Dictionary-ID.
    descr: 'description',  // Description of the meaning of concept `URI:003`.
    terms: [ { str: 'abc' } ],  // Term-objects: one term as an unstyled string.
    str: 'abc',            // The term-string that this match pertains to.
    type: 'S' },           // Match type. Prefix(S)-matches come before infix(T).
  { id: 'URI:002',
    dictID: 'DictID_12',
    terms: [ { str: 'aab' } ],
    str: 'aab',
    type: 'T' } ]
const VsmDictionaryLocal = require('vsm-dictionary-local');

// Create.
var dict = new VsmDictionaryLocal({
  dictData: [
    { id: 'DictID_12',
      name: 'Example subdictionary',
      entries: [
        { id: 'URI:001', terms: [{str: 'aaa'}, {str: 'synonym'}] },
        { id: 'URI:002', terms: [{str: 'aab'}] },
        { id: 'URI:003', terms: [{str: 'abc'}], descr: 'description' }
      ]
    },
  ],
});

// Query.
dict.getMatchesForString('ab', {}, (err, res) => {
  console.dir(res.items, {depth: 3});
});

which gives the same output.

Tests

Run npm test, which runs tests with Mocha.
Run npm run testw, which automatically reruns tests when any file changes.

Demo in Node.js

More examples are included in demoInNode.js (based on demoData.js).
Run it with: node demo/demoInNode.js.

Interactive demo in the browser

Run npm run demo to start an interactive demo of (only) the string-search functionality, based on example data.
This opens a browser page with an input-field to search on demoData.js.

The demo works by making a Webpack dev-server bundle all source code (VsmDictionaryLocal and its dependencies) and serve it to the browser.
This is useful during development, to see immediate effects of changes to the source code (excl. the demo code).

(For normal use in browsers, just include the browser-build via a <script>-tag, see above).

License

This project is licensed under the AGPL license - see LICENSE.md.