我正在尝试使用日语的自然语言标注器。我使用了这个示例代码:“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
}
字符串
1条答案
按热度按时间8nuwlpux1#
这是一个老问题,但为了子孙后代,您必须检查一种语言的可用标记方案。举例来说:
字符串
将产生:
型
请注意,
NameType
不可用。