Skip to content

Instantly share code, notes, and snippets.

@mohdsanadzakirizvi
Created November 26, 2019 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohdsanadzakirizvi/ba94e253b7b2f5d9516752d11d812376 to your computer and use it in GitHub Desktop.
Save mohdsanadzakirizvi/ba94e253b7b2f5d9516752d11d812376 to your computer and use it in GitHub Desktop.
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