JSPM

@sharpapi/sharpapi-node-travel-review-sentiment

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10
  • Score
    100M100P100Q48597F
  • License MIT

SharpAPI.com Node.js SDK for analyzing travel review sentiment

Package Exports

  • @sharpapi/sharpapi-node-travel-review-sentiment
  • @sharpapi/sharpapi-node-travel-review-sentiment/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@sharpapi/sharpapi-node-travel-review-sentiment) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

SharpAPI GitHub cover

Travel Review Sentiment Analyzer API for Node.js

✈️ Analyze travel review sentiment with AI — powered by SharpAPI.

npm version License

SharpAPI Travel Review Sentiment Analyzer uses AI to determine if travel reviews are positive, negative, or neutral with confidence scores. Perfect for hotels, airlines, tour operators, and travel booking platforms.


📋 Table of Contents

  1. Requirements
  2. Installation
  3. Usage
  4. API Documentation
  5. Response Format
  6. Examples
  7. License

Requirements

  • Node.js >= 16.x
  • npm or yarn

Installation

Step 1. Install the package via npm:

npm install @sharpapi/sharpapi-node-travel-review-sentiment

Step 2. Get your API key

Visit SharpAPI.com to get your API key.


Usage

const { SharpApiTravelReviewSentimentService } = require('@sharpapi/sharpapi-node-travel-review-sentiment');

const apiKey = process.env.SHARP_API_KEY;
const service = new SharpApiTravelReviewSentimentService(apiKey);

const review = `
Amazing hotel! The staff was incredibly friendly and helpful.
The room was spacious and clean with a beautiful ocean view.
Would definitely recommend and stay here again!
`;

async function analyzeReview() {
  try {
    const statusUrl = await service.analyzeSentiment(review);
    console.log('Job submitted. Status URL:', statusUrl);

    const result = await service.fetchResults(statusUrl);
    const sentiment = result.getResultJson();

    console.log('Sentiment:', sentiment.opinion);
    console.log('Confidence:', sentiment.score + '%');
  } catch (error) {
    console.error('Error:', error.message);
  }
}

analyzeReview();

API Documentation

Methods

analyzeSentiment(reviewText: string): Promise<string>

Analyzes the sentiment of a travel review.

Parameters:

  • reviewText (string, required): The travel review text to analyze

Returns:

  • Promise: Status URL for polling the job result

Response Format

The API returns sentiment classification with confidence score:

{
  "opinion": "POSITIVE",
  "score": 95,
  "key_aspects": {
    "service": "positive",
    "cleanliness": "positive",
    "location": "positive",
    "value": "neutral"
  },
  "summary": "Highly positive review praising staff, room quality, and views"
}

Sentiment Values:

  • POSITIVE: Review expresses satisfaction or praise
  • NEGATIVE: Review expresses dissatisfaction or criticism
  • NEUTRAL: Review is balanced or factual without strong opinion

Confidence Score:

  • 90-100%: Very high confidence
  • 75-89%: High confidence
  • 60-74%: Moderate confidence
  • Below 60%: Low confidence (review may be ambiguous)

Examples

Basic Sentiment Analysis

const { SharpApiTravelReviewSentimentService } = require('@sharpapi/sharpapi-node-travel-review-sentiment');

const service = new SharpApiTravelReviewSentimentService(process.env.SHARP_API_KEY);

const review = 'The hotel location was great but the room was dirty and noisy.';

service.analyzeSentiment(review)
  .then(statusUrl => service.fetchResults(statusUrl))
  .then(result => {
    const sentiment = result.getResultJson();

    const emoji = sentiment.opinion === 'POSITIVE' ? '😊' :
                  sentiment.opinion === 'NEGATIVE' ? '😞' : '😐';

    console.log(`${emoji} Sentiment: ${sentiment.opinion} (${sentiment.score}% confidence)`);
  })
  .catch(error => console.error('Analysis failed:', error));

Batch Review Analysis for Hotels

const service = new SharpApiTravelReviewSentimentService(process.env.SHARP_API_KEY);

const hotelReviews = [
  { id: 1, text: 'Perfect location! Walking distance to everything.' },
  { id: 2, text: 'Terrible experience. Would not recommend.' },
  { id: 3, text: 'Average hotel. Nothing special but decent value.' },
  { id: 4, text: 'Outstanding service! Best vacation ever!' }
];

async function analyzeAllReviews(reviews) {
  const analyzed = await Promise.all(
    reviews.map(async (review) => {
      const statusUrl = await service.analyzeSentiment(review.text);
      const result = await service.fetchResults(statusUrl);
      const sentiment = result.getResultJson();

      return {
        id: review.id,
        text: review.text,
        sentiment: sentiment.opinion,
        score: sentiment.score
      };
    })
  );

  const positive = analyzed.filter(r => r.sentiment === 'POSITIVE').length;
  const negative = analyzed.filter(r => r.sentiment === 'NEGATIVE').length;
  const neutral = analyzed.filter(r => r.sentiment === 'NEUTRAL').length;

  return {
    total: reviews.length,
    positive,
    negative,
    neutral,
    positiveRate: Math.round((positive / reviews.length) * 100),
    reviews: analyzed
  };
}

