Google 텍스트 감정 분석

구글 감정 분석 가이드 문서를 보고 따라했다.

Install Cloud Natural Language API

pip install --upgrade google-cloud-language
"""Demonstrates how to make a simple call to the Natural Language API."""

import argparse

from import language
from import enums
from import types

def print_result(annotations):
    score = annotations.document_sentiment.score
    magnitude = annotations.document_sentiment.magnitude

    for index, sentence in enumerate(annotations.sentences):
        sentence_sentiment = sentence.sentiment.score
        print('Sentence {} has a sentiment score of {}'.format(
            index, sentence_sentiment))

    print('Overall Sentiment: score of {} with magnitude of {}'.format(
        score, magnitude))
    return 0

def analyze(movie_review_filename):
    """Run a sentiment analysis request on text within a passed filename."""
    client = language.LanguageServiceClient()

    with open(movie_review_filename, 'r') as review_file:
        # Instantiates a plain text document.
        content =

    document = types.Document(
    annotations = client.analyze_sentiment(document=document)

    # Print the results

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        help='The filename of the movie review you\'d like to analyze.')
    args = parser.parse_args()


Leave a Reply

Your email address will not be published. Required fields are marked *