Documentation
¶
Overview ¶
Package similarity provides a SequenceMatcher implementation equivalent to Python's difflib.SequenceMatcher for computing string similarity ratios.
Index ¶
- func SetRatio(a, b []string) float64
- func StringRatio(a, b string) float64
- type Match
- type OpCode
- type SequenceMatcher
- func (sm *SequenceMatcher) GetMatchingBlocks() []Match
- func (sm *SequenceMatcher) GetOpcodes() []OpCode
- func (sm *SequenceMatcher) QuickRatio() float64
- func (sm *SequenceMatcher) Ratio() float64
- func (sm *SequenceMatcher) SetA(a string)
- func (sm *SequenceMatcher) SetB(b string)
- func (sm *SequenceMatcher) SetSeqs(a, b string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetRatio ¶
SetRatio computes the similarity ratio between two string sets using intersection/union (Jaccard similarity).
func StringRatio ¶
StringRatio is a convenience function that returns the similarity ratio between two strings.
Types ¶
type Match ¶
type Match struct {
A int // position in sequence a
B int // position in sequence b
Size int // length of match
}
Match represents a matching block between two sequences.
type OpCode ¶
type OpCode struct {
Tag byte // 'e' equal, 'r' replace, 'i' insert, 'd' delete
I1 int
I2 int
J1 int
J2 int
}
OpCode represents a single edit operation.
type SequenceMatcher ¶
type SequenceMatcher struct {
// contains filtered or unexported fields
}
SequenceMatcher compares two sequences and finds the longest common subsequences. It is a Go port of Python's difflib.SequenceMatcher.
func NewSequenceMatcher ¶
func NewSequenceMatcher(a, b string) *SequenceMatcher
NewSequenceMatcher creates a new SequenceMatcher for the given sequences.
func (*SequenceMatcher) GetMatchingBlocks ¶
func (sm *SequenceMatcher) GetMatchingBlocks() []Match
GetMatchingBlocks returns a list of matching blocks. The last block is a sentinel (len(a), len(b), 0).
func (*SequenceMatcher) GetOpcodes ¶
func (sm *SequenceMatcher) GetOpcodes() []OpCode
GetOpcodes returns a list of 5-tuples describing how to turn a into b.
func (*SequenceMatcher) QuickRatio ¶
func (sm *SequenceMatcher) QuickRatio() float64
QuickRatio returns an upper bound on Ratio() relatively quickly.
func (*SequenceMatcher) Ratio ¶
func (sm *SequenceMatcher) Ratio() float64
Ratio returns a float in [0, 1] measuring similarity. 2.0 * M / T where M = matching characters, T = total characters in both.
func (*SequenceMatcher) SetB ¶
func (sm *SequenceMatcher) SetB(b string)
SetB replaces sequence b and reindexes.
func (*SequenceMatcher) SetSeqs ¶
func (sm *SequenceMatcher) SetSeqs(a, b string)
SetSeqs replaces both sequences and resets caches.