SwiftyStringScore

0.2.3

Swift string fuzzy ranking. Score of 0 for no match; up to 1 for perfect. "String".score(word:"str"); //=> 0.825
yichizhang/SwiftyStringScore

What's New

0.2.3

2020-08-22T17:02:41Z

Fix for referencing wrong strings for counts. This Resolves an issue where self would be a string backed by NSString and when lowercased the length would change. Referencing string.count gives us the wrong length

SwiftyStringScore

SwiftyStringScore (StringScore_Swift) is a Swift library which provides fast fuzzy string matching/scoring. Based on the JavaScript library of the same name, by Joshaven Potter.

Screenshot

Examples

"hello world".score(word: "axl")	// ->0.0
"hello world".score(word: "ow")	// ->0.354545454545455
"hello world".score(word: "e")	// ->0.109090909090909
"hello world".score(word: "h")	// ->0.586363636363636
"hello world".score(word: "he")	// ->0.622727272727273
"hello world".score(word: "hel")	// ->0.659090909090909
"hello world".score(word: "hell")	// ->0.695454545454545
"hello world".score(word: "hello")	// ->0.731818181818182
"hello world".score(word: "hello worl")	// ->0.913636363636364
"hello world".score(word: "hello world")	// ->1.0
"hello world".score(word: "hello wor1")	// ->0.0
"hello world".score(word: "h")	// ->0.586363636363636
"hello world".score(word: "H")	// ->0.531818181818182
"hello world".score(word: "HiMi")	// ->0.0
"hello world".score(word: "Hills")	// ->0.0
"hello world".score(word: "Hillsd")	// ->0.0

"He".score(word: "h")	// ->0.675
"He".score(word: "H")	// ->0.75

"Hello".score(word: "hell")	// ->0.8475
"Hello".score(word: "hello")	// ->0.93
"Hello".score(word: "hello worl")	// ->0.0
"Hello".score(word: "hello world")	// ->0.0
"Hello".score(word: "hello wor1")	// ->0.0

"hello world".score(word: "hello worl", fuzziness:0.5)	// ->0.913636363636364
"hello world".score(word: "hello world", fuzziness:0.5)	// ->1.0
"hello world".score(word: "hello wor1", fuzziness:0.5)	// ->0.608181818181818

"Hillsdale Michigan".score(word: "HiMi", fuzziness:1.0)	// ->0.669444444444444
"Hillsdale Michigan".score(word: "Hills", fuzziness:1.0)	// ->0.661111111111111
"Hillsdale Michigan".score(word: "Hillsd", fuzziness:1.0)	// ->0.683333333333333

Parameters

Fuzziness

A number between 0 and 1 which varys how fuzzy/ the calculation is. Defaults to nil (fuzziness disabled).

License

Licensed under the MIT license.

Description

  • Swift Tools
View More Packages from this Author

Dependencies

  • None
Last updated: Wed Nov 09 2022 23:05:12 GMT-0500 (GMT-05:00)