Skip to content

Commit

Permalink
Updated regex logic, added terms to dictionnaries.
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperOuss committed Apr 2, 2024
1 parent e705b6c commit 8ef8d90
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,19 @@ function extractRoomType(roomName) {
}

// Improved fallback logic for 'single', 'double', 'triple', 'quad'
if (/(single|double|triple|quad)(?!\s+(bed|sofa|sofabed|murphy))/.test(normalizedRoomName)) {
// If matched at the start and not followed by bed/sofa/sofabed, return it as room type
let type = RegExp.$1 + ' ' + "room";
return type;
let match = normalizedRoomName.match(/\b(single|double|triple|quad)\b/i);
if (match) {
let indexAfterMatch = match.index + match[0].length; // Calculate the index immediately after the match
let subsequentText = normalizedRoomName.slice(indexAfterMatch); // Extract subsequent text
// Verify if not immediately describing a bed type, to consider as a room type
if (!/\b(bed|sofa|sofabed|murphy|beds)\b/i.test(subsequentText)) {
return match[1] + ' room'; // Consider it as room type
}
}



if (/twin(?!\s+(bed|sofa|sofabed))/.test(normalizedRoomName)) {
if (/twin(?!\s+(bed|sofa|sofabed|beds))/.test(normalizedRoomName)) {
// This will now only match if "twin" is present and not followed by "bed", "sofa", or "sofabed"
let type = "twin room";
return type;
Expand All @@ -79,7 +84,6 @@ function extractRoomType(roomName) {
'family': 'family room',
'connected': 'connected rooms',
'communicating rooms': 'connected rooms',
'Disability access': 'accessible',
// Extend with more synonyms as needed
};

Expand Down Expand Up @@ -132,6 +136,7 @@ function extractRoomCategory(roomName) {
'low-rise': 'low floor',
'ground floor': 'low floor',
'with a view': 'balcony',
'disability access': 'accessible',
// Add other synonyms or similar terms as needed
};

Expand All @@ -148,7 +153,7 @@ function extractRoomCategory(roomName) {
'business class', 'premium', 'boutique', 'historic', 'modern',
'oceanfront', 'beachfront', 'executive club',
'high floor', 'low floor', 'prestige','singular','style', 'privilege','design',
'balcony',
'balcony', 'accessible'
];

// Collect all matching categories
Expand Down Expand Up @@ -202,16 +207,16 @@ function extractView(roomName) {

function extractBedTypes(roomName) {
const bedTypes = [
'single bed', 'double bed', 'queen bed', 'king bed', 'twin bed', 'twin beds',
'bunk bed', 'double sofa bed', 'sofa bed', 'futon', 'murphy bed',
'single bed', 'double bed', 'queen bed', 'king bed', 'twin bed', 'twin beds', 'double beds',
'bunk bed', 'double sofa bed', 'sofa bed', 'futon', 'murphy bed', 'queen',
'full bed', 'california king bed', 'kingsize', 'queensize', 'twin sofa bed', 'twin sofabed',
'day bed', 'trundle bed', 'extra bed', 'cot', 'rollaway bed', 'single sofa bed', 'sofabed',
'queen beds', 'king beds', 'kingsize bed', 'kingsize beds', 'queen size bed', 'queensize bed',
'queen size beds', 'queensize beds', 'king size bed', 'king size beds', 'kingsize beds', 'kingsize bed'
].sort((a, b) => b.length - a.length); // Ensure longer (more specific) names are matched first

const sizeAndTypeNormalization = {
'single bed': 'single', 'double bed': 'double', 'queen bed': 'queen',
'single bed': 'single', 'double bed': 'double', 'queen bed': 'queen', 'double beds': 'double',
'king bed': 'king', 'twin bed': 'twin', 'twin beds': 'twin', 'bunk bed': 'bunk',
'double sofa bed': 'double sofa', 'single sofa bed': 'single sofa',
'sofa bed': 'single sofa', 'futon': 'futon', 'murphy bed': 'murphy',
Expand All @@ -224,8 +229,8 @@ function extractBedTypes(roomName) {
// Additions to cover all specified bed types
'queen size bed': 'queen', 'queen size beds': 'queen',
'king size bed': 'king', 'king size beds': 'king',
'queensize bed': 'queen', 'queensize beds': 'queen',
'kingsize bed': 'king', 'kingsize beds': 'king',
'queensize bed': 'queen', 'queensize beds': 'queen', 'queen': 'queen',
'kingsize bed': 'king', 'kingsize beds': 'king',
};

roomName = roomName.toLowerCase();
Expand Down Expand Up @@ -525,7 +530,7 @@ function addMatchToResults(refRoom, match, results) {
//Test route
app.get('/', async (req, res) => {
res.status(200).send({
message: 'Hello from Nuitee room mapping API v0.4 !',
message: 'Hello from Nuitee room mapping API v0.45 !',
});
});

Expand Down

0 comments on commit 8ef8d90

Please sign in to comment.