Use different language in NLTagger

How can I use different language like simplifiedChinese in NLTagger to get sentimentScore?


Here are my code.

------------

let tagger = NLTagger(tagSchemes: [.sentimentScore])


let input = "I am delightly"


tagger.string = input


let(sentimen, _) = tagger.tag(at:input.startIndex, unit:.paragraph, scheme: .sentimentScore)


print(sentimen ?? 0)

------------


I want to use Chinese instead of English

Replies

I do not practice NL.


I tried this, but got surprising results …

And with simplified Chinese, no result…

I must be missing something, but hopes that will give some hint to the solution.


import NaturalLanguage

let tagger = NLTagger(tagSchemes: [.sentimentScore, .language])
let input = "Je suis très joyeux"// Je suis heureux
// let input = "Wǒ hěn kāixīn"
// let input = "I am delightly"
tagger.string = input

let nsrange = NSRange(location: 0, length: input.count)
let range = Range(nsrange, in: input)!
tagger.setLanguage(.french, range: range as Range) // Replace with .simplifiedChinese

let(sentimen, _) = tagger.tag(at:input.startIndex, unit:.paragraph, scheme: .sentimentScore)

print("NL", sentimen ?? 0)


However, the language ios recognized:


let tagger = NLTagger(tagSchemes: [.sentimentScore, .language])
//let input = "Je suis très joyeux"// Je suis heureux
let input = "Wǒ hěn kāixīn"
// let input = "I am delightly"
tagger.string = input

let nsrange = NSRange(location: 0, length: input.count)
let range = Range(nsrange, in: input)!
tagger.setLanguage(.simplifiedChinese, range: range as Range) // Replace with .simplifiedChinese
let lang = NLLanguageRecognizer.dominantLanguage(for: input)!.rawValue
print("language", lang)

let(sentiment, _) = tagger.tag(at:input.startIndex, unit:.paragraph, scheme: .sentimentScore)
 let score = Double(sentiment?.rawValue ?? "0") ?? 0
 print("Sentiment", score)


gives

language cs

but :

Sentiment 0.0