approx

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2018 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

approx is a package for approximate string matching. It will extract strings withing a given edit distance and return their start, end, and distance.

Index

Constants

View Source
const MaxInt = int(^uint(0) >> 1)

Variables

This section is empty.

Functions

func LogMatrix

func LogMatrix(pattern []rune, text []rune, matrix [][]int)

LogMatrix writes a visual representation of the given matrix for the given strings to os.Stderr. This function is deprecated, use WriteMatrix(pattern, text, matrix, os.Stderr) instead.

func WriteMatrix

func WriteMatrix(pattern []rune, text []rune, matrix [][]int, writer io.Writer)

WriteMatrix writes a visual representation of the given matrix for the given strings to the given writer.

Types

type Match

type Match struct {
	Start int
	End   int
	Dist  int
}

A match

func ApproxFind

func ApproxFind(pattern string, text string, maxE int, op Options) ([]Match, error)

ApproxFind uses a modified Levenshtein function to find a 'pattern' in a 'text'. It is not the most optimal way to do this for longer strings, thus it is recommend for use on short patterns only (to be defined lanter). If you are finding that it returns many options for a single pattern, ie find 'perl' in 'berd' with a max dist of 2, You should concider ammending the Options to make the version you don't want to see cost more.

type MatchFunction

type MatchFunction func(rune, rune) bool

type Options

type Options struct {
	InsCost int
	DelCost int
	SubCost int
	Matches MatchFunction
}
var DefaultOptions Options = Options{
	InsCost: 1,
	DelCost: 1,
	SubCost: 1,
	Matches: func(sourceCharacter rune, targetCharacter rune) bool {
		return sourceCharacter == targetCharacter
	},
}

DefaultOptions is the default options: insertion cost is 1, deletion cost is 1, substitution cost is 1, and two runes match iff they are the same.

Jump to

Keyboard shortcuts

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