ddddxxx / LyricsKit

Lyrics submodule for LyricsX
https://github.com/ddddxxx/LyricsX
Mozilla Public License 2.0
128 stars 42 forks source link

Lyrics Quality is NaN and Inf #7

Open wimbledon opened 3 years ago

wimbledon commented 3 years ago

Please reference #5 for more details.

wimbledon commented 3 years ago

@ddddxxx

wimbledon commented 3 years ago

The reason is that similarity func will return Inf if one of the input strings has zero length due to division by zero.

private func similarity(s1: String, s2: String) -> Double {
    let len = min(s1.count, s2.count)
    let diff = min(s1.distance(to: s2, insertionCost: 0), s1.distance(to: s2, deletionCost: 0))
    return Double(len - diff) / Double(len)
}