spell

package
v0.0.0-...-36cd861 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMinSpanningLen = 3.0
	DefaultIndexSplitLen  = 5
	DefaultMinTermLen     = 4
	DefaultMinTermCount   = 10
)

Variables

View Source
var CheckOperationWeight = append([]OperationWeight{{
	0,
	0.8,
	[]int{1},
}}, OperationWeights...)
View Source
var OperationWeights = []OperationWeight{
	{
		1,
		0.8,
		[]int{0, -1},
	},
	{
		2,
		1.1,
		[]int{0},
	},
	{
		3,
		1.9,
		[]int{0},
	},
}

Functions

func GetEdits

func GetEdits(term string, usedWeight float64, maxWeight float64) map[string]float64

func GetMultiEdits

func GetMultiEdits(term string, usedWeight float64, maxWeight float64) map[string]float64

func GetTrackingEdits

func GetTrackingEdits(term string, usedAffectedChange OperationAffectedChange, maxWeight float64) map[string]*OperationAffectedChange

func GetTrackingMultiEdits

func GetTrackingMultiEdits(term string, usedAffectedChange OperationAffectedChange, maxWeight float64) map[string]*OperationAffectedChange

Types

type DistanceMeasurer

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

func NewDistanceMeasurer

func NewDistanceMeasurer() *DistanceMeasurer

func (*DistanceMeasurer) Distance

func (measurer *DistanceMeasurer) Distance(a, b string, calcEditorialPrescription bool) (distance int, editorialPrescription *EditorialPrescription)

type EditAction

type EditAction uint32
const (
	Insert        EditAction = 0
	Delete        EditAction = 1
	Replace       EditAction = 2
	Match         EditAction = 3
	Transposition EditAction = 4
	Duplicate     EditAction = 5
	MissDouble    EditAction = 6
	Triplet       EditAction = 7
)

type EditVariance

type EditVariance struct {
	MinTermLen    int
	PossibleEdits [][]EditAction
}

type EditorialPrescription

type EditorialPrescription struct {
	Froms   []rune
	Tos     []rune
	Actions []EditAction
}

func (*EditorialPrescription) Dump

func (prescription *EditorialPrescription) Dump()

type LearnProgressor

type LearnProgressor interface {
	LearnProgress() string
}

type Learner

type Learner interface {
	Learn(learningData []*LearningTerm) ScoreModel
}

type LearningTerm

type LearningTerm struct {
	Term        string
	Misspell    string
	Suggestions []Suggestion
}

type Misspell

type Misspell struct {
	Term      string
	Misspells []string
}

type MisspellParser

type MisspellParser struct {
}

func NewMisspellParser

func NewMisspellParser() *MisspellParser

func (*MisspellParser) Parse

func (parser *MisspellParser) Parse(reader io.Reader) ([]Misspell, error)

func (*MisspellParser) ParseFromFile

func (parser *MisspellParser) ParseFromFile(fileName string) ([]Misspell, error)

type Model

type Model struct {
	Terms     []string
	TermsDict map[string]int
	Index     map[string][][]int
	IndexTail map[string]map[string]bool

	Affects       [][][]int // inputlen -> edit len -> term lens
	KnownAffects  []bool
	Depth         int
	IndexSplitLen int

	TermsCounts []float64
	TotalTerms  float64
	// contains filtered or unexported fields
}

*

Model represents misspell corrector structure

func InitModel

func InitModel() *Model

func (*Model) AddTerm

func (model *Model) AddTerm(term string, count float64) bool

*

Add one term to the model

func (*Model) GetRawSuggestions

func (model *Model) GetRawSuggestions(input string, calcEditorialPrescription bool) map[string]Suggestion

*

Calculate raw unsorted suggestions

func (*Model) GetSuggestions

func (model *Model) GetSuggestions(input string, scoreModel ScoreModel, calcEditorialPrescription bool) []Suggestion

*

Return suggestions sorted by given scorer

func (*Model) HasTerm

func (model *Model) HasTerm(term string) bool

*

Has term been added to the model

func (*Model) InitMeasurers

func (model *Model) InitMeasurers()

func (*Model) TrainTerms

func (model *Model) TrainTerms(terms []string)

*

Directly add terms to the model

func (*Model) TrainText

func (model *Model) TrainText(text []byte)

*

Parse text, split it to terms and add them to the model

type OperationAffectedChange

type OperationAffectedChange struct {
	Weight    float64
	InputLens map[int]bool
}

type OperationWeight

type OperationWeight struct {
	AffectedLen  int
	Weight       float64
	MisspellLens []int
}

type ScoreModel

type ScoreModel interface {
	Score(a *Suggestion) float64
	Compare(a *Suggestion, b *Suggestion) float64
}

type Scorer

type Scorer interface {
	GetDifference(prescription *EditorialPrescription) float64
	Learn(learningData []LearningTerm)
}

type Suggestion

type Suggestion struct {
	Term         string
	Distance     int
	Score        float64
	Count        float64
	Prescription *EditorialPrescription
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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