match

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: BSD-3-Clause Imports: 2 Imported by: 2

README

match

A simple fuzzy matcher. Inspired by closestmatch.

godoc

Documentation

Overview

Package match provides a fuzzy matcher for strings.

Example
matcher := New([]string{"Golang", "Python", "C"}, 1, 2)

for _, s := range []string{"go", "py", "c"} {
	fmt.Println(matcher.Closest(s))
}
Output:


Golang
Python
C

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ngrams

func Ngrams(s string, n int) []string

Ngrams generates grams of len n from s, normalized (lowercase, no whitespace).

Types

type Bag

type Bag struct {
	N     int
	Grams []string

	// Grams index to Words index
	GramsToWords [][]int
}

Bag is a collection of Grams of len N.

type Match

type Match struct {
	Word  string
	Score int
}

Match is a potential match, and its score.

type Matches

type Matches []Match

Matches is a slice of Match, and satisfies sort.Interface.

func (Matches) Len

func (m Matches) Len() int

func (Matches) Less

func (m Matches) Less(i, j int) bool

func (Matches) Swap

func (m Matches) Swap(i, j int)

type Model

type Model struct {
	Words []string
	Bags  []Bag
}

Model is a collection of Words and Bags.

func New

func New(words []string, bags ...int) *Model

New returns an instance of Model. If bags isn't passed, you need to call model.Bag(bags) yourself.

func (*Model) Bag

func (m *Model) Bag(N ...int) *Model

Bag adds a bag of grams of len n to the Model. Pass multiple ints for multiple bags.

func (*Model) Closest

func (m *Model) Closest(s string) string

Closest returns the closest match to s, or an empty string if none.

func (*Model) Matches

func (m *Model) Matches(s string) (a Matches)

Matches returns all the matches for s, sorted by score (descending).

Jump to

Keyboard shortcuts

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