Skip to content

Commit 5f10fee

Browse files
committed
Minor code cleanup; updated docs and ci settings
1 parent ad4eb37 commit 5f10fee

File tree

3 files changed

+60
-53
lines changed

3 files changed

+60
-53
lines changed

.travis.yml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
language: go
2-
2+
sudo: false
33
go:
4+
- 1.8
45
- 1.7.5
56
- 1.7.4
67
- 1.7.3
78
- 1.7.2
89
- 1.7.1
910
- 1.7
11+
- tip
1012
- 1.6.4
1113
- 1.6.3
1214
- 1.6.2
1315
- 1.6.1
1416
- 1.6
15-
- tip
1617
- 1.5.4
1718
- 1.5.3
1819
- 1.5.2
@@ -32,15 +33,22 @@ go:
3233
- 1.1.2
3334
- 1.1.1
3435
- 1.1
35-
- 1.0.3
36-
- 1.0.2
37-
- 1.0.1
38-
- 1
39-
36+
before_install:
37+
- go get github.com/mattn/goveralls
38+
script:
39+
- $HOME/gopath/bin/goveralls -service=travis-ci
40+
notifications:
41+
email:
42+
on_success: never
4043
matrix:
4144
fast_finish: true
4245
allow_failures:
4346
- go: tip
47+
- go: 1.6.4
48+
- go: 1.6.3
49+
- go: 1.6.2
50+
- go: 1.6.1
51+
- go: 1.6
4452
- go: 1.5.4
4553
- go: 1.5.3
4654
- go: 1.5.2
@@ -60,7 +68,3 @@ matrix:
6068
- go: 1.1.2
6169
- go: 1.1.1
6270
- go: 1.1
63-
- go: 1.0.3
64-
- go: 1.0.2
65-
- go: 1.0.1
66-
- go: 1

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
# A Go package for calculating the Levenshtein distance between two strings
22

3-
This package implements distance and similarity metrics for strings, based on the Levenshtein measure, in [Go](http://golang.org).
3+
[![Release](https://img.shields.io/github/release/agext/levenshtein.svg?style=flat)](https://github.com/agext/levenshtein/releases/latest)
4+
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/agext/levenshtein) 
5+
[![Build Status](https://travis-ci.org/agext/levenshtein.svg?branch=master&style=flat)](https://travis-ci.org/agext/levenshtein)
6+
[![Coverage Status](https://coveralls.io/repos/github/agext/levenshtein/badge.svg?style=flat)](https://coveralls.io/github/agext/levenshtein)
7+
[![Go Report Card](https://goreportcard.com/badge/github.com/agext/levenshtein?style=flat)](https://goreportcard.com/report/github.com/agext/levenshtein)
8+
49

5-
## Maturity
10+
This package implements distance and similarity metrics for strings, based on the Levenshtein measure, in [Go](http://golang.org).
611

7-
[![Build Status](https://travis-ci.org/agext/levenshtein.svg?branch=master)](https://travis-ci.org/agext/levenshtein)
12+
## Project Status
813

9-
v1.2 Stable: Guaranteed no breaking changes to the API in future v1.x releases. No known bugs or performance issues. Probably safe to use in production, though provided on "AS IS" basis.
14+
v1.2.1 Stable: Guaranteed no breaking changes to the API in future v1.x releases. Probably safe to use in production, though provided on "AS IS" basis.
1015

1116
This package is being actively maintained. If you encounter any problems or have any suggestions for improvement, please [open an issue](https://github.com/agext/levenshtein/issues). Pull requests are welcome.
1217

1318
## Overview
1419

15-
[![GoDoc](https://godoc.org/github.com/agext/levenshtein?status.png)](https://godoc.org/github.com/agext/levenshtein)
16-
1720
The Levenshtein `Distance` between two strings is the minimum total cost of edits that would convert the first string into the second. The allowed edit operations are insertions, deletions, and substitutions, all at character (one UTF-8 code point) level. Each operation has a default cost of 1, but each can be assigned its own cost equal to or greater than 0.
1821

1922
A `Distance` of 0 means the two strings are identical, and the higher the value the more different the strings. Since in practice we are interested in finding if the two strings are "close enough", it often does not make sense to continue the calculation once the result is mathematically guaranteed to exceed a desired threshold. Providing this value to the `Distance` function allows it to take a shortcut and return a lower bound instead of an exact cost when the threshold is exceeded.

params.go

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,106 +47,106 @@ func NewParams() *Params {
4747

4848
// Clone returns a pointer to a copy of the receiver parameter set, or of a new
4949
// default parameter set if the receiver is nil.
50-
func (this *Params) Clone() *Params {
51-
if this == nil {
50+
func (p *Params) Clone() *Params {
51+
if p == nil {
5252
return NewParams()
5353
}
5454
return &Params{
55-
insCost: this.insCost,
56-
subCost: this.subCost,
57-
delCost: this.delCost,
58-
maxCost: this.maxCost,
59-
minScore: this.minScore,
60-
bonusPrefix: this.bonusPrefix,
61-
bonusScale: this.bonusScale,
62-
bonusThreshold: this.bonusThreshold,
55+
insCost: p.insCost,
56+
subCost: p.subCost,
57+
delCost: p.delCost,
58+
maxCost: p.maxCost,
59+
minScore: p.minScore,
60+
bonusPrefix: p.bonusPrefix,
61+
bonusScale: p.bonusScale,
62+
bonusThreshold: p.bonusThreshold,
6363
}
6464
}
6565

6666
// InsCost overrides the default value of 1 for the cost of insertion.
6767
// The new value must be zero or positive.
68-
func (this *Params) InsCost(v int) *Params {
68+
func (p *Params) InsCost(v int) *Params {
6969
if v >= 0 {
70-
this.insCost = v
70+
p.insCost = v
7171
}
72-
return this
72+
return p
7373
}
7474

7575
// SubCost overrides the default value of 1 for the cost of substitution.
7676
// The new value must be zero or positive.
77-
func (this *Params) SubCost(v int) *Params {
77+
func (p *Params) SubCost(v int) *Params {
7878
if v >= 0 {
79-
this.subCost = v
79+
p.subCost = v
8080
}
81-
return this
81+
return p
8282
}
8383

8484
// DelCost overrides the default value of 1 for the cost of deletion.
8585
// The new value must be zero or positive.
86-
func (this *Params) DelCost(v int) *Params {
86+
func (p *Params) DelCost(v int) *Params {
8787
if v >= 0 {
88-
this.delCost = v
88+
p.delCost = v
8989
}
90-
return this
90+
return p
9191
}
9292

9393
// MaxCost overrides the default value of 0 (meaning unlimited) for the maximum cost.
9494
// The calculation of Distance() stops when the result is guaranteed to exceed
9595
// this maximum, returning a lower-bound rather than exact value.
9696
// The new value must be zero or positive.
97-
func (this *Params) MaxCost(v int) *Params {
97+
func (p *Params) MaxCost(v int) *Params {
9898
if v >= 0 {
99-
this.maxCost = v
99+
p.maxCost = v
100100
}
101-
return this
101+
return p
102102
}
103103

104104
// MinScore overrides the default value of 0 for the minimum similarity score.
105105
// Scores below this threshold are returned as 0 by Similarity() and Match().
106106
// The new value must be zero or positive. Note that a minimum greater than 1
107107
// can never be satisfied, resulting in a score of 0 for any pair of strings.
108-
func (this *Params) MinScore(v float64) *Params {
108+
func (p *Params) MinScore(v float64) *Params {
109109
if v >= 0 {
110-
this.minScore = v
110+
p.minScore = v
111111
}
112-
return this
112+
return p
113113
}
114114

115115
// BonusPrefix overrides the default value for the maximum length of
116116
// common prefix to be considered for bonus by Match().
117117
// The new value must be zero or positive.
118-
func (this *Params) BonusPrefix(v int) *Params {
118+
func (p *Params) BonusPrefix(v int) *Params {
119119
if v >= 0 {
120-
this.bonusPrefix = v
120+
p.bonusPrefix = v
121121
}
122-
return this
122+
return p
123123
}
124124

125125
// BonusScale overrides the default value for the scaling factor used by Match()
126126
// in calculating the bonus.
127127
// The new value must be zero or positive. To guarantee that the similarity score
128128
// remains in the interval 0..1, this scaling factor is not allowed to exceed
129129
// 1 / BonusPrefix.
130-
func (this *Params) BonusScale(v float64) *Params {
130+
func (p *Params) BonusScale(v float64) *Params {
131131
if v >= 0 {
132-
this.bonusScale = v
132+
p.bonusScale = v
133133
}
134134

135135
// the bonus cannot exceed (1-sim), or the score may become greater than 1.
136-
if float64(this.bonusPrefix)*this.bonusScale > 1 {
137-
this.bonusScale = 1 / float64(this.bonusPrefix)
136+
if float64(p.bonusPrefix)*p.bonusScale > 1 {
137+
p.bonusScale = 1 / float64(p.bonusPrefix)
138138
}
139139

140-
return this
140+
return p
141141
}
142142

143143
// BonusThreshold overrides the default value for the minimum similarity score
144144
// for which Match() can assign a bonus.
145145
// The new value must be zero or positive. Note that a threshold greater than 1
146146
// effectively makes Match() become the equivalent of Similarity().
147-
func (this *Params) BonusThreshold(v float64) *Params {
147+
func (p *Params) BonusThreshold(v float64) *Params {
148148
if v >= 0 {
149-
this.bonusThreshold = v
149+
p.bonusThreshold = v
150150
}
151-
return this
151+
return p
152152
}

0 commit comments

Comments
 (0)