feat(csv-parser): Introduce header signature ranking metrics for enhanced CSV analysis
- Added new functions for calculating header signature recall and ranking metrics, improving the analysis of CSV templates. - Updated existing CSV analysis endpoints to utilize the new ranking metrics, enhancing the accuracy of template matching. - Refactored related code to replace Jaccard score calculations with the new metrics, providing a more comprehensive evaluation of CSV structure. - Improved documentation for new functions to clarify their purpose and usage in the context of CSV template analysis.
This commit is contained in:
1 parent
c10da55ec6
commit
b4cc3cb934
7 files changed
+223
-60
No files matched your search
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Vorschau-Zellen: Zahlen rechts (tabular-nums), Text links — typisch für CSV-Tabellen.
|
||||
*/
|
||||
|
||||
function stripForNumericTest(s) {
|
||||
return String(s)
|
||||
.trim()
|
||||
.replace(/\u00a0/g, '')
|
||||
.replace(/\s/g, '')
|
||||
}
|
||||
|
||||
/**
|
||||
* Einfache Heuristik: reine Zahl / Dezimal (ein Punkt oder ein Komma als Dezimaltrenner).
|
||||
* Keine Datums-/Zeitstrings (mehrere Punkte ohne klares Muster werden nicht als Zahl gewertet).
|
||||
*/
|
||||
export function isCsvPreviewNumericCell(val) {
|
||||
if (val == null || val === '—') return false
|
||||
let s = stripForNumericTest(val)
|
||||
if (!s) return false
|
||||
if (/^\d{1,2}[./]\d{1,2}[./]\d{2,4}/.test(s)) return false
|
||||
if (/^\d{4}-\d{2}-\d{2}/.test(s)) return false
|
||||
if (/:/.test(s) && /\d/.test(s)) return false
|
||||
|
||||
s = s.replace(/^[-+]/, '')
|
||||
const comma = (s.match(/,/g) || []).length
|
||||
const dot = (s.match(/\./g) || []).length
|
||||
if (comma > 1 || dot > 1 || (comma >= 1 && dot >= 1)) return false
|
||||
|
||||
s = s.replace(',', '.')
|
||||
if (!/^\d*\.?\d+$/.test(s) && !/^\d+\.\d+$/.test(s)) return false
|
||||
return Number.isFinite(Number(s))
|
||||
}
|
||||
|
||||
/** td-Style für CSV-Vorschau (Import + Admin-Editor) */
|
||||
export function csvPreviewTdStyle(val, extra = {}) {
|
||||
const numeric = isCsvPreviewNumericCell(val)
|
||||
return {
|
||||
padding: '6px 8px',
|
||||
borderBottom: '1px solid var(--border)',
|
||||
maxWidth: 220,
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
textAlign: numeric ? 'right' : 'left',
|
||||
fontVariantNumeric: numeric ? 'tabular-nums' : undefined,
|
||||
...extra,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user