简体   繁体   中英

How to add names to NSLinguisticTagger?

I'm currently doing work with people using speech recognition and detecting names in speech. This works well however I'm having issues with names. I'm in Wales and many people around have Welsh names (including me). I have a CSV of all the Welsh Names. Some names are also being picked up as Places (like Osian) Is there a way to extend the NSLinguisticTagger to include Welsh Names? Or is there a way of detecting the Welsh name?

Here is my current code:

let text = "Hey I'm Osian"

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

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

// 3
tagger.enumerateTags(in: text.startIndex..<text.endIndex, unit: .word, scheme: .nameType, options: options) { tag, tokenRange in
    if let tag = tag, tags.contains(tag) {
        print("\(text[tokenRange]): \(tag.rawValue)")
    }
    return true
}

Normally you need to set the dominant language. But it appears that Welsh is not supported. See: https://developer.apple.com/documentation/naturallanguage/nllanguage?language=objc

My guess is best approach is to set dominant language a close as possible, then train a model as discussed by others.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM