简体   繁体   English

azure - Python - 分析法语文本。 法国参数?

[英]azure - Python - Analyse French text. French params?

I don't really understand if I need to set something particular if I want to use it for french text.如果我想将它用于法语文本,我真的不明白是否需要设置一些特定的东西。 I've read the Azure documentation.我已阅读 Azure 文档。 They said to use "fr" code.他们说使用“fr”代码。 But I don't really where to place it.但我真的不知道把它放在哪里。 Do you have any idea?你有什么主意吗?

#Azure lib
from azure.ai.textanalytics import TextAnalyticsClient
from azure.core.credentials import AzureKeyCredential
azurekey = ""
azureendpoint = ""

def authenticate_client():
    ta_credential = AzureKeyCredential(azurekey)
    text_analytics_client = TextAnalyticsClient(
            endpoint=azureendpoint, 
            credential=ta_credential)
    return text_analytics_client

clientazure = 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

The language code can be placed per text document, or for the entire batch.语言代码可以放置在每个文本文档中,也可以放置在整个批次中。 Pass it into the call for analyze_sentiment() if you want "fr" to apply to all documents:如果您希望将"fr"应用于所有文档, analyze_sentiment()其传递到调用analyze_sentiment()

response = clientazure.analyze_sentiment(documents = documents, language="fr")

If only wanting the language code to apply to a single document, pass in the language code at the document level.如果只想将语言代码应用于单个文档,请在文档级别传入语言代码。 Assuming that self.content contains the text you want to analyze, it would look like this:假设self.content包含您要分析的文本,它看起来像这样:

documents = [{"id": "1", "language": "fr", "text": self.content}]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM