jpoehnelt / related-documents

Find and rank text documents by similarity.

Home Page:https://jpoehnelt.github.io/related-documents

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

related-documents

npm Build Release Docs

Description

Rank text documents by similarity.

Install

Install using NPM or similar.

npm i related-documents

Usage

import { Related } from "related-documents";

const documents = [
  { title: "ruby", text: "this lorem ipsum blah foo" },
  { title: "ruby", text: "this document is about python." },
  { title: "ruby and node", text: "this document is about ruby and node." },
  {
    title: "examples",
    text: "this document is about node. it has node examples",
  },
];

// The serializer array length must match that of the weights array.
// This example applies a weight of 10 to the title and 1 to the text.
const options = {
  serializer: (document: any) => [document.title, document.text],
  weights: [10, 1],
};

const related = new Related(documents, options);

// Find documents related to document[0]
related.rank(documents[0]);

See the reference documentation.

About

Find and rank text documents by similarity.

https://jpoehnelt.github.io/related-documents

License:Apache License 2.0


Languages

Language:TypeScript 92.4%Language:JavaScript 7.6%