@sharpapi/sharpapi-node-hospitality-categories 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 +361 -0
- package/package.json +42 -0
- package/src/SharpApiHospitalityCategoriesService.js +36 -0
- package/src/index.js +6 -0
package/README.md
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# Hospitality Product Categorization API for Node.js
|
|
4
|
+
|
|
5
|
+
## 🏨 Automatically categorize hospitality products with AI — powered by SharpAPI.
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@sharpapi/sharpapi-node-hospitality-categories)
|
|
8
|
+
[](https://github.com/sharpapi/sharpapi-node-client/blob/master/LICENSE.md)
|
|
9
|
+
|
|
10
|
+
**SharpAPI Hospitality Product Categorization** uses AI to automatically categorize hotels, resorts, vacation rentals, and other hospitality products based on their descriptions. Perfect for travel platforms, booking systems, and hospitality management tools.
|
|
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-hospitality-categories
|
|
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 { SharpApiHospitalityCategoriesService } = require('@sharpapi/sharpapi-node-hospitality-categories');
|
|
51
|
+
|
|
52
|
+
const apiKey = process.env.SHARP_API_KEY;
|
|
53
|
+
const service = new SharpApiHospitalityCategoriesService(apiKey);
|
|
54
|
+
|
|
55
|
+
const propertyDescription = `
|
|
56
|
+
Luxury beachfront resort with private villas, infinity pool, spa,
|
|
57
|
+
and fine dining restaurant. All-inclusive package available.
|
|
58
|
+
Perfect for romantic getaways and honeymoons.
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
async function categorizeProperty() {
|
|
62
|
+
try {
|
|
63
|
+
const statusUrl = await service.categorizeProduct(propertyDescription);
|
|
64
|
+
console.log('Job submitted. Status URL:', statusUrl);
|
|
65
|
+
|
|
66
|
+
const result = await service.fetchResults(statusUrl);
|
|
67
|
+
console.log('Categories:', result.getResultJson());
|
|
68
|
+
} catch (error) {
|
|
69
|
+
console.error('Error:', error.message);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
categorizeProperty();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## API Documentation
|
|
79
|
+
|
|
80
|
+
### Methods
|
|
81
|
+
|
|
82
|
+
#### `categorizeProduct(productDescription: string, maxCategories?: number): Promise<string>`
|
|
83
|
+
|
|
84
|
+
Categorizes a hospitality product based on its description.
|
|
85
|
+
|
|
86
|
+
**Parameters:**
|
|
87
|
+
- `productDescription` (string, required): The property/product description to categorize
|
|
88
|
+
- `maxCategories` (number, optional): Maximum number of categories to return (default: 5)
|
|
89
|
+
|
|
90
|
+
**Returns:**
|
|
91
|
+
- Promise<string>: Status URL for polling the job result
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Response Format
|
|
96
|
+
|
|
97
|
+
The API returns categories with relevance scores (weight: 0-10):
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"categories": [
|
|
102
|
+
{
|
|
103
|
+
"name": "Luxury Beach Resort",
|
|
104
|
+
"weight": 10,
|
|
105
|
+
"subcategories": ["All-Inclusive", "Spa Resort", "Romantic Getaway"]
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"name": "Boutique Hotel",
|
|
109
|
+
"weight": 7,
|
|
110
|
+
"subcategories": ["Beachfront", "Adults Only"]
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"name": "Honeymoon Destination",
|
|
114
|
+
"weight": 9,
|
|
115
|
+
"subcategories": ["Romantic", "Luxury"]
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Weight Scale:**
|
|
122
|
+
- `10`: Perfect match
|
|
123
|
+
- `8-9`: Highly relevant
|
|
124
|
+
- `6-7`: Moderately relevant
|
|
125
|
+
- `4-5`: Somewhat relevant
|
|
126
|
+
- `1-3`: Slightly relevant
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Examples
|
|
131
|
+
|
|
132
|
+
### Basic Categorization
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
const { SharpApiHospitalityCategoriesService } = require('@sharpapi/sharpapi-node-hospitality-categories');
|
|
136
|
+
|
|
137
|
+
const service = new SharpApiHospitalityCategoriesService(process.env.SHARP_API_KEY);
|
|
138
|
+
|
|
139
|
+
const property = 'Budget-friendly city hotel near train station with free WiFi and breakfast';
|
|
140
|
+
|
|
141
|
+
service.categorizeProduct(property)
|
|
142
|
+
.then(statusUrl => service.fetchResults(statusUrl))
|
|
143
|
+
.then(result => {
|
|
144
|
+
const categories = result.getResultJson();
|
|
145
|
+
console.log('📂 Property Categories:');
|
|
146
|
+
categories.forEach((cat, index) => {
|
|
147
|
+
console.log(`${index + 1}. ${cat.name} (relevance: ${cat.weight}/10)`);
|
|
148
|
+
if (cat.subcategories) {
|
|
149
|
+
console.log(` Subcategories: ${cat.subcategories.join(', ')}`);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
})
|
|
153
|
+
.catch(error => console.error('Categorization failed:', error));
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Batch Property Categorization
|
|
157
|
+
|
|
158
|
+
```javascript
|
|
159
|
+
const service = new SharpApiHospitalityCategoriesService(process.env.SHARP_API_KEY);
|
|
160
|
+
|
|
161
|
+
const properties = [
|
|
162
|
+
'Mountain ski lodge with heated pool and après-ski bar',
|
|
163
|
+
'Downtown business hotel with conference facilities and gym',
|
|
164
|
+
'Family-friendly resort with kids club and water park',
|
|
165
|
+
'Historic boutique hotel in restored Victorian mansion'
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
async function categorizeAll(properties) {
|
|
169
|
+
const categorized = await Promise.all(
|
|
170
|
+
properties.map(async (property) => {
|
|
171
|
+
const statusUrl = await service.categorizeProduct(property, 3);
|
|
172
|
+
const result = await service.fetchResults(statusUrl);
|
|
173
|
+
const categories = result.getResultJson();
|
|
174
|
+
|
|
175
|
+
return {
|
|
176
|
+
property,
|
|
177
|
+
primary_category: categories[0]?.name,
|
|
178
|
+
all_categories: categories.map(c => c.name)
|
|
179
|
+
};
|
|
180
|
+
})
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
return categorized;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const results = await categorizeAll(properties);
|
|
187
|
+
console.log('Categorized properties:', results);
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Travel Platform Integration
|
|
191
|
+
|
|
192
|
+
```javascript
|
|
193
|
+
const service = new SharpApiHospitalityCategoriesService(process.env.SHARP_API_KEY);
|
|
194
|
+
|
|
195
|
+
async function enrichPropertyListing(property) {
|
|
196
|
+
const fullDescription = `
|
|
197
|
+
${property.name}
|
|
198
|
+
${property.description}
|
|
199
|
+
Amenities: ${property.amenities.join(', ')}
|
|
200
|
+
Location: ${property.location}
|
|
201
|
+
`;
|
|
202
|
+
|
|
203
|
+
const statusUrl = await service.categorizeProduct(fullDescription);
|
|
204
|
+
const result = await service.fetchResults(statusUrl);
|
|
205
|
+
const categories = result.getResultJson();
|
|
206
|
+
|
|
207
|
+
// Get high-relevance categories
|
|
208
|
+
const primaryCategories = categories
|
|
209
|
+
.filter(cat => cat.weight >= 7)
|
|
210
|
+
.map(cat => cat.name);
|
|
211
|
+
|
|
212
|
+
// Extract tags from subcategories
|
|
213
|
+
const tags = categories
|
|
214
|
+
.flatMap(cat => cat.subcategories || [])
|
|
215
|
+
.filter((tag, index, self) => self.indexOf(tag) === index);
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
...property,
|
|
219
|
+
categories: primaryCategories,
|
|
220
|
+
tags: tags,
|
|
221
|
+
searchable_text: [...primaryCategories, ...tags].join(' '),
|
|
222
|
+
categorization_confidence: categories[0]?.weight || 0
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const property = {
|
|
227
|
+
id: 'PROP-12345',
|
|
228
|
+
name: 'Seaside Paradise Resort',
|
|
229
|
+
description: 'Luxury oceanfront resort with private beach',
|
|
230
|
+
amenities: ['Pool', 'Spa', 'Restaurant', 'Bar'],
|
|
231
|
+
location: 'Cancun, Mexico'
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
const enrichedProperty = await enrichPropertyListing(property);
|
|
235
|
+
console.log('Enriched listing:', enrichedProperty);
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Smart Search Filter Generation
|
|
239
|
+
|
|
240
|
+
```javascript
|
|
241
|
+
const service = new SharpApiHospitalityCategoriesService(process.env.SHARP_API_KEY);
|
|
242
|
+
|
|
243
|
+
async function generateSearchFilters(propertyDescriptions) {
|
|
244
|
+
const allCategories = new Map();
|
|
245
|
+
|
|
246
|
+
for (const description of propertyDescriptions) {
|
|
247
|
+
const statusUrl = await service.categorizeProduct(description);
|
|
248
|
+
const result = await service.fetchResults(statusUrl);
|
|
249
|
+
const categories = result.getResultJson();
|
|
250
|
+
|
|
251
|
+
categories.forEach(cat => {
|
|
252
|
+
if (!allCategories.has(cat.name)) {
|
|
253
|
+
allCategories.set(cat.name, 0);
|
|
254
|
+
}
|
|
255
|
+
allCategories.set(cat.name, allCategories.get(cat.name) + 1);
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Convert to filter options
|
|
260
|
+
const filters = Array.from(allCategories.entries())
|
|
261
|
+
.map(([category, count]) => ({
|
|
262
|
+
value: category.toLowerCase().replace(/\s+/g, '_'),
|
|
263
|
+
label: category,
|
|
264
|
+
count: count
|
|
265
|
+
}))
|
|
266
|
+
.sort((a, b) => b.count - a.count);
|
|
267
|
+
|
|
268
|
+
return filters;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const sampleDescriptions = [
|
|
272
|
+
'Beach resort with water sports...',
|
|
273
|
+
'Mountain lodge with skiing...',
|
|
274
|
+
'City hotel with conference rooms...'
|
|
275
|
+
];
|
|
276
|
+
|
|
277
|
+
const searchFilters = await generateSearchFilters(sampleDescriptions);
|
|
278
|
+
console.log('Available search filters:', searchFilters);
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## Use Cases
|
|
284
|
+
|
|
285
|
+
- **Travel Booking Platforms**: Auto-categorize hotel listings
|
|
286
|
+
- **Property Management Systems**: Organize properties by type
|
|
287
|
+
- **Search & Discovery**: Enable filtered search by category
|
|
288
|
+
- **Content Management**: Tag and organize hospitality content
|
|
289
|
+
- **Recommendation Engines**: Match properties to user preferences
|
|
290
|
+
- **Market Analysis**: Analyze property types in portfolios
|
|
291
|
+
- **Inventory Management**: Classify accommodation inventory
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## Hospitality Categories
|
|
296
|
+
|
|
297
|
+
The system recognizes various property types:
|
|
298
|
+
|
|
299
|
+
**Accommodation Types:**
|
|
300
|
+
- Luxury Hotels & Resorts
|
|
301
|
+
- Budget & Economy Hotels
|
|
302
|
+
- Boutique Hotels
|
|
303
|
+
- Business Hotels
|
|
304
|
+
- Extended Stay Hotels
|
|
305
|
+
- Vacation Rentals
|
|
306
|
+
- Bed & Breakfast
|
|
307
|
+
- Hostels
|
|
308
|
+
|
|
309
|
+
**Specialized Categories:**
|
|
310
|
+
- Beach Resorts
|
|
311
|
+
- Mountain Lodges
|
|
312
|
+
- Spa Resorts
|
|
313
|
+
- Golf Resorts
|
|
314
|
+
- All-Inclusive Resorts
|
|
315
|
+
- Family Resorts
|
|
316
|
+
- Adults-Only Properties
|
|
317
|
+
- Pet-Friendly Hotels
|
|
318
|
+
|
|
319
|
+
**Purpose-Based:**
|
|
320
|
+
- Romantic Getaways
|
|
321
|
+
- Business Travel
|
|
322
|
+
- Family Vacations
|
|
323
|
+
- Adventure Travel
|
|
324
|
+
- Wellness Retreats
|
|
325
|
+
|
|
326
|
+
---
|
|
327
|
+
|
|
328
|
+
## API Endpoint
|
|
329
|
+
|
|
330
|
+
**POST** `/tth/hospitality_product_categories`
|
|
331
|
+
|
|
332
|
+
For detailed API specifications, refer to:
|
|
333
|
+
- [Postman Documentation](https://documenter.getpostman.com/view/31106842/2sBXVeGsVg)
|
|
334
|
+
- [Product Page](https://sharpapi.com/en/catalog/ai/travel-tourism-hospitality/hospitality-product-categorization)
|
|
335
|
+
|
|
336
|
+
---
|
|
337
|
+
|
|
338
|
+
## Related Packages
|
|
339
|
+
|
|
340
|
+
- [@sharpapi/sharpapi-node-tours-activities-categories](https://www.npmjs.com/package/@sharpapi/sharpapi-node-tours-activities-categories) - Tours categorization
|
|
341
|
+
- [@sharpapi/sharpapi-node-travel-review-sentiment](https://www.npmjs.com/package/@sharpapi/sharpapi-node-travel-review-sentiment) - Review sentiment
|
|
342
|
+
- [@sharpapi/sharpapi-node-product-categories](https://www.npmjs.com/package/@sharpapi/sharpapi-node-product-categories) - General product categorization
|
|
343
|
+
- [@sharpapi/sharpapi-node-client](https://www.npmjs.com/package/@sharpapi/sharpapi-node-client) - Full SharpAPI SDK
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## License
|
|
348
|
+
|
|
349
|
+
This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## Support
|
|
354
|
+
|
|
355
|
+
- **Documentation**: [SharpAPI.com Documentation](https://sharpapi.com/documentation)
|
|
356
|
+
- **Issues**: [GitHub Issues](https://github.com/sharpapi/sharpapi-node-client/issues)
|
|
357
|
+
- **Email**: contact@sharpapi.com
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
**Powered by [SharpAPI](https://sharpapi.com/) - AI-Powered API Workflow Automation**
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sharpapi/sharpapi-node-hospitality-categories",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "SharpAPI.com Node.js SDK for generating hospitality product categories",
|
|
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
|
+
"hotels",
|
|
25
|
+
"product categories"
|
|
26
|
+
],
|
|
27
|
+
"author": "Dawid Makowski <contact@sharpapi.com>",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@sharpapi/sharpapi-node-core": "file:../sharpapi-node-core"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"jest": "^29.7.0"
|
|
34
|
+
},
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/sharpapi/sharpapi-node-hospitality-categories.git"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const { SharpApiCoreService, SharpApiJobTypeEnum } = require('@sharpapi/sharpapi-node-core');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Service for generating hospitality product categories using SharpAPI.com
|
|
5
|
+
*/
|
|
6
|
+
class SharpApiHospitalityCategoriesService extends SharpApiCoreService {
|
|
7
|
+
/**
|
|
8
|
+
* Generates a list of suitable categories for the Hospitality type product
|
|
9
|
+
* with relevance weights as float value (1.0-10.0) where 10 equals 100%, the highest relevance score.
|
|
10
|
+
* Provide the product name and its parameters to get the best category matches possible.
|
|
11
|
+
* Comes in handy with populating products catalogs data and bulk products' processing.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} productName
|
|
14
|
+
* @param {string|null} city
|
|
15
|
+
* @param {string|null} country
|
|
16
|
+
* @param {string|null} language
|
|
17
|
+
* @param {number|null} maxQuantity
|
|
18
|
+
* @param {string|null} voiceTone
|
|
19
|
+
* @param {string|null} context
|
|
20
|
+
* @returns {Promise<string>} - The status URL.
|
|
21
|
+
*/
|
|
22
|
+
async hospitalityProductCategories(productName, city = null, country = null, language = null, maxQuantity = null, voiceTone = null, context = null) {
|
|
23
|
+
const data = { content: productName };
|
|
24
|
+
if (city) data.city = city;
|
|
25
|
+
if (country) data.country = country;
|
|
26
|
+
if (language) data.language = language;
|
|
27
|
+
if (maxQuantity) data.max_quantity = maxQuantity;
|
|
28
|
+
if (voiceTone) data.voice_tone = voiceTone;
|
|
29
|
+
if (context) data.context = context;
|
|
30
|
+
|
|
31
|
+
const response = await this.makeRequest('POST', SharpApiJobTypeEnum.TTH_HOSPITALITY_PRODUCT_CATEGORIES.url, data);
|
|
32
|
+
return this.parseStatusUrl(response);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = { SharpApiHospitalityCategoriesService };
|