Preserve mixed and nested sequences in layout classification

Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com>
This commit is contained in:
Rudy Celekli
2026-10-01 21:45:07 -04:00
parent d3f71c4bb8
commit a77e3e7573
@@ -191,14 +191,22 @@ export class DataShapeClassifier {
if (Array.isArray(data)) {
if (data.length === 0) return 'leaf_item';
// Classify the whole sequence; a first-item guess can hide later content.
// Mixed scalars/mappings and nested sequences need structural rendering.
const allScalars = data.every(item => typeof item !== 'object' || item === null);
const allMappings = data.every(item =>
typeof item === 'object' && item !== null && !Array.isArray(item)
);
if (!allScalars && !allMappings) return 'block_group';
// Sequence of Scalars
if (typeof data[0] !== 'object' || data[0] === null) {
if (allScalars) {
const avgLength = data.reduce((acc, str) => acc + String(str).length, 0) / data.length;
return avgLength <= 35 ? 'badge_list' : 'prose_flow';
}
// Sequence of Mappings
const records = data.filter(item => typeof item === 'object' && item !== null);
const records = data; // allMappings: every original item participates
const uniformity = this.calculateJaccardUniformity(records);
if (uniformity >= 0.55) {