Giter Club home page Giter Club logo

related-documents's Introduction

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.

related-documents's People

Contributors

dependabot[bot] avatar jpoehnelt avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

related-documents's Issues

API Not Relevant (related-documents): serializer must return an array of strings

Environment details

Mac OS 11.4

Node v16.15.0

related-documents@npm:1.0.7

Steps to reproduce

  1. Follow README/instructions to Install and configure package
  2. Set up a simple serializer that returns an array of length 1
  3. Attempt to use rank
  4. Observe error

Code example

import { Related } from 'related-documents'

const results = [{
  description: 'Hi, this is a description.'
}, {
  description: 'Hi again! This is also a description.'
}, {
  description: 'Goodbye for now! This is yet another description.'
}]

const options = {
  serializer: (doc: any) => [doc.description],
  weights: [10],
}

const related = new Related(results, options)
const results = related.rank(results[1])

Stack trace

/node_modules/related-documents/dist/index.js:117
      throw new Error(
            ^

Error: serializer must return an array of strings:
    at Related.process (/Volumes/T7/repositories/GitStumble/node_modules/related-documents/dist/index.js:117:13)
    at null.<anonymous> (/Volumes/T7/repositories/GitStumble/node_modules/related-documents/dist/index.js:92:54)
    at Array.map (<anonymous>)
    at Related.prepare (/Volumes/T7/repositories/GitStumble/node_modules/related-documents/dist/index.js:92:35)
    at Related.rank (/Volumes/T7/repositories/GitStumble/node_modules/related-documents/dist/index.js:129:10)
    ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.