Last active
August 28, 2019 21:12
-
-
Save ozgurshn/d45d7c0f5f0a6e1b366754afa734ee79 to your computer and use it in GitHub Desktop.
NLTagger
This file contains hidden or 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
| import NaturalLanguage | |
| let text = "Prime Minister Boris Johnson has urged the EU to re-open the withdrawal deal reached with Theresa May, and to make key changes that would allow it to be passed by Parliament." | |
| let tagger = NLTagger(tagSchemes: [.nameType ]) | |
| tagger.string = text | |
| let options: NLTagger.Options = [.omitPunctuation, .omitWhitespace, .joinNames] | |
| let tags: [NLTag] = [.personalName, .placeName, .organizationName, .adverb ,NLTag.pronoun, NLTag.determiner, NLTag.noun , NLTag.interjection ] | |
| tagger.enumerateTags(in: text.startIndex..<text.endIndex, unit: .word, scheme: NLTagScheme.nameType, options: options) { tag, tokenRange in | |
| if let tag = tag, tags.contains(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