fuzzy

package
v0.72.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package fuzzy provides fuzzy matching of scientific names, shared by gnmatcher and gndb, so they make exactly the same decisions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EditDistance

func EditDistance(s1, s2 string, relax bool) int

EditDistance calculates edit distance (**ed**) according to Levenshtein algorithm. It also runs additional checks and if they fail, returns -1.

Checks: - result should not exceed maxEditDistance - number of characters divided by ed should be bigger than charsPerED

It assumes that checks have to be applied only to the second string:

EditDistance("Pomatomus", "Pom atomus")

returns -1

EditDistance("Pom atomus", "Pomatomus")

returns 1

It also assumes that number os spaces between words was already normalized to 1 space, and that s1 and s2 always have the same number of words.

Types

type Trie

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

Trie finds strings that are close to a given string. It is a wrapper of levenshtein automata, gnmatcher and gndb build it from stemmed canonical forms.

func LoadTrie

func LoadTrie(r io.Reader) (*Trie, error)

LoadTrie restores a Trie saved by NewTrieWrite.

func NewTrie

func NewTrie(names []string) (*Trie, error)

NewTrie creates a Trie. The names must be unique and sorted by bytes.

func NewTrieWrite

func NewTrieWrite(names []string, w io.Writer) (*Trie, error)

NewTrieWrite creates a Trie and saves it to w, so LoadTrie can restore it later. The names must be unique and sorted by bytes.

func (*Trie) Matches

func (t *Trie) Matches(input string, maxEditDist int) []string

Matches returns names that are within maxEditDist of the input. The distance is computed without the checks of EditDistance, so callers have to run EditDistance on the results.

Jump to

Keyboard shortcuts

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