mirror of
https://github.com/qvacua/vimr.git
synced 2024-11-24 11:37:32 +03:00
32 lines
769 B
Swift
32 lines
769 B
Swift
/**
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
* See LICENSE
|
|
*/
|
|
|
|
import Foundation
|
|
|
|
class Scorer {
|
|
|
|
static func score(target: String, pattern: String) -> Float {
|
|
let wf = Matcher.wagnerFisherDistance(target, pattern: pattern)
|
|
let fuzzy = Matcher.fuzzyIgnoringCase(target, pattern: pattern)
|
|
let upper = Matcher.numberOfUppercaseMatches(target, pattern: pattern)
|
|
let exactMatch = Matcher.exactMatchIgnoringCase(target, pattern: pattern)
|
|
|
|
let exactScore: Float
|
|
switch exactMatch {
|
|
case .none:
|
|
exactScore = 0
|
|
case .exact:
|
|
return 100
|
|
case .prefix, .contains, .suffix:
|
|
exactScore = 5
|
|
}
|
|
|
|
return (wf == 0 ? 0 : 5.0 / Float(wf))
|
|
+ Float(fuzzy.matches)
|
|
+ Float(upper)
|
|
+ exactScore
|
|
}
|
|
}
|