Created
November 24, 2019 00:37
-
-
Save GrantJEmerson/35024978f0acabb970c592164e921bca to your computer and use it in GitHub Desktop.
What's in a Name - SwiftMoji Entry #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
var π¨βπ©βπ§βπ¦ = """ | |
Family: | |
Father's Name: Jayson | |
Mother's Name: Kathrine | |
Daughter's Name: Alannah | |
Son's Name: Jacob | |
""" | |
let tagger = NSLinguisticTagger(tagSchemes: [.nameType], options: 0) | |
tagger.string = π¨βπ©βπ§βπ¦ | |
let range = NSRange(π¨βπ©βπ§βπ¦.startIndex..<π¨βπ©βπ§βπ¦.endIndex, in: π¨βπ©βπ§βπ¦) | |
let options: NSLinguisticTagger.Options = [.omitPunctuation, .omitWhitespace, .joinNames] | |
tagger.enumerateTags(in: range, unit: .word, scheme: .nameType, options: options) { (tag, tokenRange, _) in | |
if let tag = tag, tag == .personalName { | |
if let range = Range(tokenRange, in: π¨βπ©βπ§βπ¦) { | |
let name = π¨βπ©βπ§βπ¦[range] | |
print("\(name)") // Jayson Katherine Alannah Jacob | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment