Documentation
¶
Overview ¶
Package naturallanguage provides Go bindings for the NaturalLanguage framework.
Analyze natural language text and deduce its language-specific metadata.
The Natural Language framework provides a variety of natural language processing (NLP) functionality with support for many different languages and scripts. Use this framework to segment natural language text into paragraphs, sentences, or words, and tag information about those segments, such as part of speech, lexical class, lemma, script, and language.
Tokenization ¶
- Tokenizing natural language text: Enumerate the words in a string.
- NLTokenizer: A tokenizer that segments natural language text into semantic units.
Language identification ¶
- Identifying the language in text: Detect the language in a piece of text by using a language recognizer.
- NLLanguageRecognizer: The language of a body of text.
- NLLanguage: The languages that the Natural Language framework supports.
Linguistic tags ¶
- Identifying parts of speech: Classify nouns, verbs, adjectives, and other parts of speech in a string.
- Identifying people, places, and organizations: Use a linguistic tagger to perform named entity recognition on a string.
- NLTagger: A tagger that analyzes natural language text. (NLTagScheme, NLTag, NLTokenUnit, NLGazetteer)
Text embedding ¶
- Finding similarities between pieces of text: Calculate the semantic distance between words or sentences.
- NLEmbedding: A map of strings to vectors, which locates neighboring, similar strings. (NLDistance)
Contextual embedding ¶
- NLContextualEmbedding: A model that computes sequences of embedding vectors for natural language utterances. (NLContextualEmbeddingResult)
- NLContextualEmbeddingKey: Contextual embedding keys.
- NLScript: The writing scripts that the Natural Language framework supports.
Natural language models ¶
- Creating a text classifier model: Train a machine learning model to classify natural language text.
- Creating a word tagger model: Train a machine learning model to tag individual words in natural language text.
- NLModel: A custom model trained to classify or tag natural language text. (NLModelConfiguration)
Key Types ¶
- NLEmbedding - A map of strings to vectors, which locates neighboring, similar strings.
- NLTagger - A tagger that analyzes natural language text.
- NLContextualEmbedding - A model that computes sequences of embedding vectors for natural language utterances.
- NLGazetteer - A collection of terms and their labels, which take precedence over a word tagger.
- NLLanguageRecognizer - The language of a body of text.
- NLTokenizer - A tokenizer that segments natural language text into semantic units.
- NLModel - A custom model trained to classify or tag natural language text.
- NLModelConfiguration - The configuration parameters of a natural language model.
- NLContextualEmbeddingResult - An object that represents the embedding vector result from applying a contextual embedding to a string.
Code generated from Apple documentation. DO NOT EDIT.
Index ¶
- Variables
- func NewNLContextualEmbeddingAssetsResultErrorBlock(handler NLContextualEmbeddingAssetsResultErrorHandler) (objc.ID, func())
- func NewNLTagBlock(handler NLTagHandler) (objc.ID, func())
- func NewNLTaggerAssetsResultErrorBlock(handler NLTaggerAssetsResultErrorHandler) (objc.ID, func())
- func NewRangeBlock(handler RangeHandler) (objc.ID, func())
- type INLContextualEmbedding
- type INLContextualEmbeddingResult
- type INLEmbedding
- type INLGazetteer
- type INLLanguageRecognizer
- type INLModel
- type INLModelConfiguration
- type INLTagger
- type INLTokenizer
- type NLContextualEmbedding
- func NLContextualEmbeddingFromID(id objc.ID) NLContextualEmbedding
- func NewContextualEmbeddingWithLanguage(language NLLanguage) NLContextualEmbedding
- func NewContextualEmbeddingWithModelIdentifier(modelIdentifier string) NLContextualEmbedding
- func NewContextualEmbeddingWithScript(script NLScript) NLContextualEmbedding
- func NewNLContextualEmbedding() NLContextualEmbedding
- func (c NLContextualEmbedding) Autorelease() NLContextualEmbedding
- func (c NLContextualEmbedding) Dimension() uint
- func (c NLContextualEmbedding) EmbeddingResultForStringLanguageError(string_ string, language NLLanguage) (INLContextualEmbeddingResult, error)
- func (c NLContextualEmbedding) HasAvailableAssets() bool
- func (c NLContextualEmbedding) Init() NLContextualEmbedding
- func (c NLContextualEmbedding) Languages() []string
- func (c NLContextualEmbedding) LoadWithError() (bool, error)
- func (c NLContextualEmbedding) MaximumSequenceLength() uint
- func (c NLContextualEmbedding) ModelIdentifier() string
- func (c NLContextualEmbedding) RequestEmbeddingAssets(ctx context.Context) (NLContextualEmbeddingAssetsResult, error)
- func (c NLContextualEmbedding) RequestEmbeddingAssetsWithCompletionHandler(completionHandler NLContextualEmbeddingAssetsResultErrorHandler)
- func (c NLContextualEmbedding) Revision() uint
- func (c NLContextualEmbedding) Scripts() []string
- func (c NLContextualEmbedding) Unload()
- type NLContextualEmbeddingAssetsResult
- type NLContextualEmbeddingAssetsResultErrorHandler
- type NLContextualEmbeddingClass
- type NLContextualEmbeddingKey
- type NLContextualEmbeddingResult
- func (c NLContextualEmbeddingResult) Autorelease() NLContextualEmbeddingResult
- func (c NLContextualEmbeddingResult) Init() NLContextualEmbeddingResult
- func (c NLContextualEmbeddingResult) Language() NLLanguage
- func (c NLContextualEmbeddingResult) SequenceLength() uint
- func (c NLContextualEmbeddingResult) String() string
- func (c NLContextualEmbeddingResult) TokenVectorAtIndexTokenRange(characterIndex uint, tokenRange foundation.NSRange) []foundation.NSNumber
- type NLContextualEmbeddingResultClass
- type NLDistance
- type NLDistanceHandler
- type NLDistanceType
- type NLEmbedding
- func (e NLEmbedding) Autorelease() NLEmbedding
- func (e NLEmbedding) ContainsString(string_ string) bool
- func (e NLEmbedding) Dimension() uint
- func (e NLEmbedding) DistanceBetweenStringAndStringDistanceType(firstString string, secondString string, distanceType NLDistanceType) NLDistance
- func (e NLEmbedding) GetVectorForString(string_ string) (float32, bool)
- func (e NLEmbedding) Init() NLEmbedding
- func (e NLEmbedding) Language() NLLanguage
- func (e NLEmbedding) NeighborsForStringMaximumCountDistanceType(string_ string, maxCount uint, distanceType NLDistanceType) []string
- func (e NLEmbedding) NeighborsForStringMaximumCountMaximumDistanceDistanceType(string_ string, maxCount uint, maxDistance NLDistance, ...) []string
- func (e NLEmbedding) NeighborsForVectorMaximumCountDistanceType(vector []foundation.NSNumber, maxCount uint, distanceType NLDistanceType) []string
- func (e NLEmbedding) NeighborsForVectorMaximumCountMaximumDistanceDistanceType(vector []foundation.NSNumber, maxCount uint, maxDistance NLDistance, ...) []string
- func (e NLEmbedding) Revision() uint
- func (e NLEmbedding) VectorForString(string_ string) []foundation.NSNumber
- func (e NLEmbedding) VocabularySize() uint
- type NLEmbeddingClass
- func (nc NLEmbeddingClass) Alloc() NLEmbedding
- func (_NLEmbeddingClass NLEmbeddingClass) CurrentRevisionForLanguage(language NLLanguage) uint
- func (_NLEmbeddingClass NLEmbeddingClass) CurrentSentenceEmbeddingRevisionForLanguage(language NLLanguage) uint
- func (_NLEmbeddingClass NLEmbeddingClass) SentenceEmbeddingForLanguage(language NLLanguage) NLEmbedding
- func (_NLEmbeddingClass NLEmbeddingClass) SentenceEmbeddingForLanguageRevision(language NLLanguage, revision uint) NLEmbedding
- func (_NLEmbeddingClass NLEmbeddingClass) SupportedRevisionsForLanguage(language NLLanguage) foundation.NSIndexSet
- func (_NLEmbeddingClass NLEmbeddingClass) SupportedSentenceEmbeddingRevisionsForLanguage(language NLLanguage) foundation.NSIndexSet
- func (_NLEmbeddingClass NLEmbeddingClass) WordEmbeddingForLanguage(language NLLanguage) NLEmbedding
- func (_NLEmbeddingClass NLEmbeddingClass) WordEmbeddingForLanguageRevision(language NLLanguage, revision uint) NLEmbedding
- func (_NLEmbeddingClass NLEmbeddingClass) WriteEmbeddingForDictionaryLanguageRevisionToURLError(dictionary foundation.INSDictionary, language NLLanguage, revision uint, ...) (bool, error)
- type NLGazetteer
- func NLGazetteerFromID(id objc.ID) NLGazetteer
- func NewGazetteerWithContentsOfURLError(url foundation.INSURL) (NLGazetteer, error)
- func NewGazetteerWithDataError(data foundation.INSData) (NLGazetteer, error)
- func NewGazetteerWithDictionaryLanguageError(dictionary foundation.INSDictionary, language NLLanguage) (NLGazetteer, error)
- func NewNLGazetteer() NLGazetteer
- func (g NLGazetteer) Autorelease() NLGazetteer
- func (g NLGazetteer) Data() foundation.INSData
- func (g NLGazetteer) Init() NLGazetteer
- func (g NLGazetteer) InitWithContentsOfURLError(url foundation.INSURL) (NLGazetteer, error)
- func (g NLGazetteer) InitWithDataError(data foundation.INSData) (NLGazetteer, error)
- func (g NLGazetteer) InitWithDictionaryLanguageError(dictionary foundation.INSDictionary, language NLLanguage) (NLGazetteer, error)
- func (g NLGazetteer) LabelForString(string_ string) string
- func (g NLGazetteer) Language() NLLanguage
- type NLGazetteerClass
- func (nc NLGazetteerClass) Alloc() NLGazetteer
- func (_NLGazetteerClass NLGazetteerClass) GazetteerWithContentsOfURLError(url foundation.INSURL) (NLGazetteer, error)
- func (_NLGazetteerClass NLGazetteerClass) WriteGazetteerForDictionaryLanguageToURLError(dictionary foundation.INSDictionary, language NLLanguage, ...) (bool, error)
- type NLLanguage
- type NLLanguageRecognizer
- func (l NLLanguageRecognizer) Autorelease() NLLanguageRecognizer
- func (l NLLanguageRecognizer) DominantLanguage() NLLanguage
- func (l NLLanguageRecognizer) Init() NLLanguageRecognizer
- func (l NLLanguageRecognizer) LanguageConstraints() []string
- func (l NLLanguageRecognizer) LanguageHints() foundation.INSDictionary
- func (l NLLanguageRecognizer) LanguageHypothesesWithMaximum(maxHypotheses uint) foundation.INSDictionary
- func (l NLLanguageRecognizer) ProcessString(string_ string)
- func (l NLLanguageRecognizer) Reset()
- func (l NLLanguageRecognizer) SetLanguageConstraints(value []string)
- func (l NLLanguageRecognizer) SetLanguageHints(value foundation.INSDictionary)
- type NLLanguageRecognizerClass
- type NLModel
- func (m NLModel) Autorelease() NLModel
- func (m NLModel) Configuration() INLModelConfiguration
- func (m NLModel) Init() NLModel
- func (m NLModel) PredictedLabelForString(string_ string) string
- func (m NLModel) PredictedLabelHypothesesForStringMaximumCount(string_ string, maximumCount uint) foundation.INSDictionary
- func (m NLModel) PredictedLabelHypothesesForTokensMaximumCount(tokens []string, maximumCount uint) foundation.INSDictionary
- func (m NLModel) PredictedLabelsForTokens(tokens []string) []string
- type NLModelClass
- type NLModelConfiguration
- func (m NLModelConfiguration) Autorelease() NLModelConfiguration
- func (m NLModelConfiguration) Configuration() INLModelConfiguration
- func (m NLModelConfiguration) EncodeWithCoder(coder foundation.INSCoder)
- func (m NLModelConfiguration) Init() NLModelConfiguration
- func (m NLModelConfiguration) Language() NLLanguage
- func (m NLModelConfiguration) Revision() uint
- func (m NLModelConfiguration) SetConfiguration(value INLModelConfiguration)
- func (m NLModelConfiguration) Type() NLModelType
- type NLModelConfigurationClass
- type NLModelType
- type NLScript
- type NLTag
- type NLTagHandler
- type NLTagScheme
- type NLTagger
- func (t NLTagger) Autorelease() NLTagger
- func (t NLTagger) DominantLanguage() NLLanguage
- func (t NLTagger) EnumerateTagsInRangeUnitSchemeOptionsUsingBlock(range_ foundation.NSRange, unit NLTokenUnit, scheme NLTagScheme, ...)
- func (t NLTagger) GazetteersForTagScheme(tagScheme NLTagScheme) []NLGazetteer
- func (t NLTagger) Init() NLTagger
- func (t NLTagger) InitWithTagSchemes(tagSchemes []string) NLTagger
- func (t NLTagger) ModelsForTagScheme(tagScheme NLTagScheme) []NLModel
- func (t NLTagger) SetGazetteersForTagScheme(gazetteers []NLGazetteer, tagScheme NLTagScheme)
- func (t NLTagger) SetLanguageRange(language NLLanguage, range_ foundation.NSRange)
- func (t NLTagger) SetModelsForTagScheme(models []NLModel, tagScheme NLTagScheme)
- func (t NLTagger) SetOrthographyRange(orthography foundation.NSOrthography, range_ foundation.NSRange)
- func (t NLTagger) SetString(value string)
- func (t NLTagger) String() string
- func (t NLTagger) TagAtIndexUnitSchemeTokenRange(characterIndex uint, unit NLTokenUnit, scheme NLTagScheme, ...) NLTag
- func (t NLTagger) TagHypothesesAtIndexUnitSchemeMaximumCountTokenRange(characterIndex uint, unit NLTokenUnit, scheme NLTagScheme, maximumCount uint, ...) foundation.INSDictionary
- func (t NLTagger) TagSchemes() []string
- func (t NLTagger) TagsInRangeUnitSchemeOptionsTokenRanges(range_ foundation.NSRange, unit NLTokenUnit, scheme NLTagScheme, ...) []string
- func (t NLTagger) TokenRangeAtIndexUnit(characterIndex uint, unit NLTokenUnit) foundation.NSRange
- func (t NLTagger) TokenRangeForRangeUnit(range_ foundation.NSRange, unit NLTokenUnit) foundation.NSRange
- type NLTaggerAssetsResult
- type NLTaggerAssetsResultErrorHandler
- type NLTaggerClass
- func (nc NLTaggerClass) Alloc() NLTagger
- func (_NLTaggerClass NLTaggerClass) AvailableTagSchemesForUnitLanguage(unit NLTokenUnit, language NLLanguage) []string
- func (tc NLTaggerClass) RequestAssetsForLanguageTagScheme(ctx context.Context, language NLLanguage, tagScheme NLTagScheme) (NLTaggerAssetsResult, error)
- func (_NLTaggerClass NLTaggerClass) RequestAssetsForLanguageTagSchemeCompletionHandler(language NLLanguage, tagScheme NLTagScheme, ...)
- type NLTaggerOptions
- type NLTokenUnit
- type NLTokenizer
- func (t NLTokenizer) Autorelease() NLTokenizer
- func (t NLTokenizer) EnumerateTokensInRangeUsingBlock(range_ foundation.NSRange, block func(unsafe.Pointer, uint64, *bool))
- func (t NLTokenizer) Init() NLTokenizer
- func (t NLTokenizer) InitWithUnit(unit NLTokenUnit) NLTokenizer
- func (t NLTokenizer) SetLanguage(language NLLanguage)
- func (t NLTokenizer) SetString(value string)
- func (t NLTokenizer) String() string
- func (t NLTokenizer) TokenRangeAtIndex(characterIndex uint) foundation.NSRange
- func (t NLTokenizer) TokenRangeForRange(range_ foundation.NSRange) foundation.NSRange
- func (t NLTokenizer) TokensForRange(range_ foundation.NSRange) []foundation.NSValue
- func (t NLTokenizer) Unit() NLTokenUnit
- type NLTokenizerAttributes
- type NLTokenizerClass
- type RangeHandler
Constants ¶
This section is empty.
Variables ¶
var NLContextualEmbeddingKeys struct { // Languages: A key that identifies the languages in a contextual embedding. Languages NLContextualEmbeddingKey // Revision: A key that identifies the revision for a contextual embedding. Revision NLContextualEmbeddingKey // Scripts: A key that identifies the scripts in a contextual embedding. Scripts NLContextualEmbeddingKey }
NLContextualEmbeddingKeys provides typed accessors for NLContextualEmbeddingKey constants.
var NLLanguages struct { // Amharic: The unique identifier string for the Amharic language. Amharic NLLanguage // Arabic: The unique identifier string for the Arabic language. Arabic NLLanguage // Armenian: The unique identifier string for the Armenian language. Armenian NLLanguage // Bengali: The unique identifier string for the Bengali language. Bengali NLLanguage // Bulgarian: The unique identifier string for the Bulgarian language. Bulgarian NLLanguage // Burmese: The unique identifier string for the Burmese language. Burmese NLLanguage // Catalan: The unique identifier string for the Catalan language. Catalan NLLanguage // Cherokee: The unique identifier string for the Cherokee language. Cherokee NLLanguage // Croatian: The unique identifier string for the Croatian language. Croatian NLLanguage // Czech: The unique identifier string for the Czech language. Czech NLLanguage // Danish: The unique identifier string for the Danish language. Danish NLLanguage // Dutch: The unique identifier string for the Dutch language. Dutch NLLanguage // English: The unique identifier string for the English language. English NLLanguage // Finnish: The unique identifier string for the Finnish language. Finnish NLLanguage // French: The unique identifier string for the French language. French NLLanguage // Georgian: The unique identifier string for the Georgian language. Georgian NLLanguage // German: The unique identifier string for the German language. German NLLanguage // Greek: The unique identifier string for the Greek language. Greek NLLanguage // Gujarati: The unique identifier string for the Gujarati language. Gujarati NLLanguage // Hebrew: The unique identifier string for the Hebrew language. Hebrew NLLanguage // Hindi: The unique identifier string for the Hindi language. Hindi NLLanguage // Hungarian: The unique identifier string for the Hungarian language. Hungarian NLLanguage // Icelandic: The unique identifier string for the Icelandic language. Icelandic NLLanguage // Indonesian: The unique identifier string for the Indonesian language. Indonesian NLLanguage // Italian: The unique identifier string for the Italian language. Italian NLLanguage // Japanese: The unique identifier string for the Japanese language. Japanese NLLanguage // Kannada: The unique identifier string for the Kannada language. Kannada NLLanguage // Kazakh: The unique identifier string for the Kazakh language. Kazakh NLLanguage // Khmer: The unique identifier string for the Khmer language. Khmer NLLanguage // Korean: The unique identifier string for the Korean language. Korean NLLanguage // Lao: The unique identifier string for the Lao language. Lao NLLanguage // Malay: The unique identifier string for the Malay language. Malay NLLanguage // Malayalam: The unique identifier string for the Malayalam language. Malayalam NLLanguage // Marathi: The unique identifier string for the Marathi language. Marathi NLLanguage // Mongolian: The unique identifier string for the Mongolian language. Mongolian NLLanguage // Norwegian: The unique identifier string for the Norwegian language. Norwegian NLLanguage // Oriya: The unique identifier string for the Oriya language. Oriya NLLanguage // Persian: The unique identifier string for the Persian language. Persian NLLanguage // Polish: The unique identifier string for the Polish language. Polish NLLanguage // Portuguese: The unique identifier string for the Portuguese language. Portuguese NLLanguage // Punjabi: The unique identifier string for the Punjabi language. Punjabi NLLanguage // Romanian: The unique identifier string for the Romanian language. Romanian NLLanguage // Russian: The unique identifier string for the Russian language. Russian NLLanguage // SimplifiedChinese: The unique identifier string for the Simplified Chinese language. SimplifiedChinese NLLanguage // Sinhalese: The unique identifier string for the Sinhalese language. Sinhalese NLLanguage // Slovak: The unique identifier string for the Slovak language. Slovak NLLanguage // Spanish: The unique identifier string for the Spanish language. Spanish NLLanguage // Swedish: The unique identifier string for the Swedish language. Swedish NLLanguage // Tamil: The unique identifier string for the Tamil language. Tamil NLLanguage // Telugu: The unique identifier string for the Telugu language. Telugu NLLanguage // Thai: The unique identifier string for the Thai language. Thai NLLanguage // Tibetan: The unique identifier string for the Tibetan language. Tibetan NLLanguage // TraditionalChinese: The unique identifier string for the Traditional Chinese language. TraditionalChinese NLLanguage // Turkish: The unique identifier string for the Turkish language. Turkish NLLanguage // Ukrainian: The unique identifier string for the Ukrainian language. Ukrainian NLLanguage // Undetermined: The unique identifier string for a language the Natural Language framework doesn’t recognize. Undetermined NLLanguage // Urdu: The unique identifier string for the Urdu language. Urdu NLLanguage // Vietnamese: The unique identifier string for the Vietnamese language. Vietnamese NLLanguage }
NLLanguages provides typed accessors for NLLanguage constants.
var NLScripts struct { // Arabic: The unique identifier string for the Arabic script. Arabic NLScript // Armenian: The unique identifier string for the Armenian script. Armenian NLScript // Bengali: The unique identifier string for the Bengali script. Bengali NLScript // CanadianAboriginalSyllabics: The unique identifier string for the Canadian Aboriginal Syllabics. CanadianAboriginalSyllabics NLScript // Cherokee: The unique identifier string for the Cherokee script. Cherokee NLScript // Cyrillic: The unique identifier string for the Cyrillic script. Cyrillic NLScript // Devanagari: The unique identifier string for the Devanagari script. Devanagari NLScript // Ethiopic: The unique identifier string for the Ethiopic script. Ethiopic NLScript // Georgian: The unique identifier string for the Georgian script. Georgian NLScript // Greek: The unique identifier string for the Greek script. Greek NLScript // Gujarati: The unique identifier string for the Gujarati script. Gujarati NLScript // Gurmukhi: The unique identifier string for the Gurmukhi script. Gurmukhi NLScript // Hebrew: The unique identifier string for the Hebrew script. Hebrew NLScript // Japanese: The unique identifier string for the Japanese script. Japanese NLScript // Kannada: The unique identifier string for the Kannada script. Kannada NLScript // Khmer: The unique identifier string for the Khmer script. Khmer NLScript // Korean: The unique identifier string for the Korean script. Korean NLScript // Lao: The unique identifier string for the Lao script. Lao NLScript // Latin: The unique identifier string for the Latin script. Latin NLScript // Malayalam: The unique identifier string for the Malayalam script. Malayalam NLScript // Mongolian: The unique identifier string for the Mongolian script. Mongolian NLScript // Myanmar: The unique identifier string for the Myanmar script. Myanmar NLScript // Oriya: The unique identifier string for the Oriya script. Oriya NLScript // SimplifiedChinese: The unique identifier string for the simplified Chinese script. SimplifiedChinese NLScript // Sinhala: The unique identifier string for the Sinhala script. Sinhala NLScript // Tamil: The unique identifier string for the Tamil script. Tamil NLScript // Telugu: The unique identifier string for the Telugu script. Telugu NLScript // Thai: The unique identifier string for the Thai script. Thai NLScript // Tibetan: The unique identifier string for the Tibetan script. Tibetan NLScript // TraditionalChinese: The unique identifier string for the traditional Chinese script. TraditionalChinese NLScript // Undetermined: The unique identifier string for a script the Natural Language framework doesn’t recognize. Undetermined NLScript }
NLScripts provides typed accessors for NLScript constants.
var NLTagSchemes struct { // Language: A scheme that supplies the language for a token, if it can determine one. Language NLTagScheme // Lemma: A scheme that supplies a stem form of a word token, if known. Lemma NLTagScheme // LexicalClass: A scheme that classifies tokens according to class: part of speech, type of punctuation, or whitespace. LexicalClass NLTagScheme // NameType: A scheme that classifies tokens according to whether they are part of a named entity. NameType NLTagScheme // NameTypeOrLexicalClass: A scheme that classifies tokens corresponding to names according to [nameType](<doc://com.apple.naturallanguage/documentation/NaturalLanguage/NLTagScheme/nameType>), and classifies all other tokens according to [lexicalClass](<doc://com.apple.naturallanguage/documentation/NaturalLanguage/NLTagScheme/lexicalClass>). NameTypeOrLexicalClass NLTagScheme // Script: A scheme that supplies the script for a token, if it can determine one. Script NLTagScheme // SentimentScore: A scheme that scores text as positive, negative, or neutral based on its sentiment polarity. SentimentScore NLTagScheme // TokenType: A scheme that classifies tokens according to their broad type: word, punctuation, or whitespace. TokenType NLTagScheme }
NLTagSchemes provides typed accessors for NLTagScheme constants.
var NLTags struct { // Adjective: A tag indicating that the token is an adjective Adjective NLTag // Adverb: A tag indicating that the token is an adverb. Adverb NLTag // Classifier: A tag indicating that the token is a classifier. Classifier NLTag // CloseParenthesis: A tag indicating that the token is a close parenthesis. CloseParenthesis NLTag // CloseQuote: A tag indicating that the token is a close quote. CloseQuote NLTag // Conjunction: A tag indicating that the token is a conjunction. Conjunction NLTag // Dash: A tag indicating that the token is a dash. Dash NLTag // Determiner: A tag indicating that the token is a determiner. Determiner NLTag // Idiom: A tag indicating that the token is an idiom. Idiom NLTag // Interjection: A tag indicating that the token is an interjection. Interjection NLTag // Noun: A tag indicating that the token is a noun. Noun NLTag // Number: A tag indicating that the token is a number. Number NLTag // OpenParenthesis: A tag indicating that the token is an open parenthesis. OpenParenthesis NLTag // OpenQuote: A tag indicating that the token is an open quote. OpenQuote NLTag // OrganizationName: A tag indicating that the token is an organization name. OrganizationName NLTag // Other: A tag indicating that the token is a non-linguistic item, such as a symbol. Other NLTag // OtherPunctuation: A tag indicating that the token is punctuation other than a kind described by other lexical classes (sentence terminator, open or close quote, open or close parenthesis, word joiner, and dash). OtherPunctuation NLTag // OtherWhitespace: A tag indicating that the token is whitespace other than a kind described by other lexical classes (paragraph break). OtherWhitespace NLTag // OtherWord: A tag indicating that the token is a word other than a kind described by other lexical classes (noun, verb, adjective, adverb, pronoun, determiner, particle, preposition, number, conjunction, interjection, classifier, and idiom). OtherWord NLTag // ParagraphBreak: A tag indicating that the token is a paragraph break. ParagraphBreak NLTag // Particle: A tag indicating that the token is a particle. Particle NLTag // PersonalName: A tag indicating that the token is a personal name. PersonalName NLTag // PlaceName: A tag indicating that the token is a place name. PlaceName NLTag // Preposition: A tag indicating that the token is a preposition. Preposition NLTag // Pronoun: A tag indicating that the token is a pronoun. Pronoun NLTag // Punctuation: A tag indicating that the token is punctuation. Punctuation NLTag // SentenceTerminator: A tag indicating that the token is punctuation at the end of a sentence. SentenceTerminator NLTag // Verb: A tag indicating that the token is a verb. Verb NLTag // Whitespace: A tag indicating that the token is white space of any sort. Whitespace NLTag // Word: A tag indicating that the token is a word. Word NLTag // WordJoiner: A tag indicating that the token is a word joiner, signifying that two tokens on each side should not be broken up. WordJoiner NLTag }
NLTags provides typed accessors for NLTag constants.
Functions ¶
func NewNLContextualEmbeddingAssetsResultErrorBlock ¶
func NewNLContextualEmbeddingAssetsResultErrorBlock(handler NLContextualEmbeddingAssetsResultErrorHandler) (objc.ID, func())
NewNLContextualEmbeddingAssetsResultErrorBlock wraps a Go NLContextualEmbeddingAssetsResultErrorHandler as an Objective-C block. The caller must defer the returned cleanup function.
Used by:
func NewNLTagBlock ¶
func NewNLTagBlock(handler NLTagHandler) (objc.ID, func())
NewNLTagBlock wraps a Go NLTagHandler as an Objective-C block. The caller must defer the returned cleanup function.
Used by:
func NewNLTaggerAssetsResultErrorBlock ¶
func NewNLTaggerAssetsResultErrorBlock(handler NLTaggerAssetsResultErrorHandler) (objc.ID, func())
NewNLTaggerAssetsResultErrorBlock wraps a Go NLTaggerAssetsResultErrorHandler as an Objective-C block. The caller must defer the returned cleanup function.
Used by:
- [NLTagger.RequestAssetsForLanguageTagSchemeCompletionHandler]
func NewRangeBlock ¶
func NewRangeBlock(handler RangeHandler) (objc.ID, func())
NewRangeBlock wraps a Go RangeHandler as an Objective-C block. The caller must defer the returned cleanup function.
Used by:
- [NLContextualEmbeddingResult.EnumerateTokenVectorsInRangeUsingBlock]
- NLTokenizer.EnumerateTokensInRangeUsingBlock
Types ¶
type INLContextualEmbedding ¶
type INLContextualEmbedding interface {
objectivec.IObject
// The number of dimensions in the script’s vector space.
Dimension() uint
// A Boolean value that indicates whether assets are available to load.
HasAvailableAssets() bool
// The languages of the text in the contextual embedding.
Languages() []string
// The maximum number of embedding vectors the model generates, in sequence.
MaximumSequenceLength() uint
// The model identifier.
ModelIdentifier() string
// The revision of the contextual embedding.
Revision() uint
// The scripts of the text in the contextual embedding.
Scripts() []string
// Requests assets for an embedding, if available.
RequestEmbeddingAssetsWithCompletionHandler(completionHandler NLContextualEmbeddingAssetsResultErrorHandler)
// Loads the embedding model.
LoadWithError() (bool, error)
// Unloads the embedding model.
Unload()
// Applies an embedding to a string and obtains the resulting embedding vectors.
EmbeddingResultForStringLanguageError(string_ string, language NLLanguage) (INLContextualEmbeddingResult, error)
}
An interface definition for the NLContextualEmbedding class.
Inspecting the contextual embedding ¶
- [INLContextualEmbedding.Dimension]: The number of dimensions in the script’s vector space.
- [INLContextualEmbedding.HasAvailableAssets]: A Boolean value that indicates whether assets are available to load.
- [INLContextualEmbedding.Languages]: The languages of the text in the contextual embedding.
- [INLContextualEmbedding.MaximumSequenceLength]: The maximum number of embedding vectors the model generates, in sequence.
- [INLContextualEmbedding.ModelIdentifier]: The model identifier.
- [INLContextualEmbedding.Revision]: The revision of the contextual embedding.
- [INLContextualEmbedding.Scripts]: The scripts of the text in the contextual embedding.
Requesting assets ¶
- [INLContextualEmbedding.RequestEmbeddingAssetsWithCompletionHandler]: Requests assets for an embedding, if available.
Loading and unloading assets ¶
- [INLContextualEmbedding.LoadWithError]: Loads the embedding model.
- [INLContextualEmbedding.Unload]: Unloads the embedding model.
Applying an embedding ¶
- [INLContextualEmbedding.EmbeddingResultForStringLanguageError]: Applies an embedding to a string and obtains the resulting embedding vectors.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbedding
type INLContextualEmbeddingResult ¶
type INLContextualEmbeddingResult interface {
objectivec.IObject
// The resulting language.
Language() NLLanguage
// The number of embedding vectors the request generates.
SequenceLength() uint
// The string value.
String() string
// Returns a token vector at the specified character index.
TokenVectorAtIndexTokenRange(characterIndex uint, tokenRange foundation.NSRange) []foundation.NSNumber
}
An interface definition for the NLContextualEmbeddingResult class.
Inspecting the result ¶
- [INLContextualEmbeddingResult.Language]: The resulting language.
- [INLContextualEmbeddingResult.SequenceLength]: The number of embedding vectors the request generates.
- [INLContextualEmbeddingResult.String]: The string value.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbeddingResult
type INLEmbedding ¶
type INLEmbedding interface {
objectivec.IObject
// The number of dimensions in the vocabulary’s vector space.
Dimension() uint
// The number of words in the vocabulary.
VocabularySize() uint
// The language of the text in the word embedding.
Language() NLLanguage
// Requests a Boolean value that indicates whether the term is in the vocabulary.
ContainsString(string_ string) bool
// The revision of the word embedding.
Revision() uint
// Calculates the distance between two strings in the vocabulary space.
DistanceBetweenStringAndStringDistanceType(firstString string, secondString string, distanceType NLDistanceType) NLDistance
// Copies a vector into the given a pointer to a float array.
GetVectorForString(string_ string) (float32, bool)
// Retrieves a limited number of strings near a string in the vocabulary.
NeighborsForStringMaximumCountDistanceType(string_ string, maxCount uint, distanceType NLDistanceType) []string
// Retrieves a limited number of strings, within a radius of a string, in the vocabulary.
NeighborsForStringMaximumCountMaximumDistanceDistanceType(string_ string, maxCount uint, maxDistance NLDistance, distanceType NLDistanceType) []string
// Retrieves a limited number of strings near a location in the vocabulary space.
NeighborsForVectorMaximumCountDistanceType(vector []foundation.NSNumber, maxCount uint, distanceType NLDistanceType) []string
// Retrieves a limited number of strings within a radius of a location in the vocabulary space.
NeighborsForVectorMaximumCountMaximumDistanceDistanceType(vector []foundation.NSNumber, maxCount uint, maxDistance NLDistance, distanceType NLDistanceType) []string
// Requests the vector for the given term.
VectorForString(string_ string) []foundation.NSNumber
}
An interface definition for the NLEmbedding class.
Inspecting the vocabulary of an embedding ¶
- [INLEmbedding.Dimension]: The number of dimensions in the vocabulary’s vector space.
- [INLEmbedding.VocabularySize]: The number of words in the vocabulary.
- [INLEmbedding.Language]: The language of the text in the word embedding.
- [INLEmbedding.ContainsString]: Requests a Boolean value that indicates whether the term is in the vocabulary.
- [INLEmbedding.Revision]: The revision of the word embedding.
See: https://developer.apple.com/documentation/NaturalLanguage/NLEmbedding
type INLGazetteer ¶
type INLGazetteer interface {
objectivec.IObject
// Creates a Natural Language gazetteer from a model created with the Create ML framework.
InitWithContentsOfURLError(url foundation.INSURL) (NLGazetteer, error)
// Creates a gazetteer from a data instance.
InitWithDataError(data foundation.INSData) (NLGazetteer, error)
// Creates a gazetteer from a set of labels for terms represented by a dictionary.
InitWithDictionaryLanguageError(dictionary foundation.INSDictionary, language NLLanguage) (NLGazetteer, error)
// Retrieves the label for the given term.
LabelForString(string_ string) string
// The gazetteer represented as a data instance.
Data() foundation.INSData
// The language of the gazetteer.
Language() NLLanguage
}
An interface definition for the NLGazetteer class.
Creating a Gazetteer ¶
- [INLGazetteer.InitWithContentsOfURLError]: Creates a Natural Language gazetteer from a model created with the Create ML framework.
- [INLGazetteer.InitWithDataError]: Creates a gazetteer from a data instance.
- [INLGazetteer.InitWithDictionaryLanguageError]: Creates a gazetteer from a set of labels for terms represented by a dictionary.
Looking Up Labels for Terms ¶
- [INLGazetteer.LabelForString]: Retrieves the label for the given term.
Inspecting a Gazetteer ¶
- [INLGazetteer.Data]: The gazetteer represented as a data instance.
- [INLGazetteer.Language]: The language of the gazetteer.
See: https://developer.apple.com/documentation/NaturalLanguage/NLGazetteer
type INLLanguageRecognizer ¶
type INLLanguageRecognizer interface {
objectivec.IObject
// Analyzes the piece of text to determine its dominant language.
ProcessString(string_ string)
// The most likely language for the processed text.
DominantLanguage() NLLanguage
// Resets the recognizer to its initial state.
Reset()
// Limits the set of possible languages that the recognizer will return.
LanguageConstraints() []string
SetLanguageConstraints(value []string)
// A dictionary that maps languages to their probabilities in the language identification process.
LanguageHints() foundation.INSDictionary
SetLanguageHints(value foundation.INSDictionary)
// Generates the probabilities of possible languages for the processed text.
LanguageHypothesesWithMaximum(maxHypotheses uint) foundation.INSDictionary
}
An interface definition for the NLLanguageRecognizer class.
Determining the language ¶
- [INLLanguageRecognizer.ProcessString]: Analyzes the piece of text to determine its dominant language.
- [INLLanguageRecognizer.DominantLanguage]: The most likely language for the processed text.
- [INLLanguageRecognizer.Reset]: Resets the recognizer to its initial state.
Guiding the recognizer ¶
- [INLLanguageRecognizer.LanguageConstraints]: Limits the set of possible languages that the recognizer will return.
- [INLLanguageRecognizer.SetLanguageConstraints]
See: https://developer.apple.com/documentation/NaturalLanguage/NLLanguageRecognizer
type INLModel ¶
type INLModel interface {
objectivec.IObject
// Predicts a label for the given input string.
PredictedLabelForString(string_ string) string
// Predicts a label for each string in the given array.
PredictedLabelsForTokens(tokens []string) []string
// A configuration describing the natural language model.
Configuration() INLModelConfiguration
// Predicts multiple possible labels for the given input string.
PredictedLabelHypothesesForStringMaximumCount(string_ string, maximumCount uint) foundation.INSDictionary
// Predicts multiple possible labels for each string in the given array.
PredictedLabelHypothesesForTokensMaximumCount(tokens []string, maximumCount uint) foundation.INSDictionary
}
An interface definition for the NLModel class.
Making predictions ¶
- [INLModel.PredictedLabelForString]: Predicts a label for the given input string.
- [INLModel.PredictedLabelsForTokens]: Predicts a label for each string in the given array.
Inspecting a model ¶
- [INLModel.Configuration]: A configuration describing the natural language model.
See: https://developer.apple.com/documentation/NaturalLanguage/NLModel
type INLModelConfiguration ¶
type INLModelConfiguration interface {
objectivec.IObject
// The language the model supports.
Language() NLLanguage
// The version of the Natural Language framework that trained the model.
Revision() uint
// The natural language model type of the model.
Type() NLModelType
// A configuration describing the natural language model.
Configuration() INLModelConfiguration
SetConfiguration(value INLModelConfiguration)
EncodeWithCoder(coder foundation.INSCoder)
}
An interface definition for the NLModelConfiguration class.
Accessing the configuration ¶
- [INLModelConfiguration.Language]: The language the model supports.
- [INLModelConfiguration.Revision]: The version of the Natural Language framework that trained the model.
- [INLModelConfiguration.Type]: The natural language model type of the model.
See: https://developer.apple.com/documentation/NaturalLanguage/NLModelConfiguration
type INLTagger ¶
type INLTagger interface {
objectivec.IObject
// Creates a linguistic tagger instance using the specified tag schemes and options.
InitWithTagSchemes(tagSchemes []string) NLTagger
// The string being analyzed by the linguistic tagger.
String() string
SetString(value string)
// The tag schemes configured for this linguistic tagger.
TagSchemes() []string
// The dominant language of the string set for the linguistic tagger.
DominantLanguage() NLLanguage
// Assigns models for a tag scheme.
SetModelsForTagScheme(models []NLModel, tagScheme NLTagScheme)
// Returns the models that apply to the given tag scheme.
ModelsForTagScheme(tagScheme NLTagScheme) []NLModel
// Attaches gazetteers to a tag scheme, typically one gazetteer per language or one language-independent gazetteer.
SetGazetteersForTagScheme(gazetteers []NLGazetteer, tagScheme NLTagScheme)
// Retrieves the gazetteers attached to a tag scheme.
GazetteersForTagScheme(tagScheme NLTagScheme) []NLGazetteer
// Enumerates a block over the tagger’s string, given a range, token unit, and tag scheme.
EnumerateTagsInRangeUnitSchemeOptionsUsingBlock(range_ foundation.NSRange, unit NLTokenUnit, scheme NLTagScheme, options NLTaggerOptions, block func(*string, unsafe.Pointer, *bool))
// Sets the language for a range of text within the tagger’s string.
SetLanguageRange(language NLLanguage, range_ foundation.NSRange)
// Sets the orthography for the specified range.
SetOrthographyRange(orthography foundation.NSOrthography, range_ foundation.NSRange)
// Finds a tag for a given linguistic unit, for a single scheme, at the specified character position.
TagAtIndexUnitSchemeTokenRange(characterIndex uint, unit NLTokenUnit, scheme NLTagScheme, tokenRange foundation.NSRange) NLTag
// Finds multiple possible tags for a given linguistic unit, for a single scheme, at the specified character position.
TagHypothesesAtIndexUnitSchemeMaximumCountTokenRange(characterIndex uint, unit NLTokenUnit, scheme NLTagScheme, maximumCount uint, tokenRange foundation.NSRange) foundation.INSDictionary
// Finds an array of linguistic tags and token ranges for a given string range and linguistic unit.
TagsInRangeUnitSchemeOptionsTokenRanges(range_ foundation.NSRange, unit NLTokenUnit, scheme NLTagScheme, options NLTaggerOptions, tokenRanges []foundation.NSValue) []string
// Returns the range of the linguistic unit containing the specified character index.
TokenRangeAtIndexUnit(characterIndex uint, unit NLTokenUnit) foundation.NSRange
// Finds the entire range of all tokens of the specified linguistic unit contained completely or partially within the specified range.
TokenRangeForRangeUnit(range_ foundation.NSRange, unit NLTokenUnit) foundation.NSRange
}
An interface definition for the NLTagger class.
Creating a tagger ¶
- [INLTagger.InitWithTagSchemes]: Creates a linguistic tagger instance using the specified tag schemes and options.
- [INLTagger.String]: The string being analyzed by the linguistic tagger.
- [INLTagger.SetString]
Getting the tag schemes ¶
- [INLTagger.TagSchemes]: The tag schemes configured for this linguistic tagger.
Determining the dominant language and orthography ¶
- [INLTagger.DominantLanguage]: The dominant language of the string set for the linguistic tagger.
Using models with a tagger ¶
- [INLTagger.SetModelsForTagScheme]: Assigns models for a tag scheme.
- [INLTagger.ModelsForTagScheme]: Returns the models that apply to the given tag scheme.
Using gazetteers with a tagger ¶
- [INLTagger.SetGazetteersForTagScheme]: Attaches gazetteers to a tag scheme, typically one gazetteer per language or one language-independent gazetteer.
- [INLTagger.GazetteersForTagScheme]: Retrieves the gazetteers attached to a tag scheme.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger
type INLTokenizer ¶
type INLTokenizer interface {
objectivec.IObject
// Creates a tokenizer with the specified unit.
InitWithUnit(unit NLTokenUnit) NLTokenizer
// The text to be tokenized.
String() string
SetString(value string)
// Sets the language of the text to be tokenized.
SetLanguage(language NLLanguage)
// The linguistic unit that this tokenizer uses.
Unit() NLTokenUnit
// Enumerates over a given range of the string and calls the specified block for each token.
EnumerateTokensInRangeUsingBlock(range_ foundation.NSRange, block func(unsafe.Pointer, uint64, *bool))
// Finds the range of the token at the given index.
TokenRangeAtIndex(characterIndex uint) foundation.NSRange
// Finds the entire range of all tokens contained completely or partially within the specified range.
TokenRangeForRange(range_ foundation.NSRange) foundation.NSRange
// Tokenizes the string within the provided range.
TokensForRange(range_ foundation.NSRange) []foundation.NSValue
}
An interface definition for the NLTokenizer class.
Creating a tokenizer ¶
- [INLTokenizer.InitWithUnit]: Creates a tokenizer with the specified unit.
Configuring a tokenizer ¶
- [INLTokenizer.String]: The text to be tokenized.
- [INLTokenizer.SetString]
- [INLTokenizer.SetLanguage]: Sets the language of the text to be tokenized.
- [INLTokenizer.Unit]: The linguistic unit that this tokenizer uses.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTokenizer
type NLContextualEmbedding ¶
type NLContextualEmbedding struct {
objectivec.Object
}
A model that computes sequences of embedding vectors for natural language utterances.
Overview ¶
Starting in iOS 17 and macOS 14, the framework supports 27 languages across three models:
- Latin — including Croatian, Czech, Danish, Dutch, English, Finnish, French, German, Hungarian, Indonesian, Italian, Norwegian, Polish, Portuguese, Romanian, Slovak, Swedish, Spanish, Turkish, and Vietnamese - Cyrillic — including Bulgarian, Kazakh, Russian, and Ukrainian - Chinese, Japanese, and Korean
In iOS 18 and macOS 15, the framework expands language support to include three additional models:
- Arabic - Thai - Indic — including Hindi, Marathi, Bangla, Urdu, Punjabi, Gujarati, Tamil, Telugu, Kannada, and Malayalam
Inspecting the contextual embedding ¶
- NLContextualEmbedding.Dimension: The number of dimensions in the script’s vector space.
- NLContextualEmbedding.HasAvailableAssets: A Boolean value that indicates whether assets are available to load.
- NLContextualEmbedding.Languages: The languages of the text in the contextual embedding.
- NLContextualEmbedding.MaximumSequenceLength: The maximum number of embedding vectors the model generates, in sequence.
- NLContextualEmbedding.ModelIdentifier: The model identifier.
- NLContextualEmbedding.Revision: The revision of the contextual embedding.
- NLContextualEmbedding.Scripts: The scripts of the text in the contextual embedding.
Requesting assets ¶
- NLContextualEmbedding.RequestEmbeddingAssetsWithCompletionHandler: Requests assets for an embedding, if available.
Loading and unloading assets ¶
- NLContextualEmbedding.LoadWithError: Loads the embedding model.
- NLContextualEmbedding.Unload: Unloads the embedding model.
Applying an embedding ¶
- NLContextualEmbedding.EmbeddingResultForStringLanguageError: Applies an embedding to a string and obtains the resulting embedding vectors.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbedding
func NLContextualEmbeddingFromID ¶
func NLContextualEmbeddingFromID(id objc.ID) NLContextualEmbedding
NLContextualEmbeddingFromID constructs a NLContextualEmbedding from an objc.ID.
A model that computes sequences of embedding vectors for natural language utterances.
func NewContextualEmbeddingWithLanguage ¶
func NewContextualEmbeddingWithLanguage(language NLLanguage) NLContextualEmbedding
Creates a contextual embedding from a language.
language: The language the framework uses to find the most recent embedding suitable for the value you specify.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbedding/init(language:)
func NewContextualEmbeddingWithModelIdentifier ¶
func NewContextualEmbeddingWithModelIdentifier(modelIdentifier string) NLContextualEmbedding
Creates a contextual embedding from a model identifier.
modelIdentifier: The model identifier that identifies the embedding model.
func NewContextualEmbeddingWithScript ¶
func NewContextualEmbeddingWithScript(script NLScript) NLContextualEmbedding
Creates a contextual embedding from a script.
script: The script the framework uses to find the most recent embedding suitable for the value you specify.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbedding/init(script:)
func NewNLContextualEmbedding ¶
func NewNLContextualEmbedding() NLContextualEmbedding
NewNLContextualEmbedding creates a new NLContextualEmbedding instance.
func (NLContextualEmbedding) Autorelease ¶
func (c NLContextualEmbedding) Autorelease() NLContextualEmbedding
Autorelease adds the receiver to the current autorelease pool.
func (NLContextualEmbedding) Dimension ¶
func (c NLContextualEmbedding) Dimension() uint
The number of dimensions in the script’s vector space.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbedding/dimension
func (NLContextualEmbedding) EmbeddingResultForStringLanguageError ¶
func (c NLContextualEmbedding) EmbeddingResultForStringLanguageError(string_ string, language NLLanguage) (INLContextualEmbeddingResult, error)
Applies an embedding to a string and obtains the resulting embedding vectors.
string: The string to apply an embedding to.
language: The language of the string.
Return Value ¶
An embedding result.
Discussion ¶
If the language of the string is unknown, the framework infers it from the string you specify.
func (NLContextualEmbedding) HasAvailableAssets ¶
func (c NLContextualEmbedding) HasAvailableAssets() bool
A Boolean value that indicates whether assets are available to load.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbedding/hasAvailableAssets
func (NLContextualEmbedding) Init ¶
func (c NLContextualEmbedding) Init() NLContextualEmbedding
Init initializes the instance.
func (NLContextualEmbedding) Languages ¶
func (c NLContextualEmbedding) Languages() []string
The languages of the text in the contextual embedding.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbedding/languages
func (NLContextualEmbedding) LoadWithError ¶
func (c NLContextualEmbedding) LoadWithError() (bool, error)
Loads the embedding model.
Discussion ¶
When you create a contextual embedding, the model isn’t loaded until you need it, by default. Use [LoadWithError] and [Unload] to control when to load and unload the model.
The method fails if the necessary assets — for the model you specify — aren’t on device. Use [HasAvailableAssets] and [RequestEmbeddingAssetsWithCompletionHandler] to manage the assets.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbedding/load()
func (NLContextualEmbedding) MaximumSequenceLength ¶
func (c NLContextualEmbedding) MaximumSequenceLength() uint
The maximum number of embedding vectors the model generates, in sequence.
func (NLContextualEmbedding) ModelIdentifier ¶
func (c NLContextualEmbedding) ModelIdentifier() string
The model identifier.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbedding/modelIdentifier
func (NLContextualEmbedding) RequestEmbeddingAssets ¶
func (c NLContextualEmbedding) RequestEmbeddingAssets(ctx context.Context) (NLContextualEmbeddingAssetsResult, error)
RequestEmbeddingAssets is a synchronous wrapper around NLContextualEmbedding.RequestEmbeddingAssetsWithCompletionHandler. It blocks until the completion handler fires or the context is cancelled.
func (NLContextualEmbedding) RequestEmbeddingAssetsWithCompletionHandler ¶
func (c NLContextualEmbedding) RequestEmbeddingAssetsWithCompletionHandler(completionHandler NLContextualEmbeddingAssetsResultErrorHandler)
Requests assets for an embedding, if available.
completionHandler: A completion handler the system calls after it finishes the request.
Discussion ¶
You use a contextual embedding after loading the necessary assets onto the device. Use [HasAvailableAssets] to determine whether assets are available.
This method returns immediately if the framework knows the state of the assets or if an error occurs.
func (NLContextualEmbedding) Revision ¶
func (c NLContextualEmbedding) Revision() uint
The revision of the contextual embedding.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbedding/revision
func (NLContextualEmbedding) Scripts ¶
func (c NLContextualEmbedding) Scripts() []string
The scripts of the text in the contextual embedding.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbedding/scripts
func (NLContextualEmbedding) Unload ¶
func (c NLContextualEmbedding) Unload()
Unloads the embedding model.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbedding/unload()
type NLContextualEmbeddingAssetsResult ¶
type NLContextualEmbeddingAssetsResult int
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbedding/AssetsResult
const ( // NLContextualEmbeddingAssetsResultAvailable: A result that indicates that the assets are present on-device. NLContextualEmbeddingAssetsResultAvailable NLContextualEmbeddingAssetsResult = 0 // NLContextualEmbeddingAssetsResultError: A result that indicates the framework encounters an error. NLContextualEmbeddingAssetsResultError NLContextualEmbeddingAssetsResult = 2 // NLContextualEmbeddingAssetsResultNotAvailable: A result that indicates that the assets aren’t present on-device. NLContextualEmbeddingAssetsResultNotAvailable NLContextualEmbeddingAssetsResult = 1 )
func (NLContextualEmbeddingAssetsResult) String ¶
func (e NLContextualEmbeddingAssetsResult) String() string
type NLContextualEmbeddingAssetsResultErrorHandler ¶
type NLContextualEmbeddingAssetsResultErrorHandler = func(NLContextualEmbeddingAssetsResult, error)
NLContextualEmbeddingAssetsResultErrorHandler handles A completion handler the system calls after it finishes the request. The error can be type-asserted to *foundation.NSError for Domain, Code, and UserInfo.
Used by:
type NLContextualEmbeddingClass ¶
type NLContextualEmbeddingClass struct {
// contains filtered or unexported fields
}
func GetNLContextualEmbeddingClass ¶
func GetNLContextualEmbeddingClass() NLContextualEmbeddingClass
GetNLContextualEmbeddingClass returns the class object for NLContextualEmbedding.
func (NLContextualEmbeddingClass) Alloc ¶
func (nc NLContextualEmbeddingClass) Alloc() NLContextualEmbedding
Alloc allocates memory for a new instance of the class.
func (NLContextualEmbeddingClass) ContextualEmbeddingsForValues ¶
func (_NLContextualEmbeddingClass NLContextualEmbeddingClass) ContextualEmbeddingsForValues(valuesDictionary foundation.INSDictionary) []NLContextualEmbedding
type NLContextualEmbeddingKey ¶
type NLContextualEmbeddingKey = string
NLContextualEmbeddingKey is contextual embedding keys.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbeddingKey
type NLContextualEmbeddingResult ¶
type NLContextualEmbeddingResult struct {
objectivec.Object
}
An object that represents the embedding vector result from applying a contextual embedding to a string.
Inspecting the result ¶
- NLContextualEmbeddingResult.Language: The resulting language.
- NLContextualEmbeddingResult.SequenceLength: The number of embedding vectors the request generates.
- NLContextualEmbeddingResult.String: The string value.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbeddingResult
func NLContextualEmbeddingResultFromID ¶
func NLContextualEmbeddingResultFromID(id objc.ID) NLContextualEmbeddingResult
NLContextualEmbeddingResultFromID constructs a NLContextualEmbeddingResult from an objc.ID.
An object that represents the embedding vector result from applying a contextual embedding to a string.
func NewNLContextualEmbeddingResult ¶
func NewNLContextualEmbeddingResult() NLContextualEmbeddingResult
NewNLContextualEmbeddingResult creates a new NLContextualEmbeddingResult instance.
func (NLContextualEmbeddingResult) Autorelease ¶
func (c NLContextualEmbeddingResult) Autorelease() NLContextualEmbeddingResult
Autorelease adds the receiver to the current autorelease pool.
func (NLContextualEmbeddingResult) Init ¶
func (c NLContextualEmbeddingResult) Init() NLContextualEmbeddingResult
Init initializes the instance.
func (NLContextualEmbeddingResult) Language ¶
func (c NLContextualEmbeddingResult) Language() NLLanguage
The resulting language.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbeddingResult/language
func (NLContextualEmbeddingResult) SequenceLength ¶
func (c NLContextualEmbeddingResult) SequenceLength() uint
The number of embedding vectors the request generates.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbeddingResult/sequenceLength
func (NLContextualEmbeddingResult) String ¶
func (c NLContextualEmbeddingResult) String() string
The string value.
See: https://developer.apple.com/documentation/NaturalLanguage/NLContextualEmbeddingResult/string
func (NLContextualEmbeddingResult) TokenVectorAtIndexTokenRange ¶
func (c NLContextualEmbeddingResult) TokenVectorAtIndexTokenRange(characterIndex uint, tokenRange foundation.NSRange) []foundation.NSNumber
Returns a token vector at the specified character index.
characterIndex: The index to get the token vector at.
tokenRange: The character range of the token in the input string.
type NLContextualEmbeddingResultClass ¶
type NLContextualEmbeddingResultClass struct {
// contains filtered or unexported fields
}
func GetNLContextualEmbeddingResultClass ¶
func GetNLContextualEmbeddingResultClass() NLContextualEmbeddingResultClass
GetNLContextualEmbeddingResultClass returns the class object for NLContextualEmbeddingResult.
func (NLContextualEmbeddingResultClass) Alloc ¶
func (nc NLContextualEmbeddingResultClass) Alloc() NLContextualEmbeddingResult
Alloc allocates memory for a new instance of the class.
type NLDistance ¶
type NLDistance = float64
NLDistance is the distance between two strings in a text embedding.
See: https://developer.apple.com/documentation/NaturalLanguage/NLDistance
type NLDistanceHandler ¶
type NLDistanceHandler = func(*string)
NLDistanceHandler handles A block with the following parameters:
Used by:
- [NLEmbedding.EnumerateNeighborsForStringMaximumCountDistanceTypeUsingBlock]
- [NLEmbedding.EnumerateNeighborsForStringMaximumCountMaximumDistanceDistanceTypeUsingBlock]
- [NLEmbedding.EnumerateNeighborsForVectorMaximumCountDistanceTypeUsingBlock]
- [NLEmbedding.EnumerateNeighborsForVectorMaximumCountMaximumDistanceDistanceTypeUsingBlock]
type NLDistanceType ¶
type NLDistanceType int
See: https://developer.apple.com/documentation/NaturalLanguage/NLDistanceType
const ( // NLDistanceTypeCosine: A method of calculating distance by using cosine similarity. NLDistanceTypeCosine NLDistanceType = 0 )
func (NLDistanceType) String ¶
func (e NLDistanceType) String() string
type NLEmbedding ¶
type NLEmbedding struct {
objectivec.Object
}
A map of strings to vectors, which locates neighboring, similar strings.
Overview ¶
Use an NLEmbedding to find similar strings based on the proximity of their vectors. The is the entire set of strings in an embedding. Each string in the vocabulary has a vector, which is an array of doubles, and each double corresponds to a dimension in the embedding. An NLEmbedding uses these vectors to determine the distance between two strings, or to find the nearest neighbors of a string in the vocabulary. The higher the similarity of any two strings, the smaller the distance is between them.
Natural Language provides built-in word embeddings that you can retrieve by using the [NLEmbedding.WordEmbeddingForLanguage] method. You can also compile your own custom embedding into an efficient, searchable, on-disk representation. Typically, you compile an embedding by using Create ML’s MLWordEmbedding and save it as a file for your Xcode project at development time. Alternatively, you can compile an embedding at runtime by using Natural Language’s [NLEmbedding.WriteEmbeddingForDictionaryLanguageRevisionToURLError] method.
Your custom embedding can use any kind of string that’s useful to your app, such as phrases, brand names, serial numbers, and so on. For example, you could make an embedding of movie titles. Each movie title could have a vector that places similar movies close together in the embedding.
Inspecting the vocabulary of an embedding ¶
- NLEmbedding.Dimension: The number of dimensions in the vocabulary’s vector space.
- NLEmbedding.VocabularySize: The number of words in the vocabulary.
- NLEmbedding.Language: The language of the text in the word embedding.
- NLEmbedding.ContainsString: Requests a Boolean value that indicates whether the term is in the vocabulary.
- NLEmbedding.Revision: The revision of the word embedding.
See: https://developer.apple.com/documentation/NaturalLanguage/NLEmbedding
func NLEmbeddingFromID ¶
func NLEmbeddingFromID(id objc.ID) NLEmbedding
NLEmbeddingFromID constructs a NLEmbedding from an objc.ID.
A map of strings to vectors, which locates neighboring, similar strings.
func NewEmbeddingWithContentsOfURLError ¶
func NewEmbeddingWithContentsOfURLError(url foundation.INSURL) (NLEmbedding, error)
Creates a word embedding from a model file.
url: The location of the .`mlmodel` file that contains a word embedding.
Discussion ¶
Use this initializer to create a word embedding from an `XCUIElementTypeMlmodel` file saved by Create ML’s MLWordEmbedding.
See: https://developer.apple.com/documentation/NaturalLanguage/NLEmbedding/init(contentsOf:)
func NewNLEmbedding ¶
func NewNLEmbedding() NLEmbedding
NewNLEmbedding creates a new NLEmbedding instance.
func (NLEmbedding) Autorelease ¶
func (e NLEmbedding) Autorelease() NLEmbedding
Autorelease adds the receiver to the current autorelease pool.
func (NLEmbedding) ContainsString ¶
func (e NLEmbedding) ContainsString(string_ string) bool
Requests a Boolean value that indicates whether the term is in the vocabulary.
string: The term to search for in the word embedding.
Return Value ¶
`true` if the term is in the word embedding’s vocabulary, otherwise `false`.
See: https://developer.apple.com/documentation/NaturalLanguage/NLEmbedding/contains(_:)
func (NLEmbedding) Dimension ¶
func (e NLEmbedding) Dimension() uint
The number of dimensions in the vocabulary’s vector space.
See: https://developer.apple.com/documentation/NaturalLanguage/NLEmbedding/dimension
func (NLEmbedding) DistanceBetweenStringAndStringDistanceType ¶
func (e NLEmbedding) DistanceBetweenStringAndStringDistanceType(firstString string, secondString string, distanceType NLDistanceType) NLDistance
Calculates the distance between two strings in the vocabulary space.
firstString: A string in the embedding vocabulary.
secondString: Another string in the embedding vocabulary.
distanceType: A means of calculating distance that determines which formula the method uses to evaluate the distance between `firstString` and `secondString`.
Return Value ¶
The distance associated with `distanceType`.
func (NLEmbedding) GetVectorForString ¶
func (e NLEmbedding) GetVectorForString(string_ string) (float32, bool)
Copies a vector into the given a pointer to a float array.
vector: An array of floats the method copies the vector to. The array’s capacity must be at least [Dimension].
string: The term to find in the word embedding.
Return Value ¶
A Boolean indicating whether the method copied the vector.
See: https://developer.apple.com/documentation/NaturalLanguage/NLEmbedding/getVector:forString:
func (NLEmbedding) Language ¶
func (e NLEmbedding) Language() NLLanguage
The language of the text in the word embedding.
See: https://developer.apple.com/documentation/NaturalLanguage/NLEmbedding/language
func (NLEmbedding) NeighborsForStringMaximumCountDistanceType ¶
func (e NLEmbedding) NeighborsForStringMaximumCountDistanceType(string_ string, maxCount uint, distanceType NLDistanceType) []string
Retrieves a limited number of strings near a string in the vocabulary.
string: A string in the embedding vocabulary.
maxCount: The largest number of neighboring strings that the method can return in an array.
distanceType: A means of calculating distance that determines which formula the method uses to evaluate a neighbor’s distance from `string`.
Return Value ¶
An array of neighboring strings.
func (NLEmbedding) NeighborsForStringMaximumCountMaximumDistanceDistanceType ¶
func (e NLEmbedding) NeighborsForStringMaximumCountMaximumDistanceDistanceType(string_ string, maxCount uint, maxDistance NLDistance, distanceType NLDistanceType) []string
Retrieves a limited number of strings, within a radius of a string, in the vocabulary.
string: A string in the embedding vocabulary.
maxCount: The largest number of neighboring strings that the method can return in an array.
maxDistance: The largest distance a neighbor can be from `string`.
distanceType: A means of calculating distance that determines which formula the method uses to evaluate a neighbor’s distance from `string`.
Return Value ¶
An array of neighboring strings.
func (NLEmbedding) NeighborsForVectorMaximumCountDistanceType ¶
func (e NLEmbedding) NeighborsForVectorMaximumCountDistanceType(vector []foundation.NSNumber, maxCount uint, distanceType NLDistanceType) []string
Retrieves a limited number of strings near a location in the vocabulary space.
vector: A location in the vocabulary space.
maxCount: The largest number of neighboring strings that the method can return in an array.
distanceType: A means of calculating distance that determines which formula the method uses to evaluate a neighbor’s distance from `vector`.
Return Value ¶
An array of tuples that contain neighboring strings and their distances. In Objective-C, this returns an array of neighboring strings.
func (NLEmbedding) NeighborsForVectorMaximumCountMaximumDistanceDistanceType ¶
func (e NLEmbedding) NeighborsForVectorMaximumCountMaximumDistanceDistanceType(vector []foundation.NSNumber, maxCount uint, maxDistance NLDistance, distanceType NLDistanceType) []string
Retrieves a limited number of strings within a radius of a location in the vocabulary space.
vector: A location in the vocabulary space.
maxCount: The largest number of neighboring strings that the method can return in an array.
maxDistance: The largest distance a neighbor can be from `vector`.
distanceType: A means of calculating distance that determines which formula the method uses to evaluate a neighbor’s distance from `vector`.
Return Value ¶
An array of strings.
func (NLEmbedding) Revision ¶
func (e NLEmbedding) Revision() uint
The revision of the word embedding.
See: https://developer.apple.com/documentation/NaturalLanguage/NLEmbedding/revision
func (NLEmbedding) VectorForString ¶
func (e NLEmbedding) VectorForString(string_ string) []foundation.NSNumber
Requests the vector for the given term.
string: The term to find in the word embedding.
Return Value ¶
A vector represented as an array of doubles if present in the word embedding, otherwise `nil`.
See: https://developer.apple.com/documentation/NaturalLanguage/NLEmbedding/vectorForString:
func (NLEmbedding) VocabularySize ¶
func (e NLEmbedding) VocabularySize() uint
The number of words in the vocabulary.
See: https://developer.apple.com/documentation/NaturalLanguage/NLEmbedding/vocabularySize
type NLEmbeddingClass ¶
type NLEmbeddingClass struct {
// contains filtered or unexported fields
}
func GetNLEmbeddingClass ¶
func GetNLEmbeddingClass() NLEmbeddingClass
GetNLEmbeddingClass returns the class object for NLEmbedding.
func (NLEmbeddingClass) Alloc ¶
func (nc NLEmbeddingClass) Alloc() NLEmbedding
Alloc allocates memory for a new instance of the class.
func (NLEmbeddingClass) CurrentRevisionForLanguage ¶
func (_NLEmbeddingClass NLEmbeddingClass) CurrentRevisionForLanguage(language NLLanguage) uint
Retrieves the current version of a word embedding for the given language.
language: A language supported by the Natural Language framework.
Return Value ¶
An integer.
See: https://developer.apple.com/documentation/NaturalLanguage/NLEmbedding/currentRevision(for:)
func (NLEmbeddingClass) CurrentSentenceEmbeddingRevisionForLanguage ¶
func (_NLEmbeddingClass NLEmbeddingClass) CurrentSentenceEmbeddingRevisionForLanguage(language NLLanguage) uint
Retrieves the current version of a sentence embedding for the given language.
language: A language supported by the Natural Language framework. For possible values, see NLLanguage.
Return Value ¶
An integer representing the current version number of a sentence embedding.
func (NLEmbeddingClass) SentenceEmbeddingForLanguage ¶
func (_NLEmbeddingClass NLEmbeddingClass) SentenceEmbeddingForLanguage(language NLLanguage) NLEmbedding
Retrieves a sentence embedding for a given language.
language: The language of the sentence embedding, such as [french]. For possible values, see NLLanguage. // [french]: https://developer.apple.com/documentation/NaturalLanguage/NLLanguage/french
Return Value ¶
An NLEmbedding if available, otherwise `nil`.
See: https://developer.apple.com/documentation/NaturalLanguage/NLEmbedding/sentenceEmbedding(for:)
func (NLEmbeddingClass) SentenceEmbeddingForLanguageRevision ¶
func (_NLEmbeddingClass NLEmbeddingClass) SentenceEmbeddingForLanguageRevision(language NLLanguage, revision uint) NLEmbedding
Retrieves a sentence embedding for a given language and revision.
language: The language of the sentence embedding, such as [french]. For possible values, see NLLanguage. // [french]: https://developer.apple.com/documentation/NaturalLanguage/NLLanguage/french
revision: The revision of the sentence embedding.
Return Value ¶
An NLEmbedding if available, otherwise `nil`.
func (NLEmbeddingClass) SupportedRevisionsForLanguage ¶
func (_NLEmbeddingClass NLEmbeddingClass) SupportedRevisionsForLanguage(language NLLanguage) foundation.NSIndexSet
Retrieves all version numbers of a word embedding for the given language.
language: A language supported by the Natural Language framework.
Return Value ¶
An index set.
See: https://developer.apple.com/documentation/NaturalLanguage/NLEmbedding/supportedRevisions(for:)
func (NLEmbeddingClass) SupportedSentenceEmbeddingRevisionsForLanguage ¶
func (_NLEmbeddingClass NLEmbeddingClass) SupportedSentenceEmbeddingRevisionsForLanguage(language NLLanguage) foundation.NSIndexSet
Retrieves all version numbers of a sentence embedding for the given language.
language: A language supported by the Natural Language framework. For possible values, see NLLanguage.
Return Value ¶
An index set representing all of the supported version numbers of the sentence embedding.
func (NLEmbeddingClass) WordEmbeddingForLanguage ¶
func (_NLEmbeddingClass NLEmbeddingClass) WordEmbeddingForLanguage(language NLLanguage) NLEmbedding
Retrieves a word embedding for a given language.
language: The language of the word embedding, such as [french]. // [french]: https://developer.apple.com/documentation/NaturalLanguage/NLLanguage/french
Return Value ¶
An NLEmbedding if available, otherwise `nil`.
See: https://developer.apple.com/documentation/NaturalLanguage/NLEmbedding/wordEmbedding(for:)
func (NLEmbeddingClass) WordEmbeddingForLanguageRevision ¶
func (_NLEmbeddingClass NLEmbeddingClass) WordEmbeddingForLanguageRevision(language NLLanguage, revision uint) NLEmbedding
Retrieves a word embedding for a given language and revision.
language: The language of the word embedding, such as [french]. // [french]: https://developer.apple.com/documentation/NaturalLanguage/NLLanguage/french
revision: The revision of the word embedding.
Return Value ¶
An NLEmbedding if available, otherwise `nil`.
See: https://developer.apple.com/documentation/NaturalLanguage/NLEmbedding/wordEmbedding(for:revision:)
func (NLEmbeddingClass) WriteEmbeddingForDictionaryLanguageRevisionToURLError ¶
func (_NLEmbeddingClass NLEmbeddingClass) WriteEmbeddingForDictionaryLanguageRevisionToURLError(dictionary foundation.INSDictionary, language NLLanguage, revision uint, url foundation.INSURL) (bool, error)
Exports the word embedding contained within a Core ML model file at the given URL.
dictionary: A dictionary of terms, and their vectors, which are represented by an array of doubles.
language: The language of the text in the word embedding.
revision: The revision of the word embedding.
url: The location in the file system to write the file to.
type NLGazetteer ¶
type NLGazetteer struct {
objectivec.Object
}
A collection of terms and their labels, which take precedence over a word tagger.
Overview ¶
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 [SetGazetteersForTagScheme] 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 NLGazetteer.InitWithDictionaryLanguageError.
Creating a Gazetteer ¶
- NLGazetteer.InitWithContentsOfURLError: Creates a Natural Language gazetteer from a model created with the Create ML framework.
- NLGazetteer.InitWithDataError: Creates a gazetteer from a data instance.
- NLGazetteer.InitWithDictionaryLanguageError: Creates a gazetteer from a set of labels for terms represented by a dictionary.
Looking Up Labels for Terms ¶
- NLGazetteer.LabelForString: Retrieves the label for the given term.
Inspecting a Gazetteer ¶
- NLGazetteer.Data: The gazetteer represented as a data instance.
- NLGazetteer.Language: The language of the gazetteer.
See: https://developer.apple.com/documentation/NaturalLanguage/NLGazetteer
func NLGazetteerFromID ¶
func NLGazetteerFromID(id objc.ID) NLGazetteer
NLGazetteerFromID constructs a NLGazetteer from an objc.ID.
A collection of terms and their labels, which take precedence over a word tagger.
func NewGazetteerWithContentsOfURLError ¶
func NewGazetteerWithContentsOfURLError(url foundation.INSURL) (NLGazetteer, error)
Creates a Natural Language gazetteer from a model created with the Create ML framework.
url: The location of the .`mlmodel` file that contains a gazetteer.
Discussion ¶
Use this initializer to create an NLGazetteer from an `XCUIElementTypeMlmodel` file saved by MLGazetteer in the `Create ML` framework.
See: https://developer.apple.com/documentation/NaturalLanguage/NLGazetteer/init(contentsOf:)
func NewGazetteerWithDataError ¶
func NewGazetteerWithDataError(data foundation.INSData) (NLGazetteer, error)
Creates a gazetteer from a data instance.
data: A gazetteer contained in a data instance.
See: https://developer.apple.com/documentation/NaturalLanguage/NLGazetteer/init(data:)
func NewGazetteerWithDictionaryLanguageError ¶
func NewGazetteerWithDictionaryLanguageError(dictionary foundation.INSDictionary, language NLLanguage) (NLGazetteer, error)
Creates a gazetteer from a set of labels for terms represented by a dictionary.
dictionary: The dictionary of labels and an array of terms for each label.
language: The language of the text in the dictionary.
See: https://developer.apple.com/documentation/NaturalLanguage/NLGazetteer/init(dictionary:language:)
func NewNLGazetteer ¶
func NewNLGazetteer() NLGazetteer
NewNLGazetteer creates a new NLGazetteer instance.
func (NLGazetteer) Autorelease ¶
func (g NLGazetteer) Autorelease() NLGazetteer
Autorelease adds the receiver to the current autorelease pool.
func (NLGazetteer) Data ¶
func (g NLGazetteer) Data() foundation.INSData
The gazetteer represented as a data instance.
See: https://developer.apple.com/documentation/NaturalLanguage/NLGazetteer/data
func (NLGazetteer) InitWithContentsOfURLError ¶
func (g NLGazetteer) InitWithContentsOfURLError(url foundation.INSURL) (NLGazetteer, error)
Creates a Natural Language gazetteer from a model created with the Create ML framework.
url: The location of the .`mlmodel` file that contains a gazetteer.
Discussion ¶
Use this initializer to create an NLGazetteer from an `XCUIElementTypeMlmodel` file saved by MLGazetteer in the `Create ML` framework.
See: https://developer.apple.com/documentation/NaturalLanguage/NLGazetteer/init(contentsOf:)
func (NLGazetteer) InitWithDataError ¶
func (g NLGazetteer) InitWithDataError(data foundation.INSData) (NLGazetteer, error)
Creates a gazetteer from a data instance.
data: A gazetteer contained in a data instance.
See: https://developer.apple.com/documentation/NaturalLanguage/NLGazetteer/init(data:)
func (NLGazetteer) InitWithDictionaryLanguageError ¶
func (g NLGazetteer) InitWithDictionaryLanguageError(dictionary foundation.INSDictionary, language NLLanguage) (NLGazetteer, error)
Creates a gazetteer from a set of labels for terms represented by a dictionary.
dictionary: The dictionary of labels and an array of terms for each label.
language: The language of the text in the dictionary.
See: https://developer.apple.com/documentation/NaturalLanguage/NLGazetteer/init(dictionary:language:)
func (NLGazetteer) LabelForString ¶
func (g NLGazetteer) LabelForString(string_ string) string
Retrieves the label for the given term.
string: The term used to find a label.
Return Value ¶
A string if the term is in the vocabulary; otherwise `nil`.
See: https://developer.apple.com/documentation/NaturalLanguage/NLGazetteer/label(for:)
func (NLGazetteer) Language ¶
func (g NLGazetteer) Language() NLLanguage
The language of the gazetteer.
See: https://developer.apple.com/documentation/NaturalLanguage/NLGazetteer/language
type NLGazetteerClass ¶
type NLGazetteerClass struct {
// contains filtered or unexported fields
}
func GetNLGazetteerClass ¶
func GetNLGazetteerClass() NLGazetteerClass
GetNLGazetteerClass returns the class object for NLGazetteer.
func (NLGazetteerClass) Alloc ¶
func (nc NLGazetteerClass) Alloc() NLGazetteer
Alloc allocates memory for a new instance of the class.
func (NLGazetteerClass) GazetteerWithContentsOfURLError ¶
func (_NLGazetteerClass NLGazetteerClass) GazetteerWithContentsOfURLError(url foundation.INSURL) (NLGazetteer, error)
Creates a Natural Language gazetteer from a model created with the Create ML framework.
url: The location of the .`mlmodel` file that contains a gazetteer.
Discussion ¶
Use this initializer to create an NLGazetteer from an `XCUIElementTypeMlmodel` file saved by MLGazetteer in the `Create ML` framework.
func (NLGazetteerClass) WriteGazetteerForDictionaryLanguageToURLError ¶
func (_NLGazetteerClass NLGazetteerClass) WriteGazetteerForDictionaryLanguageToURLError(dictionary foundation.INSDictionary, language NLLanguage, url foundation.INSURL) (bool, error)
Creates a gazetteer from a set of labels for terms represented by a dictionary and saves the gazetteer to a file.
dictionary: The dictionary of labels and an array of terms for each label.
language: The language of the text in the dictionary.
url: The location in the file system to which the file should be written.
See: https://developer.apple.com/documentation/NaturalLanguage/NLGazetteer/write(_:language:to:)
type NLLanguage ¶
type NLLanguage = string
NLLanguage is the languages that the Natural Language framework supports.
See: https://developer.apple.com/documentation/NaturalLanguage/NLLanguage
type NLLanguageRecognizer ¶
type NLLanguageRecognizer struct {
objectivec.Object
}
The language of a body of text.
Overview ¶
An NLLanguageRecognizer object automatically detects the language of a piece of text. It performs language identification by:
- Identifying the dominant script of a piece of text. Some languages have a unique script (like Greek), but others share the same script (like English, French, and German, which all share the Latin script). - Identifying the language itself.
The identification obtained from an NLLanguageRecognizer object can be either a single most likely language, access through NLLanguageRecognizer.DominantLanguage, or a set of language candidates with probabilities, using NLLanguageRecognizer.LanguageHypothesesWithMaximum. You can reset the recognizer to its initial state, to be reused for new analysis.
Use the convenience method, [NLLanguageRecognizer.DominantLanguageForString], to get the most likely language without creating an NLLanguageRecognizer.
Determining the language ¶
- NLLanguageRecognizer.ProcessString: Analyzes the piece of text to determine its dominant language.
- NLLanguageRecognizer.DominantLanguage: The most likely language for the processed text.
- NLLanguageRecognizer.Reset: Resets the recognizer to its initial state.
Guiding the recognizer ¶
- NLLanguageRecognizer.LanguageConstraints: Limits the set of possible languages that the recognizer will return.
- NLLanguageRecognizer.SetLanguageConstraints
See: https://developer.apple.com/documentation/NaturalLanguage/NLLanguageRecognizer
func NLLanguageRecognizerFromID ¶
func NLLanguageRecognizerFromID(id objc.ID) NLLanguageRecognizer
NLLanguageRecognizerFromID constructs a NLLanguageRecognizer from an objc.ID.
The language of a body of text.
func NewNLLanguageRecognizer ¶
func NewNLLanguageRecognizer() NLLanguageRecognizer
NewNLLanguageRecognizer creates a new NLLanguageRecognizer instance.
func (NLLanguageRecognizer) Autorelease ¶
func (l NLLanguageRecognizer) Autorelease() NLLanguageRecognizer
Autorelease adds the receiver to the current autorelease pool.
func (NLLanguageRecognizer) DominantLanguage ¶
func (l NLLanguageRecognizer) DominantLanguage() NLLanguage
The most likely language for the processed text.
See: https://developer.apple.com/documentation/NaturalLanguage/NLLanguageRecognizer/dominantLanguage
func (NLLanguageRecognizer) Init ¶
func (l NLLanguageRecognizer) Init() NLLanguageRecognizer
Init initializes the instance.
func (NLLanguageRecognizer) LanguageConstraints ¶
func (l NLLanguageRecognizer) LanguageConstraints() []string
Limits the set of possible languages that the recognizer will return.
See: https://developer.apple.com/documentation/NaturalLanguage/NLLanguageRecognizer/languageConstraints
func (NLLanguageRecognizer) LanguageHints ¶
func (l NLLanguageRecognizer) LanguageHints() foundation.INSDictionary
A dictionary that maps languages to their probabilities in the language identification process.
Discussion ¶
This is a dictionary mapping languages to their probabilities and used by [ProcessString].
See: https://developer.apple.com/documentation/NaturalLanguage/NLLanguageRecognizer/languageHints-3gy00
func (NLLanguageRecognizer) LanguageHypothesesWithMaximum ¶
func (l NLLanguageRecognizer) LanguageHypothesesWithMaximum(maxHypotheses uint) foundation.INSDictionary
Generates the probabilities of possible languages for the processed text.
maxHypotheses: The maximum number of languages to return.
Return Value ¶
A dictionary mapping languages with their probabilities, up to `maxHypotheses` languages.
func (NLLanguageRecognizer) ProcessString ¶
func (l NLLanguageRecognizer) ProcessString(string_ string)
Analyzes the piece of text to determine its dominant language.
Discussion ¶
Use this method to process the provided text and to update the [DominantLanguage] result and `languageHypotheses()` probabilities.
See: https://developer.apple.com/documentation/NaturalLanguage/NLLanguageRecognizer/processString(_:)
func (NLLanguageRecognizer) Reset ¶
func (l NLLanguageRecognizer) Reset()
Resets the recognizer to its initial state.
See: https://developer.apple.com/documentation/NaturalLanguage/NLLanguageRecognizer/reset()
func (NLLanguageRecognizer) SetLanguageConstraints ¶
func (l NLLanguageRecognizer) SetLanguageConstraints(value []string)
func (NLLanguageRecognizer) SetLanguageHints ¶
func (l NLLanguageRecognizer) SetLanguageHints(value foundation.INSDictionary)
type NLLanguageRecognizerClass ¶
type NLLanguageRecognizerClass struct {
// contains filtered or unexported fields
}
func GetNLLanguageRecognizerClass ¶
func GetNLLanguageRecognizerClass() NLLanguageRecognizerClass
GetNLLanguageRecognizerClass returns the class object for NLLanguageRecognizer.
func (NLLanguageRecognizerClass) Alloc ¶
func (nc NLLanguageRecognizerClass) Alloc() NLLanguageRecognizer
Alloc allocates memory for a new instance of the class.
func (NLLanguageRecognizerClass) DominantLanguageForString ¶
func (_NLLanguageRecognizerClass NLLanguageRecognizerClass) DominantLanguageForString(string_ string) NLLanguage
Finds the most likely language of a piece of text.
string: The text to analyze.
Return Value ¶
The most probable language of the piece of text.
type NLModel ¶
type NLModel struct {
objectivec.Object
}
A custom model trained to classify or tag natural language text.
Overview ¶
With Natural Language, you can create text classifier (MLTextClassifier) or word tagger (MLWordTagger) models. Use NLModel to integrate those models into your app. This integration ensures that your tokenization and tagger configurations are identical when you train your model and use it in your app.
If you create a text classifier as described in doc:creating-a-text-classifier-model, you can integrate that model into your app and use it to make predictions like this:
If you create a custom word tagger as described in doc:creating-a-word-tagger-model, you can integrate that model into your app and generate tags for new text input like this:
Making predictions ¶
- NLModel.PredictedLabelForString: Predicts a label for the given input string.
- NLModel.PredictedLabelsForTokens: Predicts a label for each string in the given array.
Inspecting a model ¶
- NLModel.Configuration: A configuration describing the natural language model.
See: https://developer.apple.com/documentation/NaturalLanguage/NLModel
func NLModelFromID ¶
NLModelFromID constructs a NLModel from an objc.ID.
A custom model trained to classify or tag natural language text.
func NewModelWithContentsOfURLError ¶
func NewModelWithContentsOfURLError(url foundation.INSURL) (NLModel, error)
Creates a new natural language model based on a compiled Core ML model at the given URL.
url: The location of the Core ML model file in the file system (ending with `XCUIElementTypeMlmodelc`) that’s the basis for this natural language model.
See: https://developer.apple.com/documentation/NaturalLanguage/NLModel/init(contentsOf:)
func NewModelWithMLModelError ¶
Creates a new natural language model based on the given Core ML model instance.
mlModel: A Core ML model instance that’s the basis for this natural language model.
See: https://developer.apple.com/documentation/NaturalLanguage/NLModel/init(mlModel:)
func (NLModel) Autorelease ¶
Autorelease adds the receiver to the current autorelease pool.
func (NLModel) Configuration ¶
func (m NLModel) Configuration() INLModelConfiguration
A configuration describing the natural language model.
See: https://developer.apple.com/documentation/NaturalLanguage/NLModel/configuration
func (NLModel) PredictedLabelForString ¶
Predicts a label for the given input string.
string: The input text for the model to analyze.
Return Value ¶
The model’s predicted label for the input string.
See: https://developer.apple.com/documentation/NaturalLanguage/NLModel/predictedLabel(for:)
func (NLModel) PredictedLabelHypothesesForStringMaximumCount ¶
func (m NLModel) PredictedLabelHypothesesForStringMaximumCount(string_ string, maximumCount uint) foundation.INSDictionary
Predicts multiple possible labels for the given input string.
string: The input string for the model to analyze.
maximumCount: The maximum number of label predictions to return for each input string.
Return Value ¶
A dictionary of label hypotheses. Each dictionary entry is a predicted label with its associated probability score. These labels are the top candidates proposed as possible labels for the input string. The dictionary contains up to `maximumCount` entries.
func (NLModel) PredictedLabelHypothesesForTokensMaximumCount ¶
func (m NLModel) PredictedLabelHypothesesForTokensMaximumCount(tokens []string, maximumCount uint) foundation.INSDictionary
Predicts multiple possible labels for each string in the given array.
tokens: An array of input tokens for the model to analyze.
maximumCount: The maximum number of label predictions to return for each input string.
Return Value ¶
An array of dictionaries. Each dictionary corresponds to the token at the same index in the input array `tokens`. Within each dictionary, each entry is a predicted label with its associated probability score. These labels are the top candidates proposed as possible labels for the token. Each dictionary contains up to `maximumCount` entries.
func (NLModel) PredictedLabelsForTokens ¶
Predicts a label for each string in the given array.
tokens: An array of input strings for the model to analyze.
Return Value ¶
The model’s predicted labels for each of the input strings.
See: https://developer.apple.com/documentation/NaturalLanguage/NLModel/predictedLabels(forTokens:)
type NLModelClass ¶
type NLModelClass struct {
// contains filtered or unexported fields
}
func GetNLModelClass ¶
func GetNLModelClass() NLModelClass
GetNLModelClass returns the class object for NLModel.
func (NLModelClass) Alloc ¶
func (nc NLModelClass) Alloc() NLModel
Alloc allocates memory for a new instance of the class.
type NLModelConfiguration ¶
type NLModelConfiguration struct {
objectivec.Object
}
The configuration parameters of a natural language model.
Accessing the configuration ¶
- NLModelConfiguration.Language: The language the model supports.
- NLModelConfiguration.Revision: The version of the Natural Language framework that trained the model.
- NLModelConfiguration.Type: The natural language model type of the model.
See: https://developer.apple.com/documentation/NaturalLanguage/NLModelConfiguration
func NLModelConfigurationFromID ¶
func NLModelConfigurationFromID(id objc.ID) NLModelConfiguration
NLModelConfigurationFromID constructs a NLModelConfiguration from an objc.ID.
The configuration parameters of a natural language model.
func NewNLModelConfiguration ¶
func NewNLModelConfiguration() NLModelConfiguration
NewNLModelConfiguration creates a new NLModelConfiguration instance.
func (NLModelConfiguration) Autorelease ¶
func (m NLModelConfiguration) Autorelease() NLModelConfiguration
Autorelease adds the receiver to the current autorelease pool.
func (NLModelConfiguration) Configuration ¶
func (m NLModelConfiguration) Configuration() INLModelConfiguration
A configuration describing the natural language model.
See: https://developer.apple.com/documentation/naturallanguage/nlmodel/configuration
func (NLModelConfiguration) EncodeWithCoder ¶
func (m NLModelConfiguration) EncodeWithCoder(coder foundation.INSCoder)
func (NLModelConfiguration) Init ¶
func (m NLModelConfiguration) Init() NLModelConfiguration
Init initializes the instance.
func (NLModelConfiguration) Language ¶
func (m NLModelConfiguration) Language() NLLanguage
The language the model supports.
See: https://developer.apple.com/documentation/NaturalLanguage/NLModelConfiguration/language
func (NLModelConfiguration) Revision ¶
func (m NLModelConfiguration) Revision() uint
The version of the Natural Language framework that trained the model.
See: https://developer.apple.com/documentation/NaturalLanguage/NLModelConfiguration/revision
func (NLModelConfiguration) SetConfiguration ¶
func (m NLModelConfiguration) SetConfiguration(value INLModelConfiguration)
func (NLModelConfiguration) Type ¶
func (m NLModelConfiguration) Type() NLModelType
The natural language model type of the model.
See: https://developer.apple.com/documentation/NaturalLanguage/NLModelConfiguration/type
type NLModelConfigurationClass ¶
type NLModelConfigurationClass struct {
// contains filtered or unexported fields
}
func GetNLModelConfigurationClass ¶
func GetNLModelConfigurationClass() NLModelConfigurationClass
GetNLModelConfigurationClass returns the class object for NLModelConfiguration.
func (NLModelConfigurationClass) Alloc ¶
func (nc NLModelConfigurationClass) Alloc() NLModelConfiguration
Alloc allocates memory for a new instance of the class.
func (NLModelConfigurationClass) CurrentRevisionForType ¶
func (_NLModelConfigurationClass NLModelConfigurationClass) CurrentRevisionForType(type_ NLModelType) uint
Returns the current Natural Language framework version in the OS.
Return Value ¶
A version number.
See: https://developer.apple.com/documentation/NaturalLanguage/NLModelConfiguration/currentRevision(for:)
func (NLModelConfigurationClass) SupportedRevisionsForType ¶
func (_NLModelConfigurationClass NLModelConfigurationClass) SupportedRevisionsForType(type_ NLModelType) foundation.NSIndexSet
Returns the versions of the Natural Language framework the OS supports.
Return Value ¶
An index set of version numbers.
type NLModelType ¶
type NLModelType int
See: https://developer.apple.com/documentation/NaturalLanguage/NLModel/ModelType
const ( // NLModelTypeClassifier: A classifier model type that tags text at the phrase, sentence, paragraph, or higher level. NLModelTypeClassifier NLModelType = 0 // NLModelTypeSequence: A sequence model type that tags text at the token level. NLModelTypeSequence NLModelType = 1 )
func (NLModelType) String ¶
func (e NLModelType) String() string
type NLScript ¶
type NLScript = string
NLScript is the writing scripts that the Natural Language framework supports.
See: https://developer.apple.com/documentation/NaturalLanguage/NLScript
type NLTag ¶
type NLTag = string
NLTag is a token type, lexical class, name, lemma, language, or script returned by a linguistic tagger for natural language text.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTag
type NLTagHandler ¶
type NLTagHandler = func(NLTag)
NLTagHandler handles The block this method uses to iterate over the tagger’s string property.
- tag: The tag of the token.
- tokenRange: The range of the token.
- stop: A reference to a Boolean value. The block can set the value to `true` to stop further processing of the set. The `stop` argument is an out-only argument. You should only ever set this Boolean to `true` within the block.
Used by:
type NLTagScheme ¶
type NLTagScheme = string
NLTagScheme is constants for the tag schemes specified when initializing a linguistic tagger.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagScheme
type NLTagger ¶
type NLTagger struct {
objectivec.Object
}
A tagger that analyzes natural language text.
Overview ¶
NLTagger supports many different languages and scripts. Use it to segment natural language text into paragraph, sentence, or word units and to tag each unit with information like 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 NLTagScheme values. Set the NLTagger.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.
Creating a tagger ¶
- NLTagger.InitWithTagSchemes: Creates a linguistic tagger instance using the specified tag schemes and options.
- NLTagger.String: The string being analyzed by the linguistic tagger.
- NLTagger.SetString
Getting the tag schemes ¶
- NLTagger.TagSchemes: The tag schemes configured for this linguistic tagger.
Determining the dominant language and orthography ¶
- NLTagger.DominantLanguage: The dominant language of the string set for the linguistic tagger.
Using models with a tagger ¶
- NLTagger.SetModelsForTagScheme: Assigns models for a tag scheme.
- NLTagger.ModelsForTagScheme: Returns the models that apply to the given tag scheme.
Using gazetteers with a tagger ¶
- NLTagger.SetGazetteersForTagScheme: Attaches gazetteers to a tag scheme, typically one gazetteer per language or one language-independent gazetteer.
- NLTagger.GazetteersForTagScheme: Retrieves the gazetteers attached to a tag scheme.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger
func NLTaggerFromID ¶
NLTaggerFromID constructs a NLTagger from an objc.ID.
A tagger that analyzes natural language text.
func NewTaggerWithTagSchemes ¶
Creates a linguistic tagger instance using the specified tag schemes and options.
tagSchemes: An array of tag schemes to be used. See NLTagScheme for the possible values.
Discussion ¶
Pass any tag schemes to tagSchemes that you intend to use with the methods described in Enumerating linguistic tags and Getting linguistic tags in NLTagger.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/init(tagSchemes:)
func (NLTagger) Autorelease ¶
Autorelease adds the receiver to the current autorelease pool.
func (NLTagger) DominantLanguage ¶
func (t NLTagger) DominantLanguage() NLLanguage
The dominant language of the string set for the linguistic tagger.
Discussion ¶
If you want to know the dominant language of a string that you’re analyzing with a linguistic tagger (for example, identifying part of speech for each word), specify the language tag scheme in the initializer. After you set the [String] property of the linguistic tagger, the dominant language can be determined with the [DominantLanguage] property, as shown in this example:
In the example, german is the dominant language, indicating that the text is in German.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/dominantLanguage
func (NLTagger) EnumerateTagsInRangeUnitSchemeOptionsUsingBlock ¶
func (t NLTagger) EnumerateTagsInRangeUnitSchemeOptionsUsingBlock(range_ foundation.NSRange, unit NLTokenUnit, scheme NLTagScheme, options NLTaggerOptions, block func(*string, unsafe.Pointer, *bool))
Enumerates a block over the tagger’s string, given a range, token unit, and tag scheme.
range: The range of the string you want the tagger to analyze.
unit: The linguistic unit of scale you’re interested in, such as [TokenUnitWord], [TokenUnitSentence], [TokenUnitParagraph], or [TokenUnitDocument].
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 block. For other tag schemes, see NLTagScheme. // [language]: https://developer.apple.com/documentation/NaturalLanguage/NLTagScheme/language [script]: https://developer.apple.com/documentation/NaturalLanguage/NLTagScheme/script
options: The set of linguistic tagger options to use, such as [TaggerOmitWhitespace]. For all available options, see [NLTagger.Options]. // [NLTagger.Options]: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/Options
block: The block this method uses to iterate over the tagger’s [String] property. The block has the following parameters:
tag: The tag of the token. tokenRange: The range of the token. stop: A reference to a Boolean value. The block can set the value to `true` to stop further processing of the set. The `stop` argument is an out-only argument. You should only ever set this Boolean to `true` within the block.
Discussion ¶
Use this method to iterate your block over the given range of a string. The method divides up the string with the given NLTokenUnit and NLTagScheme and then calls your block. 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.
func (NLTagger) GazetteersForTagScheme ¶
func (t NLTagger) GazetteersForTagScheme(tagScheme NLTagScheme) []NLGazetteer
Retrieves the gazetteers attached to a tag scheme.
tagScheme: The tag scheme for the gazetteers.
Return Value ¶
An array of NLGazetteer.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/gazetteers(for:)
func (NLTagger) InitWithTagSchemes ¶
Creates a linguistic tagger instance using the specified tag schemes and options.
tagSchemes: An array of tag schemes to be used. See NLTagScheme for the possible values.
Discussion ¶
Pass any tag schemes to tagSchemes that you intend to use with the methods described in Enumerating linguistic tags and Getting linguistic tags in NLTagger.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/init(tagSchemes:)
func (NLTagger) ModelsForTagScheme ¶
func (t NLTagger) ModelsForTagScheme(tagScheme NLTagScheme) []NLModel
Returns the models that apply to the given tag scheme.
tagScheme: The tag scheme to filter the list of models with.
Return Value ¶
The array of models that apply to the given tag scheme.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/models(forTagScheme:)
func (NLTagger) SetGazetteersForTagScheme ¶
func (t NLTagger) SetGazetteersForTagScheme(gazetteers []NLGazetteer, tagScheme NLTagScheme)
Attaches gazetteers to a tag scheme, typically one gazetteer per language or one language-independent gazetteer.
gazetteers: The gazetteers to attach to a tag scheme.
tagScheme: The tag scheme for the gazetteers.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/setGazetteers(_:for:)
func (NLTagger) SetLanguageRange ¶
func (t NLTagger) SetLanguageRange(language NLLanguage, range_ foundation.NSRange)
Sets the language for a range of text within the tagger’s string.
language: The language of the text range.
range: The range of the string that is being assigned a language.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/setLanguage:range:
func (NLTagger) SetModelsForTagScheme ¶
func (t NLTagger) SetModelsForTagScheme(models []NLModel, tagScheme NLTagScheme)
Assigns models for a tag scheme.
models: Array of NLModel objects to be used with this tagger.
tagScheme: The tag scheme the models would be used with.
Discussion ¶
An array of models is allowed for the case where multiple models need to be used. For example, when models were trained on specific languages.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/setModels(_:forTagScheme:)
func (NLTagger) SetOrthographyRange ¶
func (t NLTagger) SetOrthographyRange(orthography foundation.NSOrthography, range_ foundation.NSRange)
Sets the orthography for the specified range.
orthography: The orthography for the given range.
range: The range of the string that is being assigned an orthography.
Discussion ¶
If the orthography of the linguistic tagger is not set, it will determine it automatically from the contents of the text. You should call this method only if you know the orthography of the text by some other means.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/setOrthography:range:
func (NLTagger) String ¶
The string being analyzed by the linguistic tagger.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/string
func (NLTagger) TagAtIndexUnitSchemeTokenRange ¶
func (t NLTagger) TagAtIndexUnitSchemeTokenRange(characterIndex uint, unit NLTokenUnit, scheme NLTagScheme, tokenRange foundation.NSRange) NLTag
Finds a tag for a given linguistic unit, for a single scheme, at the specified character position.
characterIndex: The position of the initial character.
unit: The linguistic unit. See NLTokenUnit for possible values. // NLTokenUnit: https://developer.apple.com/documentation/NaturalLanguage/NLTokenUnit
scheme: The tag scheme. See NLTagScheme for possible values.
tokenRange: A pointer to the token range.
Return Value ¶
The tag for the requested tag scheme and linguistic unit, or `nil`. If a tag is returned, this function returns by reference the range of the token to `tokenRange`.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/tagAtIndex:unit:scheme:tokenRange:
func (NLTagger) TagHypothesesAtIndexUnitSchemeMaximumCountTokenRange ¶
func (t NLTagger) TagHypothesesAtIndexUnitSchemeMaximumCountTokenRange(characterIndex uint, unit NLTokenUnit, scheme NLTagScheme, maximumCount uint, tokenRange foundation.NSRange) foundation.INSDictionary
Finds multiple possible tags for a given linguistic unit, for a single scheme, at the specified character position.
unit: The linguistic unit. See NLTokenUnit for possible values. // NLTokenUnit: https://developer.apple.com/documentation/NaturalLanguage/NLTokenUnit
scheme: The tag scheme. See NLTagScheme for possible values. Not all tag schemes produce more than one prediction.
maximumCount: The maximum number of tag predictions to return.
tokenRange: The range of the token for which the tags were produced.
Return Value ¶
A tuple containing a dictionary and a range.
Discussion ¶
Each dictionary entry is a predicted tag with its associated probability score. These tags are the top candidates proposed as possible tags for the token. The dictionary contains up to `maximumCount` entries.
The range contains the range of the individual token for which these tags were produced.
func (NLTagger) TagSchemes ¶
The tag schemes configured for this linguistic tagger.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/tagSchemes
func (NLTagger) TagsInRangeUnitSchemeOptionsTokenRanges ¶
func (t NLTagger) TagsInRangeUnitSchemeOptionsTokenRanges(range_ foundation.NSRange, unit NLTokenUnit, scheme NLTagScheme, options NLTaggerOptions, tokenRanges []foundation.NSValue) []string
Finds an array of linguistic tags and token ranges for a given string range and linguistic unit.
range: The range from which to return tags.
unit: The linguistic unit. See NLTokenUnit for possible values. // NLTokenUnit: https://developer.apple.com/documentation/NaturalLanguage/NLTokenUnit
scheme: The tag scheme. See NLTagScheme for possible values.
options: The linguistic tagger options to use. See [NLTagger.Options] for possible values. // [NLTagger.Options]: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/Options
tokenRanges: Returns by reference an array of token ranges.
Return Value ¶
An array of the tags in the requested range.
Discussion ¶
When the returned array contains an entry that doesn’t have a corresponding tag scheme, that entry is an empty string (””).
func (NLTagger) TokenRangeAtIndexUnit ¶
func (t NLTagger) TokenRangeAtIndexUnit(characterIndex uint, unit NLTokenUnit) foundation.NSRange
Returns the range of the linguistic unit containing the specified character index.
characterIndex: The character index to begin examination.
unit: The linguistic unit. For possible values, see NLTokenUnit. // NLTokenUnit: https://developer.apple.com/documentation/NaturalLanguage/NLTokenUnit
Return Value ¶
The range of the substring for the linguistic unit.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/tokenRangeAtIndex:unit:
func (NLTagger) TokenRangeForRangeUnit ¶
func (t NLTagger) TokenRangeForRangeUnit(range_ foundation.NSRange, unit NLTokenUnit) foundation.NSRange
Finds the entire range of all tokens of the specified linguistic unit contained completely or partially within the specified range.
range: The range within the string to search for tokens.
unit: The linguistic unit. For possible values, see NLTokenUnit. // NLTokenUnit: https://developer.apple.com/documentation/NaturalLanguage/NLTokenUnit
Return Value ¶
The smallest possible range that contains all of the tokens of the specified linguistic unit within the range specified in `range`. This result includes a token’s entire range if any part of that token is included within `range`. If the length of `range` is 0, this return value is equivalent to [TokenRangeAtIndexUnit].
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/tokenRangeForRange:unit:
type NLTaggerAssetsResult ¶
type NLTaggerAssetsResult int
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/AssetsResult
const ( // NLTaggerAssetsResultAvailable: The asset is now available and loaded onto the device. NLTaggerAssetsResultAvailable NLTaggerAssetsResult = 0 // NLTaggerAssetsResultError: The framework couldn’t load the asset due to an error. NLTaggerAssetsResultError NLTaggerAssetsResult = 2 // NLTaggerAssetsResultNotAvailable: The asset is unavailable on the device. NLTaggerAssetsResultNotAvailable NLTaggerAssetsResult = 1 )
func (NLTaggerAssetsResult) String ¶
func (e NLTaggerAssetsResult) String() string
type NLTaggerAssetsResultErrorHandler ¶
type NLTaggerAssetsResultErrorHandler = func(NLTaggerAssetsResult, error)
NLTaggerAssetsResultErrorHandler handles A closure the framework uses to notify your app when the tag scheme request has completed. The error can be type-asserted to *foundation.NSError for Domain, Code, and UserInfo.
Used by:
- [NLTagger.RequestAssetsForLanguageTagSchemeCompletionHandler]
type NLTaggerClass ¶
type NLTaggerClass struct {
// contains filtered or unexported fields
}
func GetNLTaggerClass ¶
func GetNLTaggerClass() NLTaggerClass
GetNLTaggerClass returns the class object for NLTagger.
func (NLTaggerClass) Alloc ¶
func (nc NLTaggerClass) Alloc() NLTagger
Alloc allocates memory for a new instance of the class.
func (NLTaggerClass) AvailableTagSchemesForUnitLanguage ¶
func (_NLTaggerClass NLTaggerClass) AvailableTagSchemesForUnitLanguage(unit NLTokenUnit, language NLLanguage) []string
Retrieves the tag schemes available for a particular unit (like word or sentence) and language on the current device.
unit: The linguistic unit. For possible values, see NLTokenUnit. // NLTokenUnit: https://developer.apple.com/documentation/NaturalLanguage/NLTokenUnit
language: The NLLanguage identifying the language.
Return Value ¶
The supported tag schemes. For possible values, see NLTagScheme.
func (NLTaggerClass) RequestAssetsForLanguageTagScheme ¶
func (tc NLTaggerClass) RequestAssetsForLanguageTagScheme(ctx context.Context, language NLLanguage, tagScheme NLTagScheme) (NLTaggerAssetsResult, error)
RequestAssetsForLanguageTagScheme is a synchronous wrapper around [NLTagger.RequestAssetsForLanguageTagSchemeCompletionHandler]. It blocks until the completion handler fires or the context is cancelled.
func (NLTaggerClass) RequestAssetsForLanguageTagSchemeCompletionHandler ¶
func (_NLTaggerClass NLTaggerClass) RequestAssetsForLanguageTagSchemeCompletionHandler(language NLLanguage, tagScheme NLTagScheme, completionHandler NLTaggerAssetsResultErrorHandler)
Asks the Natural Language framework to load any missing assets for a tag scheme onto the device for the given language.
language: The language of the tag scheme that you’re asking the framework to load onto the device.
tagScheme: The tag scheme that you’re asking the framework to load onto the device.
completionHandler: A closure the framework uses to notify your app when the tag scheme request has completed.
Discussion ¶
Before using this method, use [AvailableTagSchemesForUnitLanguage] to check whether a tag scheme is available on the device. When a tag scheme is unavailable for a specific language, it may be because the framework hasn’t loaded the support for that language.
Use this method to ask the Natural Language framework to load any missing assets for that tag scheme. This method returns immediately but the framework may need time to complete the request. When the framework completes the request, it notifies your app with the `completionHandler` you provided to the method. In your completion handler, use the `result` parameter to check whether the tag scheme is now available.
The Natural Language framework may call your `completionHandler` immediately if it knows the state of the tag scheme’s assets or if it experiences an error.
type NLTaggerOptions ¶
type NLTaggerOptions int
See: https://developer.apple.com/documentation/NaturalLanguage/NLTagger/Options
const ( // NLTaggerJoinContractions: Contractions will be returned as one token. NLTaggerJoinContractions NLTaggerOptions = 32 // NLTaggerJoinNames: Typically, multiple-word names will be returned as multiple tokens, following the standard tokenization practice of the tagger. NLTaggerJoinNames NLTaggerOptions = 16 // NLTaggerOmitOther: Omit tokens of type other (non-linguistic items, such as symbols). NLTaggerOmitOther NLTaggerOptions = 8 // NLTaggerOmitPunctuation: Omit tokens of type punctuation (all punctuation). NLTaggerOmitPunctuation NLTaggerOptions = 2 // NLTaggerOmitWhitespace: Omit tokens of type whitespace (whitespace of all sorts). NLTaggerOmitWhitespace NLTaggerOptions = 4 // NLTaggerOmitWords: Omit tokens of type word (items considered to be words). NLTaggerOmitWords NLTaggerOptions = 1 )
func (NLTaggerOptions) String ¶
func (e NLTaggerOptions) String() string
type NLTokenUnit ¶
type NLTokenUnit int
See: https://developer.apple.com/documentation/NaturalLanguage/NLTokenUnit
const ( // NLTokenUnitDocument: The document in its entirety. NLTokenUnitDocument NLTokenUnit = 3 // NLTokenUnitParagraph: An individual paragraph. NLTokenUnitParagraph NLTokenUnit = 2 // NLTokenUnitSentence: An individual sentence. NLTokenUnitSentence NLTokenUnit = 1 // NLTokenUnitWord: An individual word. NLTokenUnitWord NLTokenUnit = 0 )
func (NLTokenUnit) String ¶
func (e NLTokenUnit) String() string
type NLTokenizer ¶
type NLTokenizer struct {
objectivec.Object
}
A tokenizer that segments natural language text into semantic units.
Overview ¶
NLTokenizer creates individual units from natural language text. Define the desired unit (word, sentence, paragraph, or document as declared in the NLTokenUnit) for tokenization, and then assign a string to tokenize. The NLTokenizer.EnumerateTokensInRangeUsingBlock method provides the ranges of the tokens in the string based on the tokenization unit.
For more information, see Tokenizing natural language text.
Creating a tokenizer ¶
- NLTokenizer.InitWithUnit: Creates a tokenizer with the specified unit.
Configuring a tokenizer ¶
- NLTokenizer.String: The text to be tokenized.
- NLTokenizer.SetString
- NLTokenizer.SetLanguage: Sets the language of the text to be tokenized.
- NLTokenizer.Unit: The linguistic unit that this tokenizer uses.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTokenizer
func NLTokenizerFromID ¶
func NLTokenizerFromID(id objc.ID) NLTokenizer
NLTokenizerFromID constructs a NLTokenizer from an objc.ID.
A tokenizer that segments natural language text into semantic units.
func NewNLTokenizer ¶
func NewNLTokenizer() NLTokenizer
NewNLTokenizer creates a new NLTokenizer instance.
func NewTokenizerWithUnit ¶
func NewTokenizerWithUnit(unit NLTokenUnit) NLTokenizer
Creates a tokenizer with the specified unit.
unit: The level of granularity that the tokenizer operates at.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTokenizer/init(unit:)
func (NLTokenizer) Autorelease ¶
func (t NLTokenizer) Autorelease() NLTokenizer
Autorelease adds the receiver to the current autorelease pool.
func (NLTokenizer) EnumerateTokensInRangeUsingBlock ¶
func (t NLTokenizer) EnumerateTokensInRangeUsingBlock(range_ foundation.NSRange, block func(unsafe.Pointer, uint64, *bool))
Enumerates over a given range of the string and calls the specified block for each token.
range: The range of the string to tokenize.
block: The closure to call after each token; return false if processing should stop.
func (NLTokenizer) InitWithUnit ¶
func (t NLTokenizer) InitWithUnit(unit NLTokenUnit) NLTokenizer
Creates a tokenizer with the specified unit.
unit: The level of granularity that the tokenizer operates at.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTokenizer/init(unit:)
func (NLTokenizer) SetLanguage ¶
func (t NLTokenizer) SetLanguage(language NLLanguage)
Sets the language of the text to be tokenized.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTokenizer/setLanguage(_:)
func (NLTokenizer) SetString ¶
func (t NLTokenizer) SetString(value string)
func (NLTokenizer) String ¶
func (t NLTokenizer) String() string
The text to be tokenized.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTokenizer/string
func (NLTokenizer) TokenRangeAtIndex ¶
func (t NLTokenizer) TokenRangeAtIndex(characterIndex uint) foundation.NSRange
Finds the range of the token at the given index.
Return Value ¶
The range of the token at the given location.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTokenizer/tokenRangeAtIndex:
func (NLTokenizer) TokenRangeForRange ¶
func (t NLTokenizer) TokenRangeForRange(range_ foundation.NSRange) foundation.NSRange
Finds the entire range of all tokens contained completely or partially within the specified range.
range: The range within the string to search for tokens.
Return Value ¶
The smallest possible range that contains all of the tokens within the range specified in `range`. This result includes a token’s entire range if any part of that token is included within `range`. If the length of `range` is 0, this return value is equivalent to [TokenRangeAtIndex].
See: https://developer.apple.com/documentation/NaturalLanguage/NLTokenizer/tokenRangeForRange:
func (NLTokenizer) TokensForRange ¶
func (t NLTokenizer) TokensForRange(range_ foundation.NSRange) []foundation.NSValue
Tokenizes the string within the provided range.
range: The range within the string that should be tokenzied.
Return Value ¶
Returns the ranges corresponding to the tokens for the tokenizer’s unit that intersect the given range.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTokenizer/tokensForRange:
func (NLTokenizer) Unit ¶
func (t NLTokenizer) Unit() NLTokenUnit
The linguistic unit that this tokenizer uses.
See: https://developer.apple.com/documentation/NaturalLanguage/NLTokenizer/unit
type NLTokenizerAttributes ¶
type NLTokenizerAttributes int
See: https://developer.apple.com/documentation/NaturalLanguage/NLTokenizer/Attributes
const ( // NLTokenizerAttributeEmoji: The string contains emoji. NLTokenizerAttributeEmoji NLTokenizerAttributes = 4 // NLTokenizerAttributeNumeric: The string contains numbers. NLTokenizerAttributeNumeric NLTokenizerAttributes = 1 // NLTokenizerAttributeSymbolic: The string contains symbols. NLTokenizerAttributeSymbolic NLTokenizerAttributes = 2 )
func (NLTokenizerAttributes) String ¶
func (e NLTokenizerAttributes) String() string
type NLTokenizerClass ¶
type NLTokenizerClass struct {
// contains filtered or unexported fields
}
func GetNLTokenizerClass ¶
func GetNLTokenizerClass() NLTokenizerClass
GetNLTokenizerClass returns the class object for NLTokenizer.
func (NLTokenizerClass) Alloc ¶
func (nc NLTokenizerClass) Alloc() NLTokenizer
Alloc allocates memory for a new instance of the class.
type RangeHandler ¶
type RangeHandler = func(foundation.NSRange)
RangeHandler handles The closure to call after each token; return false if processing should stop.
Used by:
- [NLContextualEmbeddingResult.EnumerateTokenVectorsInRangeUsingBlock]
- NLTokenizer.EnumerateTokensInRangeUsingBlock
Source Files
¶
- blocks.gen.go
- doc.gen.go
- enums.gen.go
- functions.gen.go
- generate.go
- global_vars.gen.go
- nl_contextual_embedding.gen.go
- nl_contextual_embedding_result.gen.go
- nl_embedding.gen.go
- nl_gazetteer.gen.go
- nl_language_recognizer.gen.go
- nl_model.gen.go
- nl_model_configuration.gen.go
- nl_tagger.gen.go
- nl_tokenizer.gen.go
- typedefs.gen.go
- types.gen.go
- undefined_types.gen.go