lev

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2021 License: MIT Imports: 2 Imported by: 8

README

Levenshtein-Distance

Calculate the levenshtein-distance between strings.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlignTrace added in v1.2.0

func AlignTrace(s1, s2 string, trace []byte) ([]rune, []rune)

AlignTrace aligns the two strings to the given trace. The resulting strings have then the same length as the given trace (counting unicode points).

func AlignTraceR added in v1.4.0

func AlignTraceR(s1, s2 []rune, trace []byte) ([]rune, []rune)

AlignTraceR aligns the two strings to the given trace. The resulting strings have then the same length as the given trace (counting unicode points).

func Distance

func Distance(s1, s2 string) int

Distance calculates the levenshtein distance between s1 and s2. Reference: [Levenshtein Distance](http://en.wikipedia.org/wiki/Levenshtein_distance).

Types

type Mat added in v1.1.0

type Mat struct {
	// contains filtered or unexported fields
}

Mat holds the matrix for the levenshtein distance calculation.

func (*Mat) Distance added in v1.1.0

func (m *Mat) Distance(s1, s2 string) int

Distance returns the Levenshtein-distance between two string.

func (*Mat) DistanceR added in v1.3.0

func (m *Mat) DistanceR(s1, s2 []rune) int

Distance returns the Levenshtein-distance between the two strings s1 and s2. Reference: [Levenshtein Distance](http://en.wikipedia.org/wiki/Levenshtein_distance).

func (*Mat) Trace added in v1.1.0

func (m *Mat) Trace(s1, s2 string) []byte

Trace returns the trace for two strings.

func (*Mat) TraceR added in v1.3.0

func (m *Mat) TraceR(s1, s2 []rune) []byte

Trace returns the trace that describes how to transform s1 into s2. The trace contains the chars #, ~, + meaning a substitution, an deletion or an insertion respectively. The function must be called after a call to Distance with the same string arguments.

type WMat added in v1.5.0

type WMat struct {
	// contains filtered or unexported fields
}

WMat represents the weighted matrix.

func NewWMat added in v1.5.0

func NewWMat(weights WeightFunc) *WMat

NewWMat creates a new weighted matrix with the given weight function.

func (*WMat) Distance added in v1.5.0

func (m *WMat) Distance(s1, s2 string) float64

Distance returns the weighted distance between s1 and s2.

func (*WMat) DistanceR added in v1.5.0

func (m *WMat) DistanceR(s1, s2 []rune) float64

DistanceR returns the weighted distance between s1 and s2.

The function considers all possible patterns of length 2, 1 and 0.

type WeightFunc added in v1.5.0

type WeightFunc func([]rune, []rune) (float64, bool)

WeightFunction that is used to determine the weight of patterns. The function should return the weight and true for a known pattern or 0 and false for unknown patterns.

Jump to

Keyboard shortcuts

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