swift 使用NLTagger识别日语中的人物、地点和组织

4ioopgfo  于 2023-08-02  发布在  Swift
关注(0)|答案(1)|浏览(97)

我正在尝试使用日语的自然语言标注器。我使用了这个示例代码:“https://developer.apple.com/documentation/naturallanguage/identifying_people_places_and_organizations”,但它不识别个人或组织的名称。谁来帮帮我!谢谢

let text = "中村千恵子はトヨタ株式会社の社員です。"

let tagger = NLTagger(tagSchemes: [.nameType])
tagger.string = text

let options: NLTagger.Options = [.omitPunctuation, .omitWhitespace, .joinNames]
let tags: [NLTag] = [.personalName, .placeName, .organizationName]

tagger.enumerateTags(in: text.startIndex..<text.endIndex, unit: .word, scheme: .nameType, options: options) { tag, tokenRange in
// Get *the most likely tag, and print it if it's a named entity.
    if let tag = tag, tags.contains(tag) {
        print("\(text[tokenRange]): \(tag.rawValue)")
    }
    
    return true
}

字符串

8nuwlpux

8nuwlpux1#

这是一个老问题,但为了子孙后代,您必须检查一种语言的可用标记方案。举例来说:

let jpSchemes = NLTagger.availableTagSchemes(for: .word, language: .japanese)
print(jpSchemes.map ({ $0.rawValue }))

字符串
将产生:

["Language", "Script", "TokenType"]


请注意,NameType不可用。

相关问题