Skip to content

Instantly share code, notes, and snippets.

@mohdsanadzakirizvi
Last active November 26, 2019 06:50
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/87bb5cb9f6a2fe1cc3ae4ccb89384f95 to your computer and use it in GitHub Desktop.
Save mohdsanadzakirizvi/87bb5cb9f6a2fe1cc3ae4ccb89384f95 to your computer and use it in GitHub Desktop.
// Import the NaturalLanguage library
import NaturalLanguage
let text = """
Analytics Vidhya provides a community based knowledge portal for Analytics and Data Science professionals. The aim of the platform is to become a complete portal serving all knowledge and career needs of Data Science Professionals.
"""
// Initialize the tokenizer with unit of "word"
let tokenizer = NLTokenizer(unit: .word)
// Set the string to be processed
tokenizer.string = text
// Loop over all the tokens and print them
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