Instance Method

enumerateTags(in:unit:scheme:options:using:)

Enumerates a closure over the tagger’s string, given a range, token unit, and tag scheme.

Declaration

@nonobjc func enumerateTags(in range: Range<String.Index>, unit: NLTokenUnit, scheme: NLTagScheme, options: NLTagger.Options = [], using block: (NLTag?, Range<String.Index>) -> Bool)

Parameters

range

The range of the string you want the tagger to analyze.

unit

The linguistic unit of scale you’re interested in, such as NLTokenUnit.word, NLTokenUnit.sentence, NLTokenUnit.paragraph, or NLTokenUnit.document.

scheme

The tag scheme the tagger uses to tag the string, such as language or script. This scheme determines which types of NLTag the method passes to your closure. For other tag schemes, see NLTagScheme.

options

The set of linguistic tagger options to use, such as omitWhitespace. For all available options, see NLTagger.Options.

block

The closure this method uses to iterate over the tagger’s string property. The closure has the following parameters:

tag

The tag of the token.

range

The range of the token.

Return true from the closure to tell the tagger to continue iterating over the string; otherwise return false to stop.

Discussion

Use this method to iterate your closure over the given range of a string. The method divides up the string with the given NLTokenUnit and NLTagScheme and then calls your closure. For example, use the lexicalClass tag scheme to identify which tokens are parts of speech, types of whitespace, or types of punctuation. Use the lemma tag scheme to identify the stem form of each word token, if known.

See Also

Enumerating Linguistic Tags

struct NLTagger.Options

Constants for linguistic tagger enumeration specifying which tokens to omit and whether to join names.

struct NLTag

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