Contents

NLTokenUnit.sentence

An individual sentence.

Declaration

case sentence

Discussion

Use this linguistic unit to tokenize text into sentences, like in the following example:

let text = "This is a sentence. This is another sentence."
    
let tokenizer = NLTokenizer(unit: .sentence)
tokenizer.string = text
    
let range = text.startIndex..<text.endIndex
    
let tokenArray = tokenizer.tokens(for: range)
print("Number of tokens: \(tokenArray.count)")
    
tokenizer.enumerateTokens(in: range) { tokenRange, _ in
    print(text[tokenRange])
    return true
}

For more information, see Tokenizing natural language text.

See Also

Constants