@sharpapi/sharpapi-node-travel-review-sentiment 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +355 -0
- package/package.json +41 -0
- package/src/SharpApiTravelReviewSentimentService.js +21 -0
- package/src/index.js +6 -0
package/README.md
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# Travel Review Sentiment Analyzer API for Node.js
|
|
4
|
+
|
|
5
|
+
## ✈️ Analyze travel review sentiment with AI — powered by SharpAPI.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@sharpapi/sharpapi-node-travel-review-sentiment)
|
|
8
|
+
[](https://github.com/sharpapi/sharpapi-node-client/blob/master/LICENSE.md)
|
|
9
|
+
|
|
10
|
+
**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.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 📋 Table of Contents
|
|
15
|
+
|
|
16
|
+
1. [Requirements](#requirements)
|
|
17
|
+
2. [Installation](#installation)
|
|
18
|
+
3. [Usage](#usage)
|
|
19
|
+
4. [API Documentation](#api-documentation)
|
|
20
|
+
5. [Response Format](#response-format)
|
|
21
|
+
6. [Examples](#examples)
|
|
22
|
+
7. [License](#license)
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Requirements
|
|
27
|
+
|
|
28
|
+
- Node.js >= 16.x
|
|
29
|
+
- npm or yarn
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
### Step 1. Install the package via npm:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install @sharpapi/sharpapi-node-travel-review-sentiment
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Step 2. Get your API key
|
|
42
|
+
|
|
43
|
+
Visit [SharpAPI.com](https://sharpapi.com/) to get your API key.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
const { SharpApiTravelReviewSentimentService } = require('@sharpapi/sharpapi-node-travel-review-sentiment');
|
|
51
|
+
|
|
52
|
+
const apiKey = process.env.SHARP_API_KEY;
|
|
53
|
+
const service = new SharpApiTravelReviewSentimentService(apiKey);
|
|
54
|
+
|
|
55
|
+
const review = `
|
|
56
|
+
Amazing hotel! The staff was incredibly friendly and helpful.
|
|
57
|
+
The room was spacious and clean with a beautiful ocean view.
|
|
58
|
+
Would definitely recommend and stay here again!
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
async function analyzeReview() {
|
|
62
|
+
try {
|
|
63
|
+
const statusUrl = await service.analyzeSentiment(review);
|
|
64
|
+
console.log('Job submitted. Status URL:', statusUrl);
|
|
65
|
+
|
|
66
|
+
const result = await service.fetchResults(statusUrl);
|
|
67
|
+
const sentiment = result.getResultJson();
|
|
68
|
+
|
|
69
|
+
console.log('Sentiment:', sentiment.opinion);
|
|
70
|
+
console.log('Confidence:', sentiment.score + '%');
|
|
71
|
+
} catch (error) {
|
|
72
|
+
console.error('Error:', error.message);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
analyzeReview();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## API Documentation
|
|
82
|
+
|
|
83
|
+
### Methods
|
|
84
|
+
|
|
85
|
+
#### `analyzeSentiment(reviewText: string): Promise<string>`
|
|
86
|
+
|
|
87
|
+
Analyzes the sentiment of a travel review.
|
|
88
|
+
|
|
89
|
+
**Parameters:**
|
|
90
|
+
- `reviewText` (string, required): The travel review text to analyze
|
|
91
|
+
|
|
92
|
+
**Returns:**
|
|
93
|
+
- Promise<string>: Status URL for polling the job result
|
|
94
|
+
|
|
95
|
+
---
|
|
96
|
+
|
|
97
|
+
## Response Format
|
|
98
|
+
|
|
99
|
+
The API returns sentiment classification with confidence score:
|
|
100
|
+
|
|
101
|
+
```json
|
|
102
|
+
{
|
|
103
|
+
"opinion": "POSITIVE",
|
|
104
|
+
"score": 95,
|
|
105
|
+
"key_aspects": {
|
|
106
|
+
"service": "positive",
|
|
107
|
+
"cleanliness": "positive",
|
|
108
|
+
"location": "positive",
|
|
109
|
+
"value": "neutral"
|
|
110
|
+
},
|
|
111
|
+
"summary": "Highly positive review praising staff, room quality, and views"
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Sentiment Values:**
|
|
116
|
+
- `POSITIVE`: Review expresses satisfaction or praise
|
|
117
|
+
- `NEGATIVE`: Review expresses dissatisfaction or criticism
|
|
118
|
+
- `NEUTRAL`: Review is balanced or factual without strong opinion
|
|
119
|
+
|
|
120
|
+
**Confidence Score:**
|
|
121
|
+
- `90-100%`: Very high confidence
|
|
122
|
+
- `75-89%`: High confidence
|
|
123
|
+
- `60-74%`: Moderate confidence
|
|
124
|
+
- `Below 60%`: Low confidence (review may be ambiguous)
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
## Examples
|
|
129
|
+
|
|
130
|
+
### Basic Sentiment Analysis
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
const { SharpApiTravelReviewSentimentService } = require('@sharpapi/sharpapi-node-travel-review-sentiment');
|
|
134
|
+
|
|
135
|
+
const service = new SharpApiTravelReviewSentimentService(process.env.SHARP_API_KEY);
|
|
136
|
+
|
|
137
|
+
const review = 'The hotel location was great but the room was dirty and noisy.';
|
|
138
|
+
|
|
139
|
+
service.analyzeSentiment(review)
|
|
140
|
+
.then(statusUrl => service.fetchResults(statusUrl))
|
|
141
|
+
.then(result => {
|
|
142
|
+
const sentiment = result.getResultJson();
|
|
143
|
+
|
|
144
|
+
const emoji = sentiment.opinion === 'POSITIVE' ? '😊' :
|
|
145
|
+
sentiment.opinion === 'NEGATIVE' ? '😞' : '😐';
|
|
146
|
+
|
|
147
|
+
console.log(`${emoji} Sentiment: ${sentiment.opinion} (${sentiment.score}% confidence)`);
|
|
148
|
+
})
|
|
149
|
+
.catch(error => console.error('Analysis failed:', error));
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Batch Review Analysis for Hotels
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
const service = new SharpApiTravelReviewSentimentService(process.env.SHARP_API_KEY);
|
|
156
|
+
|
|
157
|
+
const hotelReviews = [
|
|
158
|
+
{ id: 1, text: 'Perfect location! Walking distance to everything.' },
|
|
159
|
+
{ id: 2, text: 'Terrible experience. Would not recommend.' },
|
|
160
|
+
{ id: 3, text: 'Average hotel. Nothing special but decent value.' },
|
|
161
|
+
{ id: 4, text: 'Outstanding service! Best vacation ever!' }
|
|
162
|
+
];
|
|
163
|
+
|
|
164
|
+
async function analyzeAllReviews(reviews) {
|
|
165
|
+
const analyzed = await Promise.all(
|
|
166
|
+
reviews.map(async (review) => {
|
|
167
|
+
const statusUrl = await service.analyzeSentiment(review.text);
|
|
168
|
+
const result = await service.fetchResults(statusUrl);
|
|
169
|
+
const sentiment = result.getResultJson();
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
id: review.id,
|
|
173
|
+
text: review.text,
|
|
174
|
+
sentiment: sentiment.opinion,
|
|
175
|
+
score: sentiment.score
|
|
176
|
+
};
|
|
177
|
+
})
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const positive = analyzed.filter(r => r.sentiment === 'POSITIVE').length;
|
|
181
|
+
const negative = analyzed.filter(r => r.sentiment === 'NEGATIVE').length;
|
|
182
|
+
const neutral = analyzed.filter(r => r.sentiment === 'NEUTRAL').length;
|
|
183
|
+
|
|
184
|
+
return {
|
|
185
|
+
total: reviews.length,
|
|
186
|
+
positive,
|
|
187
|
+
negative,
|
|
188
|
+
neutral,
|
|
189
|
+
positiveRate: Math.round((positive / reviews.length) * 100),
|
|
190
|
+
reviews: analyzed
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const analysis = await analyzeAllReviews(hotelReviews);
|
|
195
|
+
|
|
196
|
+
console.log('📊 Review Analysis Summary:');
|
|
197
|
+
console.log(`Total Reviews: ${analysis.total}`);
|
|
198
|
+
console.log(`Positive: ${analysis.positive} (${analysis.positiveRate}%)`);
|
|
199
|
+
console.log(`Negative: ${analysis.negative}`);
|
|
200
|
+
console.log(`Neutral: ${analysis.neutral}`);
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### Real-time Review Monitoring
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
const service = new SharpApiTravelReviewSentimentService(process.env.SHARP_API_KEY);
|
|
207
|
+
|
|
208
|
+
async function monitorReview(review, alertThreshold = 40) {
|
|
209
|
+
const statusUrl = await service.analyzeSentiment(review.text);
|
|
210
|
+
const result = await service.fetchResults(statusUrl);
|
|
211
|
+
const sentiment = result.getResultJson();
|
|
212
|
+
|
|
213
|
+
const alert = {
|
|
214
|
+
reviewId: review.id,
|
|
215
|
+
sentiment: sentiment.opinion,
|
|
216
|
+
score: sentiment.score,
|
|
217
|
+
needsAttention: sentiment.opinion === 'NEGATIVE' && sentiment.score >= 70,
|
|
218
|
+
needsResponse: sentiment.opinion === 'NEGATIVE' && sentiment.score >= 85,
|
|
219
|
+
priority: sentiment.opinion === 'NEGATIVE' ?
|
|
220
|
+
(sentiment.score >= 85 ? 'HIGH' :
|
|
221
|
+
sentiment.score >= 70 ? 'MEDIUM' : 'LOW') :
|
|
222
|
+
'NONE'
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
if (alert.needsResponse) {
|
|
226
|
+
console.log(`🚨 URGENT: Negative review detected (${alert.score}%)`);
|
|
227
|
+
console.log(` Review ID: ${alert.reviewId}`);
|
|
228
|
+
console.log(` Action: Immediate response required`);
|
|
229
|
+
} else if (alert.needsAttention) {
|
|
230
|
+
console.log(`⚠️ WARNING: Negative feedback detected`);
|
|
231
|
+
console.log(` Review ID: ${alert.reviewId}`);
|
|
232
|
+
console.log(` Action: Manager review recommended`);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return alert;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const newReview = {
|
|
239
|
+
id: 'REV-12345',
|
|
240
|
+
text: 'Absolutely terrible. The worst hotel experience ever. Staff was rude and unprofessional.'
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
const alert = await monitorReview(newReview);
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Travel Platform Dashboard
|
|
247
|
+
|
|
248
|
+
```javascript
|
|
249
|
+
const service = new SharpApiTravelReviewSentimentService(process.env.SHARP_API_KEY);
|
|
250
|
+
|
|
251
|
+
async function generatePropertyInsights(propertyId, reviews) {
|
|
252
|
+
const sentiments = await Promise.all(
|
|
253
|
+
reviews.map(async (review) => {
|
|
254
|
+
const statusUrl = await service.analyzeSentiment(review.text);
|
|
255
|
+
const result = await service.fetchResults(statusUrl);
|
|
256
|
+
return result.getResultJson();
|
|
257
|
+
})
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
const positive = sentiments.filter(s => s.opinion === 'POSITIVE');
|
|
261
|
+
const negative = sentiments.filter(s => s.opinion === 'NEGATIVE');
|
|
262
|
+
const avgScore = sentiments.reduce((sum, s) => sum + s.score, 0) / sentiments.length;
|
|
263
|
+
|
|
264
|
+
return {
|
|
265
|
+
propertyId,
|
|
266
|
+
totalReviews: reviews.length,
|
|
267
|
+
sentimentBreakdown: {
|
|
268
|
+
positive: positive.length,
|
|
269
|
+
negative: negative.length,
|
|
270
|
+
neutral: sentiments.length - positive.length - negative.length
|
|
271
|
+
},
|
|
272
|
+
averageConfidence: Math.round(avgScore),
|
|
273
|
+
overallRating: positive.length > negative.length ? 'Positive' : 'Negative',
|
|
274
|
+
needsImprovement: negative.length > reviews.length * 0.3,
|
|
275
|
+
recommendation: negative.length > reviews.length * 0.5 ?
|
|
276
|
+
'Critical: Immediate action required' :
|
|
277
|
+
negative.length > reviews.length * 0.3 ?
|
|
278
|
+
'Warning: Address customer concerns' :
|
|
279
|
+
'Good: Maintain current service levels'
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const propertyReviews = [
|
|
284
|
+
{ text: 'Excellent experience!' },
|
|
285
|
+
{ text: 'Good value for money.' },
|
|
286
|
+
{ text: 'Room was dirty and outdated.' }
|
|
287
|
+
];
|
|
288
|
+
|
|
289
|
+
const insights = await generatePropertyInsights('HOTEL-789', propertyReviews);
|
|
290
|
+
console.log('Property Insights:', insights);
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## Use Cases
|
|
296
|
+
|
|
297
|
+
- **Hotel Management**: Monitor guest satisfaction in real-time
|
|
298
|
+
- **Online Travel Agencies**: Filter and display reviews by sentiment
|
|
299
|
+
- **Tour Operators**: Track customer experience across tours
|
|
300
|
+
- **Airlines**: Analyze passenger feedback and service quality
|
|
301
|
+
- **Restaurant Reviews**: Understand diner satisfaction trends
|
|
302
|
+
- **Reputation Management**: Identify and respond to negative feedback quickly
|
|
303
|
+
- **Competitive Analysis**: Compare sentiment across properties
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## Travel-Specific Sentiment Analysis
|
|
308
|
+
|
|
309
|
+
The analyzer evaluates travel-specific factors:
|
|
310
|
+
|
|
311
|
+
- **Service Quality**: Staff friendliness, professionalism
|
|
312
|
+
- **Cleanliness**: Room and facility cleanliness
|
|
313
|
+
- **Location**: Accessibility, convenience, safety
|
|
314
|
+
- **Value for Money**: Price vs. quality perception
|
|
315
|
+
- **Amenities**: Facilities and services quality
|
|
316
|
+
- **Food & Beverage**: Dining experience
|
|
317
|
+
- **Comfort**: Room comfort, noise levels
|
|
318
|
+
- **Overall Experience**: General satisfaction level
|
|
319
|
+
|
|
320
|
+
---
|
|
321
|
+
|
|
322
|
+
## API Endpoint
|
|
323
|
+
|
|
324
|
+
**POST** `/tth/review_sentiment`
|
|
325
|
+
|
|
326
|
+
For detailed API specifications, refer to:
|
|
327
|
+
- [Postman Documentation](https://documenter.getpostman.com/view/31106842/2sBXVeGsVf)
|
|
328
|
+
- [Product Page](https://sharpapi.com/en/catalog/ai/travel-tourism-hospitality/travel-review-sentiment-checker)
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
## Related Packages
|
|
333
|
+
|
|
334
|
+
- [@sharpapi/sharpapi-node-product-review-sentiment](https://www.npmjs.com/package/@sharpapi/sharpapi-node-product-review-sentiment) - Product review sentiment
|
|
335
|
+
- [@sharpapi/sharpapi-node-hospitality-categories](https://www.npmjs.com/package/@sharpapi/sharpapi-node-hospitality-categories) - Hospitality categorization
|
|
336
|
+
- [@sharpapi/sharpapi-node-detect-spam](https://www.npmjs.com/package/@sharpapi/sharpapi-node-detect-spam) - Spam detection
|
|
337
|
+
- [@sharpapi/sharpapi-node-client](https://www.npmjs.com/package/@sharpapi/sharpapi-node-client) - Full SharpAPI SDK
|
|
338
|
+
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## License
|
|
342
|
+
|
|
343
|
+
This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## Support
|
|
348
|
+
|
|
349
|
+
- **Documentation**: [SharpAPI.com Documentation](https://sharpapi.com/documentation)
|
|
350
|
+
- **Issues**: [GitHub Issues](https://github.com/sharpapi/sharpapi-node-client/issues)
|
|
351
|
+
- **Email**: contact@sharpapi.com
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
**Powered by [SharpAPI](https://sharpapi.com/) - AI-Powered API Workflow Automation**
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sharpapi/sharpapi-node-travel-review-sentiment",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "SharpAPI.com Node.js SDK for analyzing travel review sentiment",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "jest"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"sharpapi",
|
|
11
|
+
"ai-powered",
|
|
12
|
+
"ai capabilities",
|
|
13
|
+
"api",
|
|
14
|
+
"ai api",
|
|
15
|
+
"api integration",
|
|
16
|
+
"artificial intelligence",
|
|
17
|
+
"natural language processing",
|
|
18
|
+
"restful api",
|
|
19
|
+
"nodejs",
|
|
20
|
+
"software development",
|
|
21
|
+
"travel",
|
|
22
|
+
"tourism",
|
|
23
|
+
"hospitality",
|
|
24
|
+
"sentiment analysis"
|
|
25
|
+
],
|
|
26
|
+
"author": "Dawid Makowski <contact@sharpapi.com>",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@sharpapi/sharpapi-node-core": "file:../sharpapi-node-core"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"jest": "^29.7.0"
|
|
33
|
+
},
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/sharpapi/sharpapi-node-travel-review-sentiment.git"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const { SharpApiCoreService, SharpApiJobTypeEnum } = require('@sharpapi/sharpapi-node-core');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Service for analyzing travel review sentiment using SharpAPI.com
|
|
5
|
+
*/
|
|
6
|
+
class SharpApiTravelReviewSentimentService extends SharpApiCoreService {
|
|
7
|
+
/**
|
|
8
|
+
* Parses the Travel/Hospitality product review and provides its sentiment (POSITIVE/NEGATIVE/NEUTRAL)
|
|
9
|
+
* with a score between 0-100%. Great for sentiment report processing for any online store.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} text
|
|
12
|
+
* @returns {Promise<string>} - The status URL.
|
|
13
|
+
*/
|
|
14
|
+
async travelReviewSentiment(text) {
|
|
15
|
+
const data = { content: text };
|
|
16
|
+
const response = await this.makeRequest('POST', SharpApiJobTypeEnum.TTH_REVIEW_SENTIMENT.url, data);
|
|
17
|
+
return this.parseStatusUrl(response);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = { SharpApiTravelReviewSentimentService };
|