Skip to content

provides functions for comparing and calculating the similarity between two strings using various methods.

License

Notifications You must be signed in to change notification settings

hidden-finder/didyoumean

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Sep 23, 2023
ae01e07 · Sep 23, 2023

History

4 Commits
Sep 23, 2023
Sep 23, 2023
Sep 23, 2023
Sep 23, 2023
Sep 22, 2023
Sep 23, 2023
Sep 23, 2023
Sep 23, 2023
Sep 23, 2023
Sep 23, 2023

Repository files navigation

@hidden-finder/didyoumean

Introduction

This library provides functions for comparing and calculating the similarity between two strings using various methods. It includes the following functions:

  • calculateDistance: Calculates the edit distance (Levenshtein distance) between two strings.
  • levenshteinSimilarity: Calculates the Levenshtein similarity between two strings.
  • bigramSimilarity: Calculates the bigram similarity between two strings.
  • similarity: Calculates a combined similarity score using Levenshtein and bigram similarities.
  • didyoumean: Finds the most similar pattern from an array of patterns to a given input string.

Installation

To use this library in your project, you can install it via:

npm install @hidden-finder/didyoumean

yarn add @hidden-finder/didyoumean

Overview

import { calculateDistance, levenshteinSimilarity, bigramSimilarity, similarity, didyoumean } from '@hidden-finder/didyoumean'

Functions

calculateDistance

Parameters:

  • text (string): The first input string.
  • pattern (string): The second input string.

Returns: number - The edit distance between the two strings.

Example:

const distance = calculateDistance('kitten', 'sitting')

levenshteinSimilarity

Parameters:

  • text (string): The first input string.
  • pattern (string): The second input string.

Returns: number - The Levenshtein similarity between the two strings (a value between 0 and 1).

Example:

const similarity = levenshteinSimilarity('kitten', 'sitting')

bigramSimilarity

Parameters:

  • text (string): The first input string.
  • pattern (string): The second input string.

Returns: number - The bigram similarity between the two strings (a value between 0 and 1).

Example:

const similarity = bigramSimilarity('kitten', 'sitting')

similarity

Parameters:

  • text (string): The first input string.
  • pattern (string): The second input string.

Returns: number - The combined similarity score between the two strings (a value between 0 and 1).

Example:

const similarity = similarity('kitten', 'sitting')

didyoumean

Parameters:

  • text (string): The input string to find a similar pattern for.
  • patterns (string[]): An array of candidate patterns.

Returns: string - The most similar pattern from the array.

Example:

const patterns = ['banana', 'apple', 'cherry', 'grape']
const similarPattern = didyoumean('aple', patterns)

License

This library is provided under the MIT License

About

provides functions for comparing and calculating the similarity between two strings using various methods.

Topics

Resources

License

Stars

Watchers

Forks