ios - 在 Swift 中显示 NLTokenizer 的索引、标记

标签 ios swift nltokenizer

我正在使用 NLTokenizer 在 swift Playground 中显示 token 列表。

enter image description here

如何在标记之前显示索引号?

喜欢:

1.Introduction
2.to
3.Natural
4.Language
5.Processing

最佳答案

您可以尝试下面的代码片段。

let text = "Introduction to natural language processing"
let tokenizer = NLTokenizer(unit: .word)
tokenizer.string = text

for (index, range) in tokenizer.tokens(for: text.startIndex..<text.endIndex).enumerated() {
    print("\(index + 1).\(text[range])")
}

关于ios - 在 Swift 中显示 NLTokenizer 的索引、标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59169308/

相关文章:

python - 模块 'tensorflow_datasets.core.features' 没有属性 'text'

ios - 在iOS/OSX上读取带有Windows和Unix行尾的文件

ios - WKWebView 不与状态栏齐平

ios - XCUITesting 权限弹出窗口 : alert appears, 但 UIInterruptionMonitor 未触发

ios - Alamofire 中的错误处理

Xcode 如何更新 Facebook sdk

ios - 如何在 iOS 上的 Swift 中以编程方式获取 UDID

ios - 将模态视图放在 View 上并使背景变灰