├── README.md └── sentiment-analysis-id.py /README.md: -------------------------------------------------------------------------------- 1 | Sentiment Analysis Twitter Bahasa Indonesia dengan TextBlob. Diaplikasikan untuk menganalisis tentang topik debat Capres-Cawapres 2019. 2 | Singkatnya, saya bereksperimen dengan translate tweets Bahasa Indonesia ke English agar bisa dianalisis oleh TextBlob. 3 | Ini adalah code untuk tugas tambahan untuk mata kuliah Artificial Intelligence. 4 | 5 | Credits: 6 | [Source code diambil dari Siraj Raval](https://github.com/llSourcell/twitter_sentiment_challenge) 7 | -------------------------------------------------------------------------------- /sentiment-analysis-id.py: -------------------------------------------------------------------------------- 1 | import tweepy 2 | from textblob import TextBlob 3 | 4 | # Step 1 - Authenticate 5 | consumer_key= 'CONSUMER_KEY' 6 | consumer_secret= 'CONSUMER_SECRET' 7 | 8 | access_token='ACCESS_TOKEN' 9 | access_token_secret='ACCESS_TOKEN_SECRET' 10 | 11 | auth = tweepy.OAuthHandler(consumer_key, consumer_secret) 12 | auth.set_access_token(access_token, access_token_secret) 13 | 14 | api = tweepy.API(auth) 15 | 16 | #Step 2 - Retrieve Tweets 17 | public_tweets = api.search(q=['CANDIDATE_NAME', 'DebatCapres2019'], count=100) 18 | 19 | all_polarity = 0 20 | for tweet in public_tweets: 21 | print(tweet.text) 22 | #Step 3 - Perform Sentiment Analysis on Tweets 23 | analysis = TextBlob(tweet.text) 24 | an = analysis.translate(from_lang='id', to='en') 25 | print(an.sentiment) 26 | all_polarity += an.polarity 27 | 28 | print("") 29 | 30 | #Step 4 - To Check Positive or Negative Sentiment from Overall Tweets 31 | if (all_polarity/100 > 0): 32 | print(all_polarity/100) 33 | print("") 34 | print('Positive') 35 | else: 36 | print(all_polarity/100) 37 | print("") 38 | print("Negative") --------------------------------------------------------------------------------