我真的不明白如果我想將其用于法語文本是否需要設(shè)置一些特定的內(nèi)容。我已閱讀 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貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個(gè)贊
語言代碼可以放置在每個(gè)文本文檔中,也可以放置在整個(gè)批次中。analyze_sentiment()
如果您想"fr"
申請(qǐng)所有文件,請(qǐng)將其傳遞到電話中:
response = clientazure.analyze_sentiment(documents = documents, language="fr")
如果只想將語言代碼應(yīng)用于單個(gè)文檔,請(qǐng)?jiān)谖臋n級(jí)別傳遞語言代碼。假設(shè)self.content
包含您要分析的文本,它看起來像這樣:
documents = [{"id": "1", "language": "fr", "text": self.content}]
添加回答
舉報(bào)
0/150
提交
取消