const analysis = await analyzeAllReviews(hotelReviews);

console.log('📊 Review Analysis Summary:');
console.log(`Total Reviews: ${analysis.total}`);
console.log(`Positive: ${analysis.positive} (${analysis.positiveRate}%)`);
console.log(`Negative: ${analysis.negative}`);
console.log(`Neutral: ${analysis.neutral}`);

Real-time Review Monitoring

const service = new SharpApiTravelReviewSentimentService(process.env.SHARP_API_KEY);

async function monitorReview(review, alertThreshold = 40) {
  const statusUrl = await service.analyzeSentiment(review.text);
  const result = await service.fetchResults(statusUrl);
  const sentiment = result.getResultJson();

  const alert = {
    reviewId: review.id,
    sentiment: sentiment.opinion,
    score: sentiment.score,
    needsAttention: sentiment.opinion === 'NEGATIVE' && sentiment.score >= 70,
    needsResponse: sentiment.opinion === 'NEGATIVE' && sentiment.score >= 85,
    priority: sentiment.opinion === 'NEGATIVE' ?
              (sentiment.score >= 85 ? 'HIGH' :
               sentiment.score >= 70 ? 'MEDIUM' : 'LOW') :
              'NONE'
  };

  if (alert.needsResponse) {
    console.log(`🚨 URGENT: Negative review detected (${alert.score}%)`);
    console.log(`   Review ID: ${alert.reviewId}`);
    console.log(`   Action: Immediate response required`);
  } else if (alert.needsAttention) {
    console.log(`⚠️  WARNING: Negative feedback detected`);
    console.log(`   Review ID: ${alert.reviewId}`);
    console.log(`   Action: Manager review recommended`);
  }

  return alert;
}

const newReview = {
  id: 'REV-12345',
  text: 'Absolutely terrible. The worst hotel experience ever. Staff was rude and unprofessional.'
};

const alert = await monitorReview(newReview);

Travel Platform Dashboard

const service = new SharpApiTravelReviewSentimentService(process.env.SHARP_API_KEY);

async function generatePropertyInsights(propertyId, reviews) {
  const sentiments = await Promise.all(
    reviews.map(async (review) => {
      const statusUrl = await service.analyzeSentiment(review.text);
      const result = await service.fetchResults(statusUrl);
      return result.getResultJson();
    })
  );

  const positive = sentiments.filter(s => s.opinion === 'POSITIVE');
  const negative = sentiments.filter(s => s.opinion === 'NEGATIVE');
  const avgScore = sentiments.reduce((sum, s) => sum + s.score, 0) / sentiments.length;

  return {
    propertyId,
    totalReviews: reviews.length,
    sentimentBreakdown: {
      positive: positive.length,
      negative: negative.length,
      neutral: sentiments.length - positive.length - negative.length
    },
    averageConfidence: Math.round(avgScore),
    overallRating: positive.length > negative.length ? 'Positive' : 'Negative',
    needsImprovement: negative.length > reviews.length * 0.3,
    recommendation: negative.length > reviews.length * 0.5 ?
      'Critical: Immediate action required' :
      negative.length > reviews.length * 0.3 ?
      'Warning: Address customer concerns' :
      'Good: Maintain current service levels'
  };
}

const propertyReviews = [
  { text: 'Excellent experience!' },
  { text: 'Good value for money.' },
  { text: 'Room was dirty and outdated.' }
];

const insights = await generatePropertyInsights('HOTEL-789', propertyReviews);
console.log('Property Insights:', insights);

Use Cases

  • Hotel Management: Monitor guest satisfaction in real-time
  • Online Travel Agencies: Filter and display reviews by sentiment
  • Tour Operators: Track customer experience across tours
  • Airlines: Analyze passenger feedback and service quality
  • Restaurant Reviews: Understand diner satisfaction trends
  • Reputation Management: Identify and respond to negative feedback quickly
  • Competitive Analysis: Compare sentiment across properties

Travel-Specific Sentiment Analysis

The analyzer evaluates travel-specific factors:

  • Service Quality: Staff friendliness, professionalism
  • Cleanliness: Room and facility cleanliness
  • Location: Accessibility, convenience, safety
  • Value for Money: Price vs. quality perception
  • Amenities: Facilities and services quality
  • Food & Beverage: Dining experience
  • Comfort: Room comfort, noise levels
  • Overall Experience: General satisfaction level

API Endpoint

POST /tth/review_sentiment

For detailed API specifications, refer to:



License

This project is licensed under the MIT License. See the LICENSE.md file for details.


Support


Powered by SharpAPI - AI-Powered API Workflow Automation