gpt4 book ai didi

python - 使用 Google 进行阿拉伯语情绪分析

转载 作者:行者123 更新时间:2023-12-04 15:32:55 24 4
gpt4 key购买 nike

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

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

    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)

有人可以确认是否支持阿拉伯语吗?

最佳答案

对多种新语言(阿拉伯语、荷兰语、印度尼西亚语、波兰语、泰语、土耳其语、越南语)的支持是 added 2020 年 3 月 20 日,已回滚。关于 supported languages 的文档页面自然语言 API 已更新,不再包含阿拉伯语。因此,截至目前,不支持阿拉伯语。

对所有这些语言的支持预计很快就会出现,但目前没有预计到达时间。

关于python - 使用 Google 进行阿拉伯语情绪分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60829422/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com