Files
ihaleist/src/services/bidTerms.js
T

36 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Extract only explicitly labelled bid validity clauses; delivery/warranty days are unrelated.
export function extractBidValidity(text) {
const source=String(text || '');
const pattern=/teklif(?:lerin|in)?\s+geçerlilik\s+süresi[^\n.\d]{0,100}(\d{1,4})(?:\s*\([^)]{0,80}\))?\s*(?:takvim\s*)?gün/giu;
const evidence=[];
for(const match of source.toLocaleLowerCase('tr-TR').matchAll(pattern)) {
const days=Number(match[1]);
if(days>0) evidence.push({days,quote:source.slice(match.index,match.index+match[0].length),start:match.index,end:match.index+match[0].length});
}
const values=[...new Set(evidence.map(e=>e.days))];
return {status:values.length>1?'conflict':values.length?'found':'not_found',days:values.length===1?values[0]:null,evidence};
}
export function bidValidityForForm(announcement, analyzed) {
const local=extractBidValidity(announcement);
const evidence=[...local.evidence,...(Array.isArray(analyzed?.evidence)?analyzed.evidence:[])];
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:[])]);
}