Skip to content

This Spring Boot application performs sentiment analysis on social media data (Twitter, Facebook, Instagram). It uses OpenAI via Spring AI to analyze the sentiment of each post or comment.

Notifications You must be signed in to change notification settings

wahIndra/social-media-sentiment-analysis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Sentiment Analyzer

This Spring Boot application performs sentiment analysis on social media data (Twitter, Facebook, Instagram). It uses OpenAI via Spring AI to analyze the sentiment of each post or comment.

Features

  • βœ… Analyze tweets (including retweets) by hashtag
  • βœ… Analyze Facebook post comments
  • βœ… Analyze Instagram media comments
  • βœ… Tag sentiment as Positive, Neutral, Negative, or Mixed
  • βœ… Store to H2 in-memory database
  • βœ… Assign town/location based on content text
  • βœ… Multi-tag (topics)
  • βœ… Per-product sentiment classification
  • βœ… REST API to trigger analysis or retrieve results

Setup

1. Prerequisites

  • Java 21+
  • Maven
  • Access tokens:
    • OPENAI_API_KEY
    • TWITTER_BEARER_TOKEN
    • FACEBOOK_ACCESS_TOKEN & PAGE_ID
    • INSTAGRAM_ACCESS_TOKEN & USER_ID

2. Configuration

Set your credentials in src/main/resources/application.yml:

openai:
  api-key: sk-xxx

twitter:
  bearer-token: YOUR_TWITTER_BEARER_TOKEN

facebook:
  page-id: YOUR_PAGE_ID
  access-token: YOUR_ACCESS_TOKEN

instagram:
  user-id: YOUR_USER_ID
  access-token: YOUR_ACCESS_TOKEN

3. Run

./mvnw spring-boot:run

4. Test API

# Analyze tweets by hashtag
curl http://localhost:8080/sentiments/twitter/AI

# Analyze Facebook comments
curl http://localhost:8080/sentiments/facebook

# Analyze Instagram comments
curl http://localhost:8080/sentiments/instagram

# Get all sentiments
curl http://localhost:8080/sentiments

# Filter by location
curl http://localhost:8080/sentiments/location/Jakarta

πŸ’¬ Example

Input:

"The delivery of Product X was excellent, but the support for Product Y was disappointing."

OpenAI Response (Expected):

{
  "sentiment": "Mixed",
  "objectTags": ["Product X", "Product Y"],
  "scopes": ["Delivery", "Support"],
  "products": [
    {"product": "Product X", "sentiment": "Positive"},
    {"product": "Product Y", "sentiment": "Negative"}
  ]
}

Location Extraction:

Location is automatically inferred from text using simple keyword matching (e.g., "Jakarta", "Bandung").

Stored in DB:

  • SocialPost
    • location: "Jakarta"
    • sentiment: "Mixed"
    • objectTags: ["Product X", "Product Y"]
    • scopes: ["Delivery", "Support"]
  • SentimentLabels
    • Product X β†’ Positive
    • Product Y β†’ Negative

About

This Spring Boot application performs sentiment analysis on social media data (Twitter, Facebook, Instagram). It uses OpenAI via Spring AI to analyze the sentiment of each post or comment.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages