Socket
Book a DemoInstallSign in
Socket

query-text-match

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

query-text-match

Calculates the matching score between query and text

latest
Source
npmnpm
Version
0.2.7
Version published
Maintainers
1
Created
Source

Query Text Match

Calculates the matching score between query and text

Installation

yarn add query-text-match

Sample

const _ = require('lodash');
const queryTextMatch = require('./index');

const query = "because I can't you";

const texts = [
  'The stranger officiates the meal.',
  'When transplanting seedlings, candied teapots will make the task easier.',
  'His mind was blown that there was nothing in space except space itself.',
  "Please put on these earmuffs because I can't you hear.",
  'Flash photography is best used in full sunlight.',
  'It dawned on her that others could make her happier, but only she could make herself happy.',
  'He was the type of guy who liked Christmas lights on his house in the middle of July.',
  "Art doesn't have to be intentional.",
  'It was getting dark, and we weren’t there yet.',
  'He learned the important lesson that a picnic at the beach on a windy day is a bad idea.',
];

const results = texts.map((text) => ({ ...queryTextMatch(query, text), text }));

console.log(
  JSON.stringify(
    _.sortBy(results, [
      'unmatchedQueryWordsCount',
      'extraCharactersCount',
      'totalDistance',
    ]),
    null,
    2
  )
);

Outcome:

[
  {
    "matchedQueryWordsCount": 3,
    "unmatchedQueryWordsCount": 1,
    "queryWordsCount": 4,
    "totalDistance": 6,
    "extraCharactersCount": 0,
    "takenWords": [
      {
        "index": 29,
        "actualWord": "because",
        "extraPerfixLength": 0,
        "extraSufixLength": 0,
        "UnNormalizedQueryWord": "because",
        "normalizedQueryWord": "because",
        "extraCharsLength": 0,
        "taken": true,
        "surroundingDistance": 7
      },
      {
        "index": 37,
        "actualWord": "I",
        "extraPerfixLength": 0,
        "extraSufixLength": 0,
        "UnNormalizedQueryWord": "I",
        "normalizedQueryWord": "i",
        "extraCharsLength": 0,
        "taken": true,
        "surroundingDistance": 14
      },
      {
        "index": 45,
        "actualWord": "you",
        "extraPerfixLength": 0,
        "extraSufixLength": 0,
        "UnNormalizedQueryWord": "you",
        "normalizedQueryWord": "you",
        "extraCharsLength": 0,
        "taken": true,
        "surroundingDistance": 7
      }
    ],
    "queryNormalizedWordsList": [
      "because",
      "i",
      "cant",
      "you"
    ],
    "text": "Please put on these earmuffs because I can't you hear."
  },
  {
    "matchedQueryWordsCount": 1,
    "unmatchedQueryWordsCount": 3,
    "queryWordsCount": 4,
    "totalDistance": 0,
    "extraCharactersCount": 0,
    "takenWords": [
      {
        "index": 42,
        "actualWord": "i",
        "extraPerfixLength": 0,
        "extraSufixLength": 0,
        "UnNormalizedQueryWord": "i",
        "normalizedQueryWord": "i",
        "extraCharsLength": 0,
        "taken": true
      }
    ],
    "queryNormalizedWordsList": [
      "because",
      "i",
      "cant",
      "you"
    ],
    "text": "His mind was blown that there was nothing in space except space itself."
  },
  ...
]

FAQs

Package last updated on 12 Dec 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts