Created
November 26, 2019 07:24
-
-
Save mohdsanadzakirizvi/ba94e253b7b2f5d9516752d11d812376 to your computer and use it in GitHub Desktop.
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
let text = "swimming, swam, swim, assuming, assumed, assume, learned, learning." | |
// Initialize the NLTagger with scheme type as "lemma" | |
let tagger = NLTagger(tagSchemes: [.lemma]) | |
// Set the string to be processed | |
tagger.string = text | |
// Loop over all the tokens and print their lemma | |
tagger.enumerateTags(in: text.startIndex..<text.endIndex, unit: .word, scheme: .lemma) { tag, tokenRange in | |
if let tag = tag { | |
print("\(text[tokenRange]): \(tag.rawValue)") | |
} | |
return true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment