ld

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2024 License: MPL-2.0 Imports: 1 Imported by: 0

Documentation

Overview

package ld implements levenshtein distance in order to provide suggestions based on similarity.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Distance

func Distance(s, t string, ignoreCase bool) int

Distance compares two strings and returns the levenshtein distance between them.

func Suggestions

func Suggestions(input string, options []string, distanceCutoff int, ignoreCase bool) []string

Suggestions takes in an input and a set of valid options. It returns a set of suggested values based on the levenshtein distance between them. The distanceCutoff can be used to control the required similarity of the option to the input for it to be included in the suggestions.

func SuggestionsWithOverride

func SuggestionsWithOverride(input string, options []string, distanceCutoff int, ignoreCase bool, override func(input, option string) bool) []string

SuggestionsWithOverride is similar to Suggestions, except it takes an optional include function. If the distance is less than the cutoff, the passed override function will be invoked, and if it returns true, the option will be added to the suggestions list. This allows custom suggestion logic to be added.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL