matchBitapScore computes and returns the score for a match with e errors and x location.
(e, x, loc int, pattern string)
| 126 | |
| 127 | // matchBitapScore computes and returns the score for a match with e errors and x location. |
| 128 | func (dmp *DiffMatchPatch) matchBitapScore(e, x, loc int, pattern string) float64 { |
| 129 | accuracy := float64(e) / float64(len(pattern)) |
| 130 | proximity := math.Abs(float64(loc - x)) |
| 131 | if dmp.MatchDistance == 0 { |
| 132 | // Dodge divide by zero error. |
| 133 | if proximity == 0 { |
| 134 | return accuracy |
| 135 | } |
| 136 | |
| 137 | return 1.0 |
| 138 | } |
| 139 | return accuracy + (proximity / float64(dmp.MatchDistance)) |
| 140 | } |
| 141 | |
| 142 | // MatchAlphabet initialises the alphabet for the Bitap algorithm. |
| 143 | func (dmp *DiffMatchPatch) MatchAlphabet(pattern string) map[byte]int { |