Mac Developer Library

Developer

Foundation Framework Reference NSLinguisticTagger Class Reference

Options
Deployment Target:

On This Page
Language:

NSLinguisticTagger

The NSLinguisticTagger class is used to automatically segment natural-language text and tag it with information, such as parts of speech. It can also tag languages, scripts, stem forms of words, etc. An instance of this class is assigned a string to tag, and clients can then obtain tags and ranges for tokens in that string appropriate to a given tag scheme.

Thread Safety

A given instance of NSLinguisticTagger should not be used from more than one thread simultaneously.

Inheritance


Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in OS X v10.7 and later.
  • Creates a linguistic tagger instance using the specified tag schemes and options.

    Declaration

    Swift

    init(tagSchemes tagSchemes: [AnyObject], options opts: Int)

    Objective-C

    - (instancetype)initWithTagSchemes:(NSArray *)tagSchemes options:(NSUInteger)opts

    Parameters

    tagSchemes

    An array of tag schemes. See Linguistic Tag Schemes for the possible values.

    opts

    The linguistic tagger options to use. See NSLinguisticTaggerOptions for the constants. These constants can be combined using the C-Bitwise OR operator.

    Return Value

    An initialized linguistic tagger.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.

  • The tag schemes configured for this linguistic tagger. (read-only)

    Declaration

    Swift

    var tagSchemes: [AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSArray *tagSchemes

    Discussion

    See Linguistic Tag Schemes for the possible values.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.

  • Returns the tag schemes supported by the linguistic tagger for a particular language.

    Declaration

    Swift

    class func availableTagSchemesForLanguage(_ language: String) -> [AnyObject]

    Objective-C

    + (NSArray *)availableTagSchemesForLanguage:(NSString *)language

    Parameters

    language

    A standard abbreviation as with NSOrthography.

    Return Value

    An array of Linguistic Tag Schemes.

    Discussion

    Clients wishing to know the tag schemes supported for a NSLinguisticTagger instance for a particular language may query them with this method. The language should be specified using a standard abbreviation as with NSOrthography.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.

  • string string Property

    The string being analyzed by the linguistic tagger.

    Declaration

    Swift

    var string: String?

    Objective-C

    @property(retain) NSString *string

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.

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

    Declaration

    Swift

    func stringEditedInRange(_ newCharRange: NSRange, changeInLength delta: Int)

    Objective-C

    - (void)stringEditedInRange:(NSRange)newCharRange changeInLength:(NSInteger)delta

    Parameters

    newCharRange

    The range in the final string that was edited.

    delta

    The change in length.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.

    See Also

    string

  • Sets the orthography for the specified range.

    Declaration

    Swift

    func setOrthography(_ orthography: NSOrthography?, range charRange: NSRange)

    Objective-C

    - (void)setOrthography:(NSOrthography *)orthography range:(NSRange)charRange

    Parameters

    orthography

    The orthography.

    charRange

    The range.

    Discussion

    If the orthography of the linguistic tagger is not set, it will determine it automatically from the contents of the text. Clients should call this method only if they already know the language of the text by some other means.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.

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

    Declaration

    Swift

    func orthographyAtIndex(_ charIndex: Int, effectiveRange effectiveRange: NSRangePointer) -> NSOrthography?

    Objective-C

    - (NSOrthography *)orthographyAtIndex:(NSUInteger)charIndex effectiveRange:(NSRangePointer)effectiveRange

    Parameters

    charIndex

    The character index to begin examination.

    effectiveRange

    An NSRangePointer that, upon completion, contains the range of the orthography containing charIndex.

    Return Value

    The orthography for the location.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.

  • Returns the range of a sentence boundary containing the specified range.

    Declaration

    Swift

    func sentenceRangeForRange(_ charRange: NSRange) -> NSRange

    Objective-C

    - (NSRange)sentenceRangeForRange:(NSRange)charRange

    Parameters

    charRange

    The range.

    Return Value

    Returns the range of a sentence that contains charRange.

    Discussion

    This method can be used to obtain the enclosing sentence range given a token range.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.

  • These constants specify the linguistic tagger options. They can be combined using the C-Bitwise OR operator.

    Declaration

    Swift

    struct NSLinguisticTaggerOptions : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var OmitWords: NSLinguisticTaggerOptions { get } static var OmitPunctuation: NSLinguisticTaggerOptions { get } static var OmitWhitespace: NSLinguisticTaggerOptions { get } static var OmitOther: NSLinguisticTaggerOptions { get } static var JoinNames: NSLinguisticTaggerOptions { get } }

    Objective-C

    enum { NSLinguisticTaggerOmitWords = 1 << 0, NSLinguisticTaggerOmitPunctuation = 1 << 1, NSLinguisticTaggerOmitWhitespace = 1 << 2, NSLinguisticTaggerOmitOther = 1 << 3, NSLinguisticTaggerJoinNames = 1 << 4 }; typedef NSUInteger NSLinguisticTaggerOptions;

    Constants

    • OmitWords

      NSLinguisticTaggerOmitWords

      Omit tokens of type NSLinguisticTagWord (items considered to be words).

      Available in OS X v10.7 and later.

    • OmitPunctuation

      NSLinguisticTaggerOmitPunctuation

      Omit tokens of type NSLinguisticTagPunctuation (all punctuation).

      Available in OS X v10.7 and later.

    • OmitWhitespace

      NSLinguisticTaggerOmitWhitespace

      Omit tokens of type NSLinguisticTagWhitespace (whitespace of all sorts).

      Available in OS X v10.7 and later.

    • OmitOther

      NSLinguisticTaggerOmitOther

      Omit tokens of type NSLinguisticTagOther (non-linguistic items such as symbols).

      Available in OS X v10.7 and later.

    • JoinNames

      NSLinguisticTaggerJoinNames

      Typically, multiple-word names will be returned as multiple tokens, following the standard tokenization practice of the tagger. If this option is set, then multiple-word names will be joined together and returned as a single token.

      Available in OS X v10.7 and later.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in OS X v10.7 and later.

  • These constants specify the linguistic tag schemes used by initWithTagSchemes:options: to create the linguistic tagger instance. The method tagSchemes returns an array of the schemes the instance was created with.

    Declaration

    Swift

    let NSLinguisticTagSchemeTokenType: NSString! let NSLinguisticTagSchemeLexicalClass: NSString! let NSLinguisticTagSchemeNameType: NSString! let NSLinguisticTagSchemeNameTypeOrLexicalClass: NSString! let NSLinguisticTagSchemeLemma: NSString! let NSLinguisticTagSchemeLanguage: NSString! let NSLinguisticTagSchemeScript: NSString!

    Objective-C

    NSString *const NSLinguisticTagSchemeTokenType; NSString *const NSLinguisticTagSchemeLexicalClass; NSString *const NSLinguisticTagSchemeNameType; NSString *const NSLinguisticTagSchemeNameTypeOrLexicalClass; NSString *const NSLinguisticTagSchemeLemma; NSString *const NSLinguisticTagSchemeLanguage; NSString *const NSLinguisticTagSchemeScript;

    Constants

    • NSLinguisticTagSchemeTokenType

      NSLinguisticTagSchemeTokenType

      This tag scheme classifies tokens according to their broad type: word, punctuation, whitespace, etc. The possible tags are: NSLinguisticTagWord, NSLinguisticTagPunctuation, NSLinguisticTagWhitespace, or NSLinguisticTagOther. For this scheme a client may use pointer equality to compare the values with the tag constants.

      Available in OS X v10.7 and later.

    • NSLinguisticTagSchemeLexicalClass

      NSLinguisticTagSchemeLexicalClass

      This tag scheme classifies tokens according to class: part of speech for words, type of punctuation or whitespace, etc. The value will be one of the constants specified in NSLinguisticTagSchemeLexicalClass. For this scheme a client may use pointer equality to compare the values with the tag constants.

      Available in OS X v10.7 and later.

    • NSLinguisticTagSchemeNameType

      NSLinguisticTagSchemeNameType

      This tag scheme classifies tokens as to whether they are part of named entities of various types or not. The possible tags are: NSLinguisticTagPersonalName, NSLinguisticTagPlaceName, or NSLinguisticTagOrganizationName. For this scheme a client may use pointer equality to compare the values with the tag constants.

      Available in OS X v10.7 and later.

    • NSLinguisticTagSchemeNameTypeOrLexicalClass

      NSLinguisticTagSchemeNameTypeOrLexicalClass

      This tag scheme follows NSLinguisticTagSchemeNameType for names, NSLinguisticTagSchemeLexicalClass for all other tokens. The possible tags are those specified in NSLinguisticTagSchemeLexicalClass or NSLinguisticTagSchemeNameType. For this scheme a client may use pointer equality to compare the values with the tag constants.

      Available in OS X v10.7 and later.

    • NSLinguisticTagSchemeLemma

      NSLinguisticTagSchemeLemma

      This tag scheme supplies a stem forms of the words, if known.

      Available in OS X v10.7 and later.

    • NSLinguisticTagSchemeLanguage

      NSLinguisticTagSchemeLanguage

      This tag scheme tags tokens according to their script. The tag values will be standard language abbreviations such as “en”, “fr”, “de”, etc., as used with the NSOrthography class. Note that the tagger generally attempts to determine the language of text at the level of an entire sentence or paragraph, rather than word by word.

      Available in OS X v10.7 and later.

    • NSLinguisticTagSchemeScript

      NSLinguisticTagSchemeScript

      This tag scheme tags tokens according to their script. The tag values will be standard script abbreviations such as “Latn”, “Cyrl”, “Jpan”, “Hans”, “Hant”, etc.

      Available in OS X v10.7 and later.

  • These constants return the linguistic token type according to their broad type.

    Declaration

    Swift

    let NSLinguisticTagWord: NSString! let NSLinguisticTagPunctuation: NSString! let NSLinguisticTagWhitespace: NSString! let NSLinguisticTagOther: NSString!

    Objective-C

    NSString *const NSLinguisticTagWord; NSString *const NSLinguisticTagPunctuation; NSString *const NSLinguisticTagWhitespace; NSString *const NSLinguisticTagOther;

    Constants

    • NSLinguisticTagWord

      NSLinguisticTagWord

      The token indicates a word.

      Available in OS X v10.7 and later.

    • NSLinguisticTagPunctuation

      NSLinguisticTagPunctuation

      The token indicates punctuation.

      Available in OS X v10.7 and later.

    • NSLinguisticTagWhitespace

      NSLinguisticTagWhitespace

      The token indicates white space of any sort.

      Available in OS X v10.7 and later.

    • NSLinguisticTagOther

      NSLinguisticTagOther

      The token indicates a token other than those currently defined.

      Available in OS X v10.7 and later.

  • These constants specify the lexical class of a token.

    Declaration

    Swift

    let NSLinguisticTagNoun: NSString! let NSLinguisticTagVerb: NSString! let NSLinguisticTagAdjective: NSString! let NSLinguisticTagAdverb: NSString! let NSLinguisticTagPronoun: NSString! let NSLinguisticTagDeterminer: NSString! let NSLinguisticTagParticle: NSString! let NSLinguisticTagPreposition: NSString! let NSLinguisticTagNumber: NSString! let NSLinguisticTagConjunction: NSString! let NSLinguisticTagInterjection: NSString! let NSLinguisticTagClassifier: NSString! let NSLinguisticTagIdiom: NSString! let NSLinguisticTagOtherWord: NSString! let NSLinguisticTagSentenceTerminator: NSString! let NSLinguisticTagOpenQuote: NSString! let NSLinguisticTagCloseQuote: NSString! let NSLinguisticTagOpenParenthesis: NSString! let NSLinguisticTagCloseParenthesis: NSString! let NSLinguisticTagWordJoiner: NSString! let NSLinguisticTagDash: NSString! let NSLinguisticTagOtherPunctuation: NSString! let NSLinguisticTagParagraphBreak: NSString! let NSLinguisticTagOtherWhitespace: NSString!

    Objective-C

    NSString *const NSLinguisticTagNoun; NSString *const NSLinguisticTagVerb; NSString *const NSLinguisticTagAdjective; NSString *const NSLinguisticTagAdverb; NSString *const NSLinguisticTagPronoun; NSString *const NSLinguisticTagDeterminer; NSString *const NSLinguisticTagParticle; NSString *const NSLinguisticTagPreposition; NSString *const NSLinguisticTagNumber; NSString *const NSLinguisticTagConjunction; NSString *const NSLinguisticTagInterjection; NSString *const NSLinguisticTagClassifier; NSString *const NSLinguisticTagIdiom; NSString *const NSLinguisticTagOtherWord; NSString *const NSLinguisticTagSentenceTerminator; NSString *const NSLinguisticTagOpenQuote; NSString *const NSLinguisticTagCloseQuote; NSString *const NSLinguisticTagOpenParenthesis; NSString *const NSLinguisticTagCloseParenthesis; NSString *const NSLinguisticTagWordJoiner; NSString *const NSLinguisticTagDash; NSString *const NSLinguisticTagOtherPunctuation; NSString *const NSLinguisticTagParagraphBreak; NSString *const NSLinguisticTagOtherWhitespace;

    Constants

    • NSLinguisticTagNoun

      NSLinguisticTagNoun

      The token is a noun.

      Available in OS X v10.7 and later.

    • NSLinguisticTagVerb

      NSLinguisticTagVerb

      This token is a verb.

      Available in OS X v10.7 and later.

    • NSLinguisticTagAdjective

      NSLinguisticTagAdjective

      This token is an adjective

      Available in OS X v10.7 and later.

    • NSLinguisticTagAdverb

      NSLinguisticTagAdverb

      This token is an adverb.

      Available in OS X v10.7 and later.

    • NSLinguisticTagPronoun

      NSLinguisticTagPronoun

      This token is a pronoun.

      Available in OS X v10.7 and later.

    • NSLinguisticTagDeterminer

      NSLinguisticTagDeterminer

      This token is a determiner.

      Available in OS X v10.7 and later.

    • NSLinguisticTagParticle

      NSLinguisticTagParticle

      This token is a particle.

      Available in OS X v10.7 and later.

    • NSLinguisticTagPreposition

      NSLinguisticTagPreposition

      This token is a preposition.

      Available in OS X v10.7 and later.

    • NSLinguisticTagNumber

      NSLinguisticTagNumber

      This token is a number.

      Available in OS X v10.7 and later.

    • NSLinguisticTagConjunction

      NSLinguisticTagConjunction

      This token is a conjunction.

      Available in OS X v10.7 and later.

    • NSLinguisticTagInterjection

      NSLinguisticTagInterjection

      This token is an interjection.

      Available in OS X v10.7 and later.

    • NSLinguisticTagClassifier

      NSLinguisticTagClassifier

      This token is a classifier.

      Available in OS X v10.7 and later.

    • NSLinguisticTagIdiom

      NSLinguisticTagIdiom

      This token is an idiom.

      Available in OS X v10.7 and later.

    • NSLinguisticTagOtherWord

      NSLinguisticTagOtherWord

      This token is some other word.

      Available in OS X v10.7 and later.

    • NSLinguisticTagSentenceTerminator

      NSLinguisticTagSentenceTerminator

      This token is a sentence terminator.

      Available in OS X v10.7 and later.

    • NSLinguisticTagOpenQuote

      NSLinguisticTagOpenQuote

      This token is an open quote.

      Available in OS X v10.7 and later.

    • NSLinguisticTagCloseQuote

      NSLinguisticTagCloseQuote

      This token is a close quote.

      Available in OS X v10.7 and later.

    • NSLinguisticTagOpenParenthesis

      NSLinguisticTagOpenParenthesis

      This token is an open parenthesis.

      Available in OS X v10.7 and later.

    • NSLinguisticTagCloseParenthesis

      NSLinguisticTagCloseParenthesis

      This token is a close parenthesis.

      Available in OS X v10.7 and later.

    • NSLinguisticTagWordJoiner

      NSLinguisticTagWordJoiner

      This token is a word joiner.

      Available in OS X v10.7 and later.

    • NSLinguisticTagDash

      NSLinguisticTagDash

      This token is a dash.

      Available in OS X v10.7 and later.

    • NSLinguisticTagOtherPunctuation

      NSLinguisticTagOtherPunctuation

      This token is punctuation not recognized as another token type.

      Available in OS X v10.7 and later.

    • NSLinguisticTagParagraphBreak

      NSLinguisticTagParagraphBreak

      This token is a paragraph break.

      Available in OS X v10.7 and later.

    • NSLinguisticTagOtherWhitespace

      NSLinguisticTagOtherWhitespace

      This token is whitespace.

      Available in OS X v10.7 and later.

  • These constants define linguistic tags for specific types of words: people, places, and organizations.

    Declaration

    Swift

    let NSLinguisticTagPersonalName: NSString! let NSLinguisticTagPlaceName: NSString! let NSLinguisticTagOrganizationName: NSString!

    Objective-C

    NSString *const NSLinguisticTagPersonalName; NSString *const NSLinguisticTagPlaceName; NSString *const NSLinguisticTagOrganizationName;

    Constants

    • NSLinguisticTagPersonalName

      NSLinguisticTagPersonalName

      This token is a personal name.

      Available in OS X v10.7 and later.

    • NSLinguisticTagPlaceName

      NSLinguisticTagPlaceName

      This token is a place name.

      Available in OS X v10.7 and later.

    • NSLinguisticTagOrganizationName

      NSLinguisticTagOrganizationName

      This token is an organization name.

      Available in OS X v10.7 and later.