File tree Expand file tree Collapse file tree 5 files changed +13
-13
lines changed
Fuzzywuzzy_swift.xcodeproj/project.xcworkspace/xcuserdata/xianli.xcuserdatad Expand file tree Collapse file tree 5 files changed +13
-13
lines changed Original file line number Diff line number Diff line change 8
8
9
9
import UIKit
10
10
11
- struct CommonSubstringPair {
11
+ public struct CommonSubstringPair {
12
12
let str1SubRange : Range < String . Index >
13
13
let str2SubRange : Range < String . Index >
14
14
let len : Int
15
15
}
16
16
17
- class CommonSubstrings : NSObject {
17
+ public class CommonSubstrings : NSObject {
18
18
/// get all pairs of common substrings
19
- class func pairs( str1 str1: String , str2: String ) -> [ CommonSubstringPair ] {
19
+ public class func pairs( str1 str1: String , str2: String ) -> [ CommonSubstringPair ] {
20
20
/// convert String to array of Characters
21
21
let charArr1 = Array ( str1. characters)
22
22
let charArr2 = Array ( str2. characters)
Original file line number Diff line number Diff line change 8
8
9
9
import UIKit
10
10
11
- class LevenshteinDistance : NSObject {
12
- class func distance( str1 str1: String , str2: String ) -> Int {
11
+ public class LevenshteinDistance : NSObject {
12
+ public class func distance( str1 str1: String , str2: String ) -> Int {
13
13
/// convert String to array of Characters
14
14
let charArr1 = Array ( str1. characters)
15
15
let charArr2 = Array ( str2. characters)
Original file line number Diff line number Diff line change 8
8
9
9
import UIKit
10
10
11
- class StringMatcher : NSObject {
11
+ public class StringMatcher : NSObject {
12
12
let str1 : String
13
13
let str2 : String
14
14
15
- lazy var levenshteinDistance : Int = LevenshteinDistance . distance ( str1: self . str1, str2: self . str2)
16
- lazy var commonSubStringPairs : [ CommonSubstringPair ] = CommonSubstrings . pairs ( str1: self . str1, str2: self . str2)
15
+ public lazy var levenshteinDistance : Int = LevenshteinDistance . distance ( str1: self . str1, str2: self . str2)
16
+ public lazy var commonSubStringPairs : [ CommonSubstringPair ] = CommonSubstrings . pairs ( str1: self . str1, str2: self . str2)
17
17
18
- init ( str1: String , str2: String ) {
18
+ public init ( str1: String , str2: String ) {
19
19
self . str1 = str1
20
20
self . str2 = str2
21
21
super. init ( )
22
22
}
23
23
24
- func ratio( ) -> Float {
24
+ public func ratio( ) -> Float {
25
25
let lenSum = ( str1. characters. count + str2. characters. count)
26
26
if lenSum == 0 { return 1 }
27
27
return Float ( lenSum - levenshteinDistance) / Float( lenSum)
Original file line number Diff line number Diff line change 8
8
9
9
import UIKit
10
10
11
- extension String {
11
+ public extension String {
12
12
/// Basic Scoring Functions
13
- static func ratio( str1 str1: String , str2: String ) -> Int {
13
+ static public func ratio( str1 str1: String , str2: String ) -> Int {
14
14
let m = StringMatcher ( str1: str1, str2: str2)
15
15
return Int ( m. ratio ( ) * 100 )
16
16
}
17
17
18
18
/// trys to match the shorter string with the most common substring of the longer one
19
- static func partialRatio( str1 str1: String , str2: String ) -> Int {
19
+ static public func partialRatio( str1 str1: String , str2: String ) -> Int {
20
20
let shorter : String
21
21
let longer : String
22
22
if str1. characters. count < str2. characters. count {
You can’t perform that action at this time.
0 commit comments