Last active
November 26, 2019 10:05
-
-
Save mohdsanadzakirizvi/c0a9aeca04a9d4079f743324b7191fc7 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 = "Hello world, I am a data scientist. I work with machine learning!" | |
// Initialize the tagger | |
let tagger = NLTagger(tagSchemes: [.lexicalClass]) | |
// Ignore whitespace and punctuation marks | |
let options : NLTagger.Options = [.omitWhitespace, .omitPunctuation] | |
// Process the text for POS | |
tagger.string = text | |
// loop through all the tokens and print their POS tags | |
tagger.enumerateTags(in: text.startIndex..<text.endIndex, unit: .word, scheme: .lexicalClass, options: options) { 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