stringmetric

package
v1.101.15 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package stringmetric provides functions to calculate string metrics, also known as string similarity metrics or string distance functions.

A string metric measures the distance ("inverse similarity") between two text strings for approximate string matching, comparison, and fuzzy string searching.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DLDistance

func DLDistance(sa, sb string) int

DLDistance calculates the Damerau-Levenshtein edit distance between two strings. It provides the distance between two strings as the minimum number of operations required to change one string into the other. The operations include insertions, deletions, substitutions, and transpositions of two adjacent characters.

Ref.: https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance

Example
package main

import (
	"fmt"

	"github.com/Vonage/gosrvlib/pkg/stringmetric"
)

func main() {
	d := stringmetric.DLDistance("a cat", "a abct")

	// "a cat" (one transposition)-> "a act" (one insertion)-> "a abct"

	fmt.Println(d)

}
Output:

2

Types

This section is empty.

Jump to

Keyboard shortcuts

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