我真的不明白如果我想將其用于法語文本是否需要設置一些特定的內容。我已閱讀 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
提交
取消