trigram

package
v0.0.0-...-8a12d84 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2023 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package trigram provides string indexing and matching.

Example
package main

import (
	"fmt"

	"dasa.cc/x/trigram"
)

func main() {
	terms := []string{"the quick", "red fox", "jumps over", "the lazy", "brown dog"}

	var gs trigram.Set
	gs.Index(terms...)

	var m []string
	var u []float64

	m, u = gs.Match("bog", 0.33) // mispelled "dog"
	for i, s := range m {
		fmt.Printf("%.2f: %q\n", u[i], s)
	}

	m, u = gs.Match("the", 0.33)
	for i, s := range m {
		fmt.Printf("%.2f: %q\n", u[i], s)
	}

}
Output:

0.50: "brown dog"
1.00: "the lazy"
1.00: "the quick"

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsSpaceDigitLetterToLower

func IsSpaceDigitLetterToLower(r rune) rune

IsSpaceDigitLetterToLower reports whether rune is a letter, digit, or space character as defined by Unicode's White Space property and maps rune to lower case.

func NoFields

func NoFields(rune) bool

NoFields always returns false; preserves white space in Parse results.

func Parse

func Parse(s string, mapping func(rune) rune, fields func(rune) bool) []string

Parse returns a slice of trigrams for s after modifying characters according to the mapping function followed by word splitting according to fields function.

Types

type Set

type Set struct {
	// Mapping function used when calling Parse
	// or defaults to IsSpaceDigitLetterToLower if not set.
	Mapping func(rune) rune

	// Fields function used when calling Parse
	// or defaults to unicode.IsSpace if not set.
	Fields func(rune) bool
	// contains filtered or unexported fields
}

Set indexer; zero value is valid.

func (*Set) Index

func (a *Set) Index(xs ...string)

Index parses and stores trigrams for each s in xs. Panics if nil.

func (Set) Match

func (a Set) Match(x string, min float64) ([]string, []float64)

Match indexed values for x that meet min threshold; returns matches and unit scores.

Jump to

Keyboard shortcuts

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