fix: enforce source-backed offer type in bid preparation
This commit is contained in:
@@ -17,3 +17,19 @@ export function bidValidityForForm(announcement, analyzed) {
|
||||
const values=[...new Set(evidence.map(e=>e.days).filter(d=>Number.isInteger(d)&&d>0))];
|
||||
return {status:values.length>1?'conflict':values.length?'found':'not_found',days:values.length===1?values[0]:null,evidence};
|
||||
}
|
||||
|
||||
export function extractBidType(text) {
|
||||
const source=String(text || ''),lower=source.toLocaleLowerCase('tr-TR'),evidence=[];
|
||||
for(const [type,label] of [['birim','birim\\s+fiyat'],['goturu','(?:anahtar\\s+teslimi?\\s+)?götürü\\s+bedel']]) {
|
||||
const pattern=new RegExp(`(?:teklif\\s+türü\\s*[::-]\\s*${label}|${label}\\s+(?:üzerinden\\s+|şeklinde\\s+)?teklif\\s+(?:verilecektir|vereceklerdir|sunulacaktır|alınacaktır))`,'gu');
|
||||
for(const match of lower.matchAll(pattern)) evidence.push({type,quote:source.slice(match.index,match.index+match[0].length),start:match.index,end:match.index+match[0].length});
|
||||
}
|
||||
return summarizeBidType(evidence);
|
||||
}
|
||||
function summarizeBidType(evidence) {
|
||||
const types=[...new Set(evidence.map(e=>e.type).filter(t=>['birim','goturu'].includes(t)))];
|
||||
return {status:types.length>1?'conflict':types.length?'found':'not_found',type:types.length===1?types[0]:null,evidence};
|
||||
}
|
||||
export function bidTypeForForm(announcement,analyzed) {
|
||||
return summarizeBidType([...extractBidType(announcement).evidence,...(Array.isArray(analyzed?.evidence)?analyzed.evidence:[])]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user