@zerocarbon/erp-config-sdk 1.0.28 → 1.0.29
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/dist/bulk-bill-agent.d.ts +33 -2
- package/dist/bulk-bill-agent.esm.js +350 -1
- package/dist/bulk-bill-agent.esm.js.map +1 -1
- package/dist/bulk-bill-agent.js +350 -0
- package/dist/bulk-bill-agent.js.map +1 -1
- package/dist/index.d.ts +33 -2
- package/dist/index.esm.js +350 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +350 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -37900,6 +37900,355 @@ const buildBulkBillAgentPromptConfig = (context = {}, documentText = '') => {
|
|
|
37900
37900
|
},
|
|
37901
37901
|
};
|
|
37902
37902
|
};
|
|
37903
|
+
const numericPattern = /-?(?:(?:\d{1,3}(?:,\d{3})+)|\d+)(?:\.\d+)?/g;
|
|
37904
|
+
const physicalUnitPattern = /\b(kwh|kw\s*h|kvah|kva\s*h|mwh|kg|kgs|kilograms?|tonnes?|tons?|mt|kl|litres?|liters?|ltr?s?|m3|m³|scm|ncm|nm3|km|passenger[-\s]?km|room[-\s]?nights?|nights?|cyl(?:inders?)?|nos?|pcs|pieces?)\b/i;
|
|
37905
|
+
const metadataOnlyPattern = /(?:₹|rs\.?|inr|amount|payable|charge|tax|gst|duty|cess|rate|tariff|arrear|rebate|subsidy|surcharge|rent|total\s+amount|invoice\s*(?:no|number)|account\s*(?:no|number)|consumer\s*(?:no|number))/i;
|
|
37906
|
+
const compactKey = (value) => normalize(value).replace(/\s+/g, '');
|
|
37907
|
+
const canonicalActivityUnit = (unit) => {
|
|
37908
|
+
const value = compactKey(unit);
|
|
37909
|
+
if (value === 'kwh' || value === 'unit' || value === 'units')
|
|
37910
|
+
return 'kWh';
|
|
37911
|
+
if (value === 'kvah')
|
|
37912
|
+
return 'kVAh';
|
|
37913
|
+
if (value === 'mwh')
|
|
37914
|
+
return 'MWh';
|
|
37915
|
+
if (value === 'kg' || value === 'kgs' || value === 'kilogram' || value === 'kilograms')
|
|
37916
|
+
return 'Kg';
|
|
37917
|
+
if (value === 'tonne' || value === 'tonnes' || value === 'ton' || value === 'tons' || value === 'mt')
|
|
37918
|
+
return 'Tonnes';
|
|
37919
|
+
if (value === 'litre' || value === 'litres' || value === 'liter' || value === 'liters' || value === 'ltr' || value === 'ltrs')
|
|
37920
|
+
return 'Litre';
|
|
37921
|
+
if (value === 'kl')
|
|
37922
|
+
return 'KL';
|
|
37923
|
+
if (value === 'm3' || value === 'm³' || value === 'scm' || value === 'ncm' || value === 'nm3')
|
|
37924
|
+
return 'M3';
|
|
37925
|
+
if (value === 'km')
|
|
37926
|
+
return 'km';
|
|
37927
|
+
if (value === 'passengerkm')
|
|
37928
|
+
return 'passenger-km';
|
|
37929
|
+
if (value === 'night' || value === 'nights' || value === 'roomnight' || value === 'roomnights')
|
|
37930
|
+
return 'night';
|
|
37931
|
+
if (value === 'cyl' || value === 'cylinder' || value === 'cylinders')
|
|
37932
|
+
return 'Cyl';
|
|
37933
|
+
if (value === 'nos' || value === 'no' || value === 'pcs' || value === 'pieces')
|
|
37934
|
+
return 'Nos';
|
|
37935
|
+
return unit;
|
|
37936
|
+
};
|
|
37937
|
+
const parsePositiveNumbers = (line) => [...line.matchAll(numericPattern)]
|
|
37938
|
+
.map((match) => ({
|
|
37939
|
+
value: match[0],
|
|
37940
|
+
index: match.index || 0,
|
|
37941
|
+
number: Number(match[0].replace(/,/g, '')),
|
|
37942
|
+
}))
|
|
37943
|
+
.filter((entry) => Number.isFinite(entry.number) && entry.number > 0 && !/[A-Za-z]/.test(line[entry.index - 1] || ''));
|
|
37944
|
+
const adjacentActivityUnit = (line, numberIndex, valueLength) => {
|
|
37945
|
+
var _a, _b, _c;
|
|
37946
|
+
const after = line.slice(numberIndex + valueLength, numberIndex + valueLength + 18);
|
|
37947
|
+
const right = ((_a = after.match(/^\s*([A-Za-z³][-A-Za-z0-9³ ]{0,16})/i)) === null || _a === void 0 ? void 0 : _a[1]) || '';
|
|
37948
|
+
const rightUnit = (_b = right.match(physicalUnitPattern)) === null || _b === void 0 ? void 0 : _b[1];
|
|
37949
|
+
if (rightUnit)
|
|
37950
|
+
return canonicalActivityUnit(rightUnit);
|
|
37951
|
+
const before = line.slice(Math.max(0, numberIndex - 18), numberIndex);
|
|
37952
|
+
const beforeUnit = (_c = before.match(new RegExp(`(${physicalUnitPattern.source})\\s*$`, 'i'))) === null || _c === void 0 ? void 0 : _c[1];
|
|
37953
|
+
return beforeUnit ? canonicalActivityUnit(beforeUnit) : '';
|
|
37954
|
+
};
|
|
37955
|
+
const candidateAllowedScore = (query, item) => {
|
|
37956
|
+
const queryKey = normalize(query);
|
|
37957
|
+
const text = itemText(item);
|
|
37958
|
+
if (!queryKey || !text)
|
|
37959
|
+
return 0;
|
|
37960
|
+
const itemNameKey = normalize(item.itemName);
|
|
37961
|
+
if (itemNameKey && (queryKey.includes(itemNameKey) || itemNameKey.includes(queryKey)))
|
|
37962
|
+
return 1;
|
|
37963
|
+
const queryTokens = queryKey.split(' ').filter((token) => token.length > 1);
|
|
37964
|
+
const itemTokens = text.split(' ').filter((token) => token.length > 1);
|
|
37965
|
+
if (!queryTokens.length || !itemTokens.length)
|
|
37966
|
+
return 0;
|
|
37967
|
+
const matched = itemTokens.filter((token) => queryTokens.some((candidate) => token === candidate || token.includes(candidate) || candidate.includes(token))).length;
|
|
37968
|
+
return matched / itemTokens.length;
|
|
37969
|
+
};
|
|
37970
|
+
const bestAllowedItemForQuery = (query, allowedItems) => {
|
|
37971
|
+
const best = allowedItems
|
|
37972
|
+
.map((item) => ({ item, score: candidateAllowedScore(query, item) }))
|
|
37973
|
+
.sort((left, right) => right.score - left.score)[0];
|
|
37974
|
+
return best && best.score >= 0.34 ? best : null;
|
|
37975
|
+
};
|
|
37976
|
+
const profileTextLines = (pages = [], group, documentText = '') => {
|
|
37977
|
+
const wanted = new Set(group.pageNumbers.map(Number));
|
|
37978
|
+
const selectedPages = pages.filter((page) => wanted.has(Number(page.pageNumber)));
|
|
37979
|
+
if (!selectedPages.length && documentText) {
|
|
37980
|
+
return documentText.split(/\n+/).map((text, lineIndex) => ({
|
|
37981
|
+
pageNumber: 1,
|
|
37982
|
+
lineIndex,
|
|
37983
|
+
text: text.replace(/\s+/g, ' ').trim(),
|
|
37984
|
+
}));
|
|
37985
|
+
}
|
|
37986
|
+
return selectedPages.flatMap((page) => String(page.text || '').split(/\n+/).map((text, lineIndex) => ({
|
|
37987
|
+
pageNumber: Number(page.pageNumber),
|
|
37988
|
+
lineIndex,
|
|
37989
|
+
text: text.replace(/\s+/g, ' ').trim(),
|
|
37990
|
+
})));
|
|
37991
|
+
};
|
|
37992
|
+
const buildProfileCandidate = ({ group, profileId, pageNumber, lineIndex, numberIndex, itemName, quantity, unit, evidenceText, allowedMatch, role = 'item_table_quantity', confidence = 0.76, }) => ({
|
|
37993
|
+
candidateId: `${group.groupId}-${profileId}-${pageNumber}-${lineIndex}-${numberIndex}-${compactKey(itemName).slice(0, 24)}`,
|
|
37994
|
+
groupId: group.groupId,
|
|
37995
|
+
profileId,
|
|
37996
|
+
itemName: (allowedMatch === null || allowedMatch === void 0 ? void 0 : allowedMatch.item.itemName) || itemName,
|
|
37997
|
+
quantity: quantity.replace(/,/g, ''),
|
|
37998
|
+
unit,
|
|
37999
|
+
role,
|
|
38000
|
+
confidence: Math.min(0.98, confidence + ((allowedMatch === null || allowedMatch === void 0 ? void 0 : allowedMatch.score) || 0) * 0.14),
|
|
38001
|
+
pageNumber,
|
|
38002
|
+
evidenceText,
|
|
38003
|
+
matchedAllowedItemName: allowedMatch === null || allowedMatch === void 0 ? void 0 : allowedMatch.item.itemName,
|
|
38004
|
+
matchedAllowedItemKey: allowedMatch === null || allowedMatch === void 0 ? void 0 : allowedMatch.item.itemKey,
|
|
38005
|
+
matchedAllowedItemSourceId: allowedMatch === null || allowedMatch === void 0 ? void 0 : allowedMatch.item.sourceId,
|
|
38006
|
+
mappingConfidence: (allowedMatch === null || allowedMatch === void 0 ? void 0 : allowedMatch.score) || undefined,
|
|
38007
|
+
});
|
|
38008
|
+
const refrigerantLabel = (line) => {
|
|
38009
|
+
const match = line.match(/\b(?:hfc[-\s]*)?r[-\s]?(?:410\s*a?|32|134\s*a?|22|404\s*a?|125|407\s*c?)\b/i);
|
|
38010
|
+
if (!match)
|
|
38011
|
+
return '';
|
|
38012
|
+
return match[0].toUpperCase().replace(/\s+/g, ' ').replace(/^R\s*/, 'R-').replace(/R-410A$/, 'R-410 A');
|
|
38013
|
+
};
|
|
38014
|
+
const industrialGasLabel = (line) => {
|
|
38015
|
+
if (/\b(?:o2|0?2\s*gas|oxygen)\b/i.test(line))
|
|
38016
|
+
return 'Oxygen Gas';
|
|
38017
|
+
if (/\b(?:co2|c0?2|carbon\s+dioxide)\b/i.test(line))
|
|
38018
|
+
return 'CO2 Gas';
|
|
38019
|
+
if (/\bnitrogen\b/i.test(line))
|
|
38020
|
+
return 'Nitrogen Gas';
|
|
38021
|
+
if (/\bargon\b/i.test(line))
|
|
38022
|
+
return 'Argon Gas';
|
|
38023
|
+
if (/\bacetylene\b/i.test(line))
|
|
38024
|
+
return 'Acetylene';
|
|
38025
|
+
return '';
|
|
38026
|
+
};
|
|
38027
|
+
const fuelLabel = (line) => {
|
|
38028
|
+
if (/\b(?:hsd|diesel)\b/i.test(line))
|
|
38029
|
+
return 'Diesel';
|
|
38030
|
+
if (/\bpetrol\b/i.test(line))
|
|
38031
|
+
return 'Petrol';
|
|
38032
|
+
if (/\bcng\b/i.test(line))
|
|
38033
|
+
return 'CNG';
|
|
38034
|
+
if (/\bfurnace\s+oil\b/i.test(line))
|
|
38035
|
+
return 'Furnace Oil';
|
|
38036
|
+
if (/\b(?:petroleum\s+coke|petcoke|coke)\b/i.test(line))
|
|
38037
|
+
return 'Petroleum Coke';
|
|
38038
|
+
if (/\bcoal\b/i.test(line))
|
|
38039
|
+
return 'Coal';
|
|
38040
|
+
if (/\b(?:lpg|liquefied\s+petroleum)\b/i.test(line))
|
|
38041
|
+
return 'LPG';
|
|
38042
|
+
if (/\b(?:lubrication\s+oil|lube\s+oil|grease)\b/i.test(line))
|
|
38043
|
+
return 'Lubrication Oil';
|
|
38044
|
+
if (/\bkerosene\b/i.test(line))
|
|
38045
|
+
return 'Kerosene';
|
|
38046
|
+
return '';
|
|
38047
|
+
};
|
|
38048
|
+
const fireExtinguisherLabel = (line) => /\b(?:fire\s+extinguisher|extinguisher|refill|refilling)\b/i.test(line) ? 'Fire Extinguisher Refilling' : '';
|
|
38049
|
+
const sf6Label = (line) => /\b(?:sf6|sulph?ur\s+hexafluoride)\b/i.test(line) ? 'SF6 Usage' : '';
|
|
38050
|
+
const waterLabel = (line) => {
|
|
38051
|
+
if (/\b(?:tanker)\b/i.test(line))
|
|
38052
|
+
return 'Tanker Water';
|
|
38053
|
+
if (/\b(?:municipal|corporation|utility)\b/i.test(line))
|
|
38054
|
+
return 'Municipal Water';
|
|
38055
|
+
if (/\b(?:ground\s*water|borewell|bore\s*well)\b/i.test(line))
|
|
38056
|
+
return 'Groundwater';
|
|
38057
|
+
if (/\b(?:wastewater|effluent|sewage)\b/i.test(line))
|
|
38058
|
+
return 'Wastewater';
|
|
38059
|
+
return /\bwater\b/i.test(line) ? 'Water' : '';
|
|
38060
|
+
};
|
|
38061
|
+
const wasteLabel = (line) => {
|
|
38062
|
+
if (/\bhazardous\b/i.test(line))
|
|
38063
|
+
return 'Hazardous Waste';
|
|
38064
|
+
if (/\b(?:recycl|scrap)\b/i.test(line))
|
|
38065
|
+
return 'Recycled Waste';
|
|
38066
|
+
if (/\bcompost\b/i.test(line))
|
|
38067
|
+
return 'Composted Waste';
|
|
38068
|
+
if (/\blandfill\b/i.test(line))
|
|
38069
|
+
return 'Landfill Waste';
|
|
38070
|
+
return /\bwaste\b/i.test(line) ? 'Waste Generated in Operations' : '';
|
|
38071
|
+
};
|
|
38072
|
+
const businessTravelLabel = (line) => {
|
|
38073
|
+
if (/\b(?:flight|airline|air\s+travel)\b/i.test(line))
|
|
38074
|
+
return 'Air Travel';
|
|
38075
|
+
if (/\b(?:train|rail|metro)\b/i.test(line))
|
|
38076
|
+
return 'Rail Travel';
|
|
38077
|
+
if (/\b(?:hotel|room\s*night|nights?)\b/i.test(line))
|
|
38078
|
+
return 'Hotel Stay';
|
|
38079
|
+
if (/\b(?:taxi|cab|rental\s+car|car\s+rental)\b/i.test(line))
|
|
38080
|
+
return 'Rental Car';
|
|
38081
|
+
return '';
|
|
38082
|
+
};
|
|
38083
|
+
const processEmissionLabel = (line) => {
|
|
38084
|
+
if (/\bclinker\b/i.test(line))
|
|
38085
|
+
return 'Clinker';
|
|
38086
|
+
if (/\bcalcination\b/i.test(line))
|
|
38087
|
+
return 'Calcination Process';
|
|
38088
|
+
if (/\b(?:limestone|dolomite|flux)\b/i.test(line))
|
|
38089
|
+
return 'Flux calcination';
|
|
38090
|
+
if (/\b(?:hot\s+metal|ironmaking)\b/i.test(line))
|
|
38091
|
+
return 'Process Emissions- Ironmaking';
|
|
38092
|
+
if (/\bsteelmaking\b/i.test(line))
|
|
38093
|
+
return 'Process Emissions- Steelmaking';
|
|
38094
|
+
return '';
|
|
38095
|
+
};
|
|
38096
|
+
const genericMaterialLabel = (line, allowedItems) => {
|
|
38097
|
+
if (metadataOnlyPattern.test(line) && !physicalUnitPattern.test(line))
|
|
38098
|
+
return '';
|
|
38099
|
+
const best = bestAllowedItemForQuery(line, allowedItems);
|
|
38100
|
+
return (best === null || best === void 0 ? void 0 : best.item.itemName) || line.split('|').map((part) => part.trim()).find((part) => /[A-Za-z]/.test(part) && !metadataOnlyPattern.test(part)) || '';
|
|
38101
|
+
};
|
|
38102
|
+
const commuteModeLabel = (line) => {
|
|
38103
|
+
const text = normalize(line);
|
|
38104
|
+
if (/\b(bike|bikt|motorcycle)\b/.test(text))
|
|
38105
|
+
return 'Motorcycle';
|
|
38106
|
+
if (/\b(scooty|scoow|scooter)\b/.test(text))
|
|
38107
|
+
return 'Scooter';
|
|
38108
|
+
if (/\b(auto|byauto|auio)\b/.test(text))
|
|
38109
|
+
return 'Small Car Gasoline';
|
|
38110
|
+
if (/\b(car|eycar|hatchback)\b/.test(text))
|
|
38111
|
+
return 'Hatchback Gasoline';
|
|
38112
|
+
if (/\b(metro|14etro|train|rail)\b/.test(text))
|
|
38113
|
+
return 'Train Domestic Electric';
|
|
38114
|
+
if (/\b(cycle|cycl|cyct)\b/.test(text))
|
|
38115
|
+
return 'Employee commute cycle';
|
|
38116
|
+
if (/\b(bus)\b/.test(text))
|
|
38117
|
+
return 'Bus';
|
|
38118
|
+
return '';
|
|
38119
|
+
};
|
|
38120
|
+
const extractNamedQuantityCandidates = ({ profileId, group, lines, allowedItems, labelForLine, }) => lines.flatMap(({ pageNumber, lineIndex, text }) => {
|
|
38121
|
+
if (!text || (metadataOnlyPattern.test(text) && !physicalUnitPattern.test(text)))
|
|
38122
|
+
return [];
|
|
38123
|
+
const itemName = labelForLine(text, allowedItems);
|
|
38124
|
+
if (!itemName)
|
|
38125
|
+
return [];
|
|
38126
|
+
return parsePositiveNumbers(text).flatMap((entry, numberIndex) => {
|
|
38127
|
+
const unit = adjacentActivityUnit(text, entry.index, entry.value.length);
|
|
38128
|
+
if (!unit)
|
|
38129
|
+
return [];
|
|
38130
|
+
const allowedMatch = bestAllowedItemForQuery(`${itemName} ${text}`, allowedItems);
|
|
38131
|
+
return [buildProfileCandidate({
|
|
38132
|
+
group,
|
|
38133
|
+
profileId,
|
|
38134
|
+
pageNumber,
|
|
38135
|
+
lineIndex,
|
|
38136
|
+
numberIndex,
|
|
38137
|
+
itemName,
|
|
38138
|
+
quantity: entry.value,
|
|
38139
|
+
unit,
|
|
38140
|
+
evidenceText: text,
|
|
38141
|
+
allowedMatch,
|
|
38142
|
+
})];
|
|
38143
|
+
});
|
|
38144
|
+
});
|
|
38145
|
+
const extractElectricityCandidates = (group, lines, allowedItems) => {
|
|
38146
|
+
const electricityLine = /\b(?:net\s+cons\.?\s+for\s+billing|billed\s+units?|billing\s+units?|units\s+consumed|energy\s+consumption|import|export|generation|solar|renewable)\b/i;
|
|
38147
|
+
return lines.flatMap(({ pageNumber, lineIndex, text }) => {
|
|
38148
|
+
if (!electricityLine.test(text) || metadataOnlyPattern.test(text))
|
|
38149
|
+
return [];
|
|
38150
|
+
return parsePositiveNumbers(text).flatMap((entry, numberIndex) => {
|
|
38151
|
+
const unit = adjacentActivityUnit(text, entry.index, entry.value.length) || (/\bunits?\b/i.test(text) ? 'kWh' : '');
|
|
38152
|
+
if (!unit || !/\b(?:kwh|kvah|mwh)\b/i.test(unit))
|
|
38153
|
+
return [];
|
|
38154
|
+
const role = /\b(?:solar|renewable|generation|export)\b/i.test(text) ? 'component_consumption' : 'bill_level_consumption';
|
|
38155
|
+
const allowedMatch = bestAllowedItemForQuery(text, allowedItems);
|
|
38156
|
+
return [buildProfileCandidate({
|
|
38157
|
+
group,
|
|
38158
|
+
profileId: 'electricity',
|
|
38159
|
+
pageNumber,
|
|
38160
|
+
lineIndex,
|
|
38161
|
+
numberIndex,
|
|
38162
|
+
itemName: (allowedMatch === null || allowedMatch === void 0 ? void 0 : allowedMatch.item.itemName) || 'Electricity Purchased from Grid',
|
|
38163
|
+
quantity: entry.value,
|
|
38164
|
+
unit,
|
|
38165
|
+
evidenceText: text,
|
|
38166
|
+
allowedMatch,
|
|
38167
|
+
role,
|
|
38168
|
+
confidence: role === 'bill_level_consumption' ? 0.86 : 0.78,
|
|
38169
|
+
})];
|
|
38170
|
+
});
|
|
38171
|
+
});
|
|
38172
|
+
};
|
|
38173
|
+
const extractEmployeeCommutingCandidates = (group, lines, allowedItems) => {
|
|
38174
|
+
const totals = new Map();
|
|
38175
|
+
for (const { pageNumber, text } of lines) {
|
|
38176
|
+
const mode = commuteModeLabel(text);
|
|
38177
|
+
if (!mode)
|
|
38178
|
+
continue;
|
|
38179
|
+
const distanceValues = parsePositiveNumbers(text)
|
|
38180
|
+
.filter((entry) => /\bkm\b/i.test(text.slice(entry.index, entry.index + 24)) || /\bkm\b/i.test(text));
|
|
38181
|
+
const value = distanceValues.length ? distanceValues[distanceValues.length - 1].number : null;
|
|
38182
|
+
if (!value)
|
|
38183
|
+
continue;
|
|
38184
|
+
const current = totals.get(mode) || { total: 0, evidence: [], pageNumber };
|
|
38185
|
+
current.total += value;
|
|
38186
|
+
if (current.evidence.length < 4)
|
|
38187
|
+
current.evidence.push(text);
|
|
38188
|
+
totals.set(mode, current);
|
|
38189
|
+
}
|
|
38190
|
+
return [...totals.entries()].map(([mode, aggregate], index) => {
|
|
38191
|
+
const allowedMatch = bestAllowedItemForQuery(mode, allowedItems);
|
|
38192
|
+
return buildProfileCandidate({
|
|
38193
|
+
group,
|
|
38194
|
+
profileId: 'employee_commuting',
|
|
38195
|
+
pageNumber: aggregate.pageNumber,
|
|
38196
|
+
lineIndex: index,
|
|
38197
|
+
numberIndex: 0,
|
|
38198
|
+
itemName: mode,
|
|
38199
|
+
quantity: String(Number(aggregate.total.toFixed(5))),
|
|
38200
|
+
unit: 'km',
|
|
38201
|
+
evidenceText: aggregate.evidence.join(' | '),
|
|
38202
|
+
allowedMatch,
|
|
38203
|
+
role: 'aggregated_distance',
|
|
38204
|
+
confidence: 0.88,
|
|
38205
|
+
});
|
|
38206
|
+
});
|
|
38207
|
+
};
|
|
38208
|
+
const extractForProfile = (profileId, group, lines, allowedItems) => {
|
|
38209
|
+
if (profileId === 'electricity')
|
|
38210
|
+
return extractElectricityCandidates(group, lines, allowedItems);
|
|
38211
|
+
if (profileId === 'employee_commuting')
|
|
38212
|
+
return extractEmployeeCommutingCandidates(group, lines, allowedItems);
|
|
38213
|
+
const labelForProfile = {
|
|
38214
|
+
fuel_combustion: (line) => fuelLabel(line),
|
|
38215
|
+
lpg_usage: (line) => fuelLabel(line),
|
|
38216
|
+
refrigerants: (line) => refrigerantLabel(line),
|
|
38217
|
+
industrial_gases: (line) => industrialGasLabel(line),
|
|
38218
|
+
business_travel: (line) => businessTravelLabel(line),
|
|
38219
|
+
fire_extinguisher: (line) => fireExtinguisherLabel(line),
|
|
38220
|
+
sf6_usage: (line) => sf6Label(line),
|
|
38221
|
+
water: (line) => waterLabel(line),
|
|
38222
|
+
waste: (line) => wasteLabel(line),
|
|
38223
|
+
process_emissions: (line) => processEmissionLabel(line),
|
|
38224
|
+
purchased_goods: genericMaterialLabel,
|
|
38225
|
+
generic_material: genericMaterialLabel,
|
|
38226
|
+
};
|
|
38227
|
+
const labelForLine = labelForProfile[profileId] || genericMaterialLabel;
|
|
38228
|
+
return extractNamedQuantityCandidates({ profileId, group, lines, allowedItems, labelForLine });
|
|
38229
|
+
};
|
|
38230
|
+
const extractBulkBillAgentProfileCandidates = ({ mappingContext = {}, pages = [], group, documentText = '', }) => {
|
|
38231
|
+
const allowedItems = Array.isArray(mappingContext.allowedItems) ? mappingContext.allowedItems : [];
|
|
38232
|
+
const lines = profileTextLines(pages, group, documentText);
|
|
38233
|
+
const groupText = documentText || lines.map((line) => line.text).join('\n');
|
|
38234
|
+
const primaryProfile = getPrimaryBulkBillAgentProfile(mappingContext, groupText);
|
|
38235
|
+
const profiles = getBulkBillAgentProfilesForMappingContext(mappingContext, groupText)
|
|
38236
|
+
.map((entry) => entry.profile.id)
|
|
38237
|
+
.filter((profileId, index, profileIds) => profileIds.indexOf(profileId) === index);
|
|
38238
|
+
const extractionProfiles = profiles.length ? profiles : [primaryProfile.id];
|
|
38239
|
+
const candidates = extractionProfiles.flatMap((profileId) => extractForProfile(profileId, group, lines, allowedItems));
|
|
38240
|
+
const seen = new Set();
|
|
38241
|
+
return candidates
|
|
38242
|
+
.sort((left, right) => right.confidence - left.confidence)
|
|
38243
|
+
.filter((candidate) => {
|
|
38244
|
+
const key = [candidate.profileId, candidate.matchedAllowedItemKey || candidate.itemName, candidate.quantity, candidate.unit, candidate.pageNumber].join('|');
|
|
38245
|
+
if (seen.has(key))
|
|
38246
|
+
return false;
|
|
38247
|
+
seen.add(key);
|
|
38248
|
+
return true;
|
|
38249
|
+
})
|
|
38250
|
+
.slice(0, 30);
|
|
38251
|
+
};
|
|
37903
38252
|
|
|
37904
38253
|
// User-specific configurations mapping
|
|
37905
38254
|
const USER_CONFIGS = {
|
|
@@ -44747,6 +45096,7 @@ exports.createCapitalizedMonthMapping = createCapitalizedMonthMapping;
|
|
|
44747
45096
|
exports.createEmissionSourceGenerator = createEmissionSourceGenerator;
|
|
44748
45097
|
exports.createMonthMapping = createMonthMapping;
|
|
44749
45098
|
exports.debugCarbonIntensityMapping = debugCarbonIntensityMapping;
|
|
45099
|
+
exports.extractBulkBillAgentProfileCandidates = extractBulkBillAgentProfileCandidates;
|
|
44750
45100
|
exports.extractCarbonIntensityData = extractCarbonIntensityData;
|
|
44751
45101
|
exports.formatEmissionValue = formatEmissionValue;
|
|
44752
45102
|
exports.formatIntensityValue = formatIntensityValue;
|