3

related-documents

 2 years ago
source link: https://www.npmjs.com/package/related-documents
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

related-documents

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 Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK