我真的不明白如果我想将其用于法语文本是否需要设置一些特定的内容。我已阅读 Azure 文档。他们说使用“fr”代码。但我真的不知道该把它放在哪里。你有什么主意吗?#Azure libfrom azure.ai.textanalytics import TextAnalyticsClientfrom azure.core.credentials import AzureKeyCredentialazurekey = ""azureendpoint = ""def authenticate_client(): ta_credential = AzureKeyCredential(azurekey) text_analytics_client = TextAnalyticsClient( endpoint=azureendpoint, credential=ta_credential) return text_analytics_clientclientazure = authenticate_client()if self.content: documents = [self.content] response = clientazure.analyze_sentiment(documents = documents)[0] try: self.emotion = "sentiment: {}".format(response.sentiment) + " detail: positive={0:.2f}; neutral={1:.2f}; negative={2:.2f} \n".format(response.confidence_scores.positive,response.confidence_scores.neutral,response.confidence_scores.negative,) except Exception as e: self.emotion = None result = clientazure.recognize_entities(documents = documents)[0] for entity in result.entities: try: self.topic = entity.text except Exception as e: self.topic = None try: self.category = entity.category except Exception as e: self.category = None
1 回答
RISEBY
TA贡献1856条经验 获得超5个赞
语言代码可以放置在每个文本文档中,也可以放置在整个批次中。analyze_sentiment()
如果您想"fr"
申请所有文件,请将其传递到电话中:
response = clientazure.analyze_sentiment(documents = documents, language="fr")
如果只想将语言代码应用于单个文档,请在文档级别传递语言代码。假设self.content
包含您要分析的文本,它看起来像这样:
documents = [{"id": "1", "language": "fr", "text": self.content}]
添加回答
举报
0/150
提交
取消