Ratio returns a measure of the sequences' similarity (float in [0,1]). Where T is the total number of elements in both sequences, and M is the number of matches, this is 2.0*M / T. Note that this is 1 if the sequences are identical, and 0 if they have nothing in common. .Ratio() is expensive to co
()
| 472 | // want to try .QuickRatio() or .RealQuickRation() first to get an |
| 473 | // upper bound. |
| 474 | func (m *SequenceMatcher) Ratio() float64 { |
| 475 | matches := 0 |
| 476 | for _, m := range m.GetMatchingBlocks() { |
| 477 | matches += m.Size |
| 478 | } |
| 479 | return calculateRatio(matches, len(m.a)+len(m.b)) |
| 480 | } |
| 481 | |
| 482 | // QuickRatio returns an upper bound on ratio() relatively quickly. |
| 483 | // |