首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用Google进行阿拉伯语情感分析

用Google进行阿拉伯语情感分析
EN

Stack Overflow用户
提问于 2020-03-24 18:42:27
回答 1查看 182关注 0票数 3

我刚刚访问了google https://cloud.google.com/natural-language/docs/languages的语言支持页面,我发现情感分析支持阿拉伯语(ar)。

当我尝试他们提到的教程,但使用阿拉伯语句子时,它给我一个错误,即ar不是一种受支持的语言。

代码语言:javascript
运行
复制
    from google.cloud import language_v1
    from google.cloud.language_v1 import enums
    import os

    print(os.environ.get('GOOGLE_APPLICATION_CREDENTIALS'))
    def sample_analyze_sentiment(text_content):
        """
        Analyzing Sentiment in a String

        Args:
          text_content The text content to analyze
        """

        client = language_v1.LanguageServiceClient()

        #text_content = 'I am so happy and joyful.'

        # Available types: PLAIN_TEXT, HTML
        type_ = enums.Document.Type.PLAIN_TEXT

        # Optional. If not specified, the language is automatically detected.
        # For list of supported languages:
        # https://cloud.google.com/natural-language/docs/languages
        language = "ar"
        document = {"content": text_content, "type": type_, "language": language}

        # Available values: NONE, UTF8, UTF16, UTF32
        encoding_type = enums.EncodingType.UTF8

        response = client.analyze_sentiment(document, encoding_type=encoding_type)
        # Get overall sentiment of the input document
        print(u"Document sentiment score: {}".format(response.document_sentiment.score))
        print(
            u"Document sentiment magnitude: {}".format(
                response.document_sentiment.magnitude
            )
        )

        # Get sentiment for all sentences in the document
        for sentence in response.sentences:
            print(u"Sentence text: {}".format(sentence.text.content))
            print(u"Sentence sentiment score: {}".format(sentence.sentiment.score))
            print(u"Sentence sentiment magnitude: {}".format(sentence.sentiment.magnitude))

        # Get the language of the text, which will be the same as
        # the language specified in the request or, if not specified,
        # the automatically-detected language.
        print(u"Language of the text: {}".format(response.language))



    text_content = "اهلا وسهلا"

    sample_analyze_sentiment(text_content)

有没有人能确认是否支持阿拉伯语?

EN

回答 1

Stack Overflow用户

发布于 2020-04-22 18:54:06

对几种新语言(阿拉伯语、荷兰语、印尼语、波兰语、泰语、土耳其语、越南语)的支持于2020年3月20日被added,现已回滚。有关自然语言应用编程接口的supported languages的文档页面已经更新,其中不再包含阿拉伯语。因此,到目前为止,还不支持阿拉伯语。

对所有这些语言的支持预计很快就会出来,但目前还没有ETA。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60829422

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档