Class

NSLinguisticTagger

Analyze natural language to tag part of speech and lexical class, identify proper names, perform lemmatization, and determine the language and script (orthography) of text.

Overview

The NSLinguisticTagger class provides a uniform interface to a variety of natural language processing functionality with support for many different languages and scripts. You can use NSLinguisticTagger to segment natural language text into paragraphs, sentences, or words, and tag information about those tokens, such as part of speech, lexical class, lemma, script, and language.

When you create a linguistic tagger, you specify what kind of information you're interested in by passing one or more NSLinguisticTagScheme values. Set the string property to the natural language text you want to analyze, and the linguistic tagger processes it according to the specified tag schemes. You can then enumerate over the tags in a specified range, using the methods described in Enumerating Linguistic Tags, to get the information requested for a given scheme and unit.

Thread Safety

A single instance of NSLinguisticTagger should not be used simultaneously from multiple threads.

Topics

Creating a Linguistic Tagger

init(tagSchemes: [NSLinguisticTagScheme], options: Int)

Creates a linguistic tagger instance using the specified tag schemes and options.

Getting and Setting the Analyzed String

var string: String?

The string being analyzed by the linguistic tagger.

func stringEdited(in: NSRange, changeInLength: Int)

Notifies the linguistic tagger that the string (if mutable) has changed as specified by the parameters.

Getting the Tag Schemes

class func availableTagSchemes(for: NSLinguisticTaggerUnit, language: String)

Returns the tag schemes available for a particular unit and language on the current device.

Beta
class func availableTagSchemes(forLanguage: String)

Returns the tag schemes available for a particular language on the current device.

var tagSchemes: [NSLinguisticTagScheme]

Returns the tag schemes configured for this linguistic tagger. For possible values, see NSLinguisticTagScheme.

Determining the Dominant Language and Orthography

class func dominantLanguage(for: String)

Returns the dominant language for the specified string.

Beta
var dominantLanguage: String?

Returns the dominant language of the string set for the linguistic tagger.

Beta
func orthography(at: Int, effectiveRange: NSRangePointer?)

Returns the orthography at the index and also returns the effective range.

func setOrthography(NSOrthography?, range: NSRange)

Sets the orthography for the specified range.

Determining the Range of a Unit Token

func tokenRange(at: Int, unit: NSLinguisticTaggerUnit)

Returns the range of the linguistic unit containing the specified character index.

Beta
func sentenceRange(for: NSRange)

Returns the range of a sentence containing the specified range.

Determining the Possible Tags

func possibleTags(at: Int, scheme: String, tokenRange: NSRangePointer?, sentenceRange: NSRangePointer?, scores: AutoreleasingUnsafeMutablePointer<NSArray?>?)

Returns an array of possible tags for the given scheme at the specified range, supplying matching scores.

Supporting Types

struct NSLinguisticTagScheme

Constants for the tag schemes specified when initializing a linguistic tagger.

Beta
enum NSLinguisticTaggerUnit

Constants representing linguistic units.

Beta
struct NSLinguisticTag

A token, lexical class, name, lemma, language, or script returned by a linguistic tagger for natural language text.

Beta

Relationships

Inherits From

Conforms To

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software