I just visited the language support page of google https://cloud.google.com/natural-language/docs/languages I found the Arabic (ar) is supported in sentiment analysis.
When I try the tutorial they mentioned but with an Arabic sentence, it gives me an error that ar is not a supported language.
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)
Could anyone confirm the support of Arabic or not?
The support for several new languages (Arabic, Dutch, Indonesian, Polish, Thai, Turkish, Vietnamese) that was added on March 20, 2020, has been rolled back. The documentation page about supported languages for the natural language API has been updated and Arabic is no longer in it. So, as of now, Arabic is not supported.
Support for all those languages is expected to come out soon but there is no ETA at the moment.