我正在使用Apple的NaturalLanguage框架构建一个项目,我尝试用法语执行情感分析,但它肯定无法识别任何单词,但标记器可以识别该语言。这是代码:
func emotionClassification(text: String) -> EmotionalStates {
var numericScore: Double = 0
let tagger = NLTagger(tagSchemes: [.tokenType, .sentimentScore])
tagger.string = text
tagger.enumerateTags(in: text.startIndex..<text.endIndex, unit: .paragraph, scheme: .sentimentScore, options: []) { sentiment, _ in
if let sentimentScore = sentiment {
print(sentimentScore.rawValue)
numericScore = Double(sentimentScore.rawValue) ?? 0
}
return true
}
emotionScore = numericScore
if numericScore <= -0.9 {
return .bad
}
else if numericScore <= -0.5 {
return .worried
}
else if numericScore <= 0.3 {
return .calm
}
else {
return .happy
}
}
“sentimentScore.rawValue”始终为 0.0
Apple 没有在任何地方声称不支持其他语言,所以请帮我解决这个问题。
我尝试标记字符串来检测此代码中的语言,并且它正确定义了它