Analise a app de sensação geral
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Uma aplicação básica da API Natural Language que realiza a análise de sentimentos em texto.
Explore mais
Para ver documentação detalhada que inclui este exemplo de código, consulte o seguinte:
Exemplo de código
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],[],[],[],null,["A basic Natural Language API application that performs sentiment analysis on text.\n\nExplore further\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Sentiment Analysis Tutorial](/natural-language/docs/sentiment-tutorial)\n\nCode sample \n\nPython\n\n\nTo learn how to install and use the client library for Natural Language, see\n[Natural Language client libraries](/natural-language/docs/reference/libraries).\n\n\nFor more information, see the\n[Natural Language Python API\nreference documentation](/python/docs/reference/language/latest).\n\n\nTo authenticate to Natural Language, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n \"\"\"Demonstrates how to make a simple call to the Natural Language API.\"\"\"\n\n import argparse\n\n from google.cloud import language_v1\n\n\n\n def print_result(annotations):\n score = annotations.document_sentiment.score\n magnitude = annotations.document_sentiment.magnitude\n\n for index, sentence in enumerate(annotations.sentences):\n sentence_sentiment = sentence.sentiment.score\n print(f\"Sentence {index} has a sentiment score of {sentence_sentiment}\")\n\n print(f\"Overall Sentiment: score of {score} with magnitude of {magnitude}\")\n return 0\n\n\n\n\n def analyze(movie_review_filename):\n \"\"\"Run a sentiment analysis request on text within a passed filename.\"\"\"\n client = language_v1.LanguageServiceClient()\n\n with open(movie_review_filename) as review_file:\n # Instantiates a plain text document.\n content = review_file.read()\n\n document = language_v1.Document(\n content=content, type_=language_v1.Document.Type.PLAIN_TEXT\n )\n annotations = client.https://cloud.google.com/python/docs/reference/language/latest/google.cloud.language_v1.services.language_service.LanguageServiceClient.html#google_cloud_language_v1_services_language_service_LanguageServiceClient_analyze_sentiment(request={\"document\": document})\n\n # Print the results\n print_result(annotations)\n\n\n\n\n if __name__ == \"__main__\":\n parser = argparse.ArgumentParser(\n description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter\n )\n parser.add_argument(\n \"movie_review_filename\",\n help=\"The filename of the movie review you'd like to analyze.\",\n )\n args = parser.parse_args()\n\n analyze(args.movie_review_filename)\n\nWhat's next\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=language)."]]