A collection of terms and their labels, which take precedence over a word tagger.


class NLGazetteer : NSObject


Use an NLGazetteer to augment an NLTagger when you need to tag a specific set of terms (single words or short phrases) with a label. Typically, you add one gazetteer per language, or one language-independent gazetteer, to an NLTagger with its setGazetteers(_:for:) method. The tagger uses its gazetteers to look up each term it processes. If a gazetteer has a label for a term, the tagger uses that label to tag the term, instead of inferring a tag itself.

Typically, you create a gazetteer at development time, such as in a macOS playground, with Create ML’s MLGazetteer. Alternatively, you can create an NLGazetteer at runtime by using init(dictionary:language:).


Creating a Gazetteer

init(contentsOf: URL)

Creates a Natural Language gazetteer from a model created with the Create ML framework.

init(data: Data)

Creates a gazetteer from a data instance.

init(dictionary: [String : [String]], language: NLLanguage?)

Creates a gazetteer from a set of labels for terms represented by a dictionary.

Looking Up Labels for Terms

func label(for: String) -> String?

Retrieves the label for the given term.

Inspecting a Gazetteer

var data: Data

The gazetteer represented as a data instance.

var language: NLLanguage?

The language of the gazetteer.

Type Methods

class func write([String : [String]], language: NLLanguage?, to: URL)

Creates a gazetteer from a set of labels for terms represented by a dictionary and saves the gazetteer to a file.


Inherits From

Conforms To

See Also

Using Gazetteers with a Tagger

func setGazetteers([NLGazetteer], for: NLTagScheme)

Attaches gazetteers to a tag scheme, typically one gazetteer per language or one language-independent gazetteer.

func gazetteers(for: NLTagScheme) -> [NLGazetteer]

Retrieves the gazetteers attached to a tag scheme.