Skip to content

Instantly share code, notes, and snippets.

@ozgurshn
Created March 10, 2019 19:59
Show Gist options
  • Save ozgurshn/c83d95a0fe566ce9a603b77fe3818409 to your computer and use it in GitHub Desktop.
Save ozgurshn/c83d95a0fe566ce9a603b77fe3818409 to your computer and use it in GitHub Desktop.
NLTokenizer
import NaturalLanguage
let text = "All human beings are born free and equal in dignity and rights. They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood."
let tokenizer = NLTokenizer(unit: .word)
tokenizer.string = text
//let tokenArray = tokenizer.tokens(for: strRange)
tokenizer.enumerateTokens(in: text.startIndex..<text.endIndex) { tokenRange, _ in
print(text[tokenRange])
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment