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 🙏

© 2024 – Pkg Stats / Ryan Hefner

jaccard-index

v0.2.0

Published

Promise-based Jaccard similarity coefficient index calculation framework

Downloads

111

Readme

jaccard-index

Promise-based Jaccard similarity coefficient index calculation framework

npm version Build Status

FEATURES

  • Fast Jaccard index calculation framework for collaborative filtering
  • Promise-based asynchronous data source loading
  • Built-in on-memory cache mechanism with automatic expiration
  • Concurrency throttle for huge data sets
  • Both directional and no-directional graph links

SYNOPSIS

var Jaccard = require("jaccard-index");

var logs = {
  "item1": ["user1", "user2"],
  "item2": ["user2", "user3", "user4"],
  "item3": ["user1", "user2", "user5"]
};

var items = Object.keys(logs); // item1, item2, item3

var options = {
  getLog: getLog
};

Jaccard(options).getLinks(items).then(showResult).catch(console.warn);

function getLog(item) {
  return Promise.resolve(logs[item]); // async loading
  // return logs[item]; // sync loading
}

function showResult(links) {
  console.log(JSON.stringify(links, null, 2));
  process.exit(0);
}

Result:

[
  {"source": "item1", "target": "item2", "value": 0.25},
  {"source": "item1", "target": "item3", "value": 0.6666666666666666},
  {"source": "item2", "target": "item3", "value": 0.2}
]

Async Loading:

getLog() method could return a Promise.

var fs = require("fs");

function getLog(item) {
  return new Promise(function(resolve, reject) {
    var file = "test/example/" + item + ".txt";
    fs.readFile(file, "utf-8", function(err, text) {
      if (err) return reject(err);
      var list = text.split("\n").filter(function(v) {
        return !!v;
      });
      return resolve(list);
    });
  });
}

Jaccard Index:

index() method accepts a pair of Arrays and returns a Jaccard index.

var Jaccard = require("jaccard-index");
var jaccard = Jaccard();

var item1 = ["user1", "user2"];
var item2 = ["user2", "user3", "user4"];
var index = jaccard.index(item1, item2);

console.log(index); // => 0.25

CLI

$ npm install jaccard-index
$ PATH=./node_modules/.bin:$PATH
$ head node_modules/jaccard-index/test/example/*.txt
$ jaccard-index --csv node_modules/jaccard-index/test/example/*.txt

SEE ALSO

JSDoc

NPM

GitHub

Tests

LICENSE

MIT License

Copyright (c) 2016 Yusuke Kawasaki

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.