Skip to content

Latest commit

 

History

History
92 lines (82 loc) · 1.61 KB

README.md

File metadata and controls

92 lines (82 loc) · 1.61 KB

gofuzzyset

A go implementation of the Javascript fuzzyset library, which is itself a port from a python library.

There is EXCELLENT documentation by the author of the Javascript library here.

Usage

The usage is simple. Just initialize a new fuzzyset, and ask for matches by using .Get:

package main

import (
	"github.com/samprakos/gofuzzyset"
	"log"
)

func main() {
	lowerGramSize := 2
	upperGramSize := 3
	minScore := 0.33

	data := []string{
		"Alabama",
		"Alaska",
		"Arizona",
		"Arkansas",
		"California",
		"Colorado",
		"Connecticut",
		"Delaware",
		"Florida",
		"Georgia",
		"Hawaii",
		"Idaho",
		"Illinois",
		"Indiana",
		"Iowa",
		"Kansas",
		"Kentucky",
		"Louisiana",
		"Maine",
		"Maryland",
		"Massachusetts",
		"Michigan",
		"Minnesota",
		"Mississippi",
		"Missouri",
		"Montana",
		"Nebraska",
		"Nevada",
		"New Hampshire",
		"New Jersey",
		"New Mexico",
		"New York",
		"North Carolina",
		"North Dakota",
		"Ohio",
		"Oklahoma",
		"Oregon",
		"Pennsylvania",
		"Rhode Island",
		"South Carolina",
		"South Dakota",
		"Tennessee",
		"Texas",
		"Utah",
		"Vermont",
		"Virginia",
		"Washington",
		"West Virginia",
		"Wisconsin",
		"Wyoming",
	}

	f := gofuzzyset.New(data, false, lowerGramSize, upperGramSize, minScore)

	results := f.Get("mossisippi")

	log.Printf("%v results found", len(results))
}

The result will []Match. The score is between 0 and 1, with 1 being a perfect match.

type Match struct {
	Word string
	Score float64
}