DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

Your Pipeline Is 20.9h Behind: Catching Law Sentiment Leads with Pulsebit

Your Pipeline Is 20.9h Behind: Catching Law Sentiment Leads with Pulsebit

We just encountered a significant anomaly: a 24-hour momentum spike of +1.045 in sentiment surrounding legal topics. This finding springs from a sharp increase in discourse, particularly in English press coverage, which is currently leading by 20.9 hours. The data reveals a critical gap in our models, especially for those not equipped to handle multilingual origins or dominant entities like Malawi, which holds a 5% share of voice with a negative sentiment score of -0.060.

English coverage led by 20.9 hours. Italian at T+20.9h. Conf
English coverage led by 20.9 hours. Italian at T+20.9h. Confidence scores: English 0.80, Spanish 0.80, Nl 0.80 Source: Pulsebit /sentiment_by_lang.

If your pipeline doesn’t capture these nuances, you may have missed this spike by over 20 hours, severely affecting your responsiveness to emerging trends and narratives.

To illustrate how we can catch such anomalies, let’s dive into some Python code that leverages our API. The goal is to filter by language and sentiment while assessing the narrative surrounding this spike.

import requests

# Define constants
topic = 'law'
score = -0.094
confidence = 0.80
momentum = +1.045

# Step 1: Geographic origin filter
url = "https://api.pulsebit.lojenterprise.com/articles"
params = {
    "lang": "en",
    "topic": topic
}
response = requests.get(url, params=params)
data = response.json()

# Check the response
if response.status_code == 200:
    print("Articles processed:", data['articles_processed'])
else:
    print("Error fetching articles:", response.status_code)

# Step 2: Meta-sentiment moment
cluster_reason = "Clustered by shared themes: lawyer, began, shipwreck, diving, her."
sentiment_url = "https://api.pulsebit.lojenterprise.com/sentiment"
sentiment_response = requests.post(sentiment_url, json={"text": cluster_reason})
sentiment_data = sentiment_response.json()

# Check sentiment response
if sentiment_response.status_code == 200:
    print("Sentiment score of the narrative:", sentiment_data['score'])
else:
    print("Error fetching sentiment:", sentiment_response.status_code)
Enter fullscreen mode Exit fullscreen mode

In this code, we first filter articles by the English language, focusing on the legal domain. The API call retrieves relevant articles, allowing us to study the momentum spike's foundation. Next, we run the cluster reason string through our sentiment analysis endpoint to assess how the narrative frames the conversation. This dual approach ensures we grasp not just the data, but also its context.

Left: Python GET /news_semantic call for 'law'. Right: retur
Left: Python GET /news_semantic call for 'law'. Right: returned JSON response structure (clusters: 3). Source: Pulsebit /news_semantic.

Now that we have a framework for capturing these insights, let's explore three specific builds we can implement based on this spike.

  1. Signal Threshold Monitor: Create a threshold alert when the sentiment score for legal topics drops below a specific level. For instance, set an alert for when the score falls below -0.1, indicating rising negativity. This can be handled with a simple cron job that checks sentiment data every hour.

  2. Geographic Entity Filter: Develop a daily report that filters articles by the key entity 'Malawi' and tracks sentiment changes. Use the existing geographic filter to build a dashboard that visualizes sentiment trends in different regions, which can be instrumental for localized strategies.

Geographic detection output for law. India leads with 16 art
Geographic detection output for law. India leads with 16 articles and sentiment +0.03. Source: Pulsebit /news_recent geographic fields.

  1. Meta-Sentiment Loop: Automate a process that continuously evaluates the narrative surrounding emerging stories, particularly for topics like 'law', 'court', and 'case'. By inputting the cluster reasons into our sentiment endpoint, we can gauge shifts in public perception and adjust our strategies accordingly.

These builds allow us to stay ahead of sentiment trends and better manage our content strategy, especially amidst the backdrop of evolving narratives.

To get started, check out our API documentation at pulsebit.lojenterprise.com/docs. You can copy-paste and run this in under 10 minutes.

Top comments (0)