MLGazetteer
A collection of terms and their labels, which augments a tagger that analyzes natural language text.
Declaration
struct MLGazetteerOverview
Use an MLGazetteer to configure a gazetteer and save it to a file, which you then add to your app in Xcode. Your app uses the gazetteer file at runtime to create an instance of NLGazetteer, which augments an NLTagger to tag specific terms with a label.
You configure a gazetteer with a dictionary, keyed by labels. Each value in the dictionary is an array of terms (words or phrases) for each label. For example, you can store the names of real and fictional planets in a gazetteer.
let planets = [
"real planet": ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"],
"fictional planet" : ["Arrakis", "Hoth", "Vulcan", "Pandora", "Tatooine", "Bajor", "Alderaan", "Romulus"]
]
let parameters = MLGazetteer.ModelParameters(language: .english)
let planetGazetteer = try! MLGazetteer(dictionary: planets, parameters: parameters)Once you’ve configured an MLGazetteer, save it to an .mlmodel file to include in your app.
try planetGazetteer.write(toFile: "~/Desktop/PlanetGazetteer.mlmodel")A gazetteer file can efficiently store many labels, and many terms for each label.
Topics
Creating a gazetteer
init(dictionary:parameters:)init(labeledData:textColumn:labelColumn:parameters:)MLGazetteer.ModelParametersmodelParameters