Spaces:
Sleeping
Sleeping
File size: 3,490 Bytes
691cd90 e00f16a 0b01d1f 9c3169c 691cd90 9c3169c e00f16a 9c3169c e00f16a bbb4e4b 0b01d1f bbb4e4b 0b01d1f e00f16a 0b01d1f 691cd90 9c3169c 691cd90 bbb4e4b 691cd90 e00f16a 691cd90 0b01d1f 691cd90 e00f16a bbb4e4b e00f16a bbb4e4b e00f16a bbb4e4b 691cd90 0b01d1f bbb4e4b e00f16a bbb4e4b 691cd90 bbb4e4b e00f16a bbb4e4b e00f16a bbb4e4b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | /** engine/extractor.js - With Remove Logic */
const KEYWORD_MAP = {
'bc': 'bc', 'ืืจืืืก': 'bc', 'ืืจืืืกืื': 'bc', 'ืืืงืืจ': 'bc',
'flyer': 'flyer', 'ืคืืืืจ': 'flyer', 'ืคืืืืจืื': 'flyer', 'ืขืืื': 'flyer',
'booklet': 'booklet', 'ืืืืจืช': 'booklet', 'ืืืืจืืช': 'booklet', 'ืกืคืจ': 'booklet', 'ืกืคืจืื': 'booklet', 'ืงืืืื': 'booklet',
'invitation': 'invitation', 'ืืืื ื': 'invitation', 'ืืืื ืืช': 'invitation', 'ืืชืื ื': 'invitation',
'rollup': 'rollup', 'ืจืืืืค': 'rollup', 'ืืื ืจ': 'rollup',
'poster': 'poster', 'ืคืืกืืจ': 'poster', 'ืงื ืืก': 'poster',
'sticker': 'sticker', 'ืืืืงื': 'sticker', 'ืืืืงืืช': 'sticker',
'envelope': 'envelope', 'ืืขืืคื': 'envelope', 'ืืขืืคืืช': 'envelope',
'folder': 'folder', 'ืคืืืืจ': 'folder'
};
const HEBREW_NUMBERS = {
'ืืื': 1, 'ืืืช': 1, 'ืฉื ื': 2, 'ืฉืชื': 2, 'ืฉืืืฉ': 3, 'ืฉืืืฉื': 3,
'ืืจืืข': 4, 'ืืจืืขื': 4, 'ืืืฉ': 5, 'ืืืืฉื': 5, 'ืฉืฉ': 6, 'ืฉืืฉื': 6,
'ืฉืืข': 7, 'ืฉืืื ื': 8, 'ืชืฉืข': 9, 'ืขืฉืจ': 10, 'ืืื': 100, 'ืืืฃ': 1000
};
function extractParameters(text) {
let cleanText = text.toLowerCase().replace(/,/g, '');
const result = {
products: [],
qty: null,
isReset: false,
isRemove: false, // <--- ืืืฉ
targetIndex: null, // <--- ืืืฉ
isCartStatus: false,
raw_text: text
};
// 1. ืืืืื ืืืืงื ืกืคืฆืืคืืช
const removeKeywords = ['ืืืง', 'ืืกืจ', 'ืืื', 'ืืืืจืื', 'ืชืืจืื'];
if (removeKeywords.some(w => cleanText.includes(w))) {
result.isRemove = true;
// ื ื ืกื ืืืฆืื ืืกืคืจ (ืืืฉื: "ืืืง ืืช 1")
const numMatch = cleanText.match(/(\d+)/);
if (numMatch) result.targetIndex = parseInt(numMatch[0]);
// ืื ืืื ืืกืคืจ, ื ื ืกื ืืืฆืื ืฉื ืืืฆืจ ืืืื...
}
// 2. ืืืืื ืืืคืืก ืืื
const resetKeywords = ['reset', 'ืืชืื', 'ืชืคืจืื', 'ื ืงื ืืื', 'ืืืคืืก', 'ืืฆืืื'];
if (resetKeywords.some(word => cleanText.includes(word)) && !result.isRemove) {
result.isReset = true;
return result;
}
// 3. ืืืืื ืขืืื
if (cleanText.includes('cart') || cleanText.includes('ืขืืื') || cleanText.includes('ืกืืืื') || cleanText.includes('ืกืืืืก')) {
result.isCartStatus = true;
return result;
}
// 4. ืืืืื ืืืฆืจืื
const foundProducts = new Set();
Object.keys(KEYWORD_MAP).forEach(keyword => {
if (cleanText.includes(keyword)) {
foundProducts.add(KEYWORD_MAP[keyword]);
}
});
result.products = Array.from(foundProducts);
// 5. ืืืืื ืืืืช
const kMatch = cleanText.match(/(\d+)k/);
if (kMatch) {
result.qty = parseInt(kMatch[1]) * 1000;
} else {
const numMatch = cleanText.match(/\d+/);
if (numMatch) {
// ืื ืื ืื ืืืืงื, ื ืืงื ืืช ืืืกืคืจ ืืืืืช
if (!result.isRemove) result.qty = parseInt(numMatch[0]);
} else {
for (const [word, val] of Object.entries(HEBREW_NUMBERS)) {
if (cleanText.includes(word)) {
result.qty = val;
break;
}
}
}
}
return result;
}
module.exports = { extractParameters }; |