2 years ago

#46450

test-img

Hiệp Chelsea

Identifying People, Places, and Organizations in Japanese with NLTagger

I am trying to use the natural language tagger for Japanese. I used this sample code: "https://developer.apple.com/documentation/naturallanguage/identifying_people_places_and_organizations" but it does not recognize names of people or organizations. someone help me! thanks

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
}

ios

swift

pos-tagger

0 Answers

Your Answer

Accepted video resources