@heripo/document-processor 0.1.14 → 0.1.15
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/index.cjs +39 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -2
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -3039,6 +3039,9 @@ var PageRangeParser = class extends VisionLLMComponent {
|
|
|
3039
3039
|
};
|
|
3040
3040
|
}
|
|
3041
3041
|
const sampledPages = /* @__PURE__ */ new Set();
|
|
3042
|
+
let consecutiveAllNullAttempts = 0;
|
|
3043
|
+
const MAX_ALL_NULL_ATTEMPTS = 3;
|
|
3044
|
+
const allSamples = [];
|
|
3042
3045
|
for (let attempt = 0; attempt <= this.MAX_PATTERN_RETRIES; attempt++) {
|
|
3043
3046
|
const samplePageNos = this.selectRandomSamples(
|
|
3044
3047
|
pageNos,
|
|
@@ -3059,6 +3062,20 @@ var PageRangeParser = class extends VisionLLMComponent {
|
|
|
3059
3062
|
);
|
|
3060
3063
|
usageList.push(result.usage);
|
|
3061
3064
|
const samples = result.samples;
|
|
3065
|
+
allSamples.push(...samples);
|
|
3066
|
+
const allNull = samples.every((s) => s.startPageNo === null);
|
|
3067
|
+
if (allNull) {
|
|
3068
|
+
consecutiveAllNullAttempts++;
|
|
3069
|
+
if (consecutiveAllNullAttempts >= MAX_ALL_NULL_ATTEMPTS) {
|
|
3070
|
+
this.log(
|
|
3071
|
+
"warn",
|
|
3072
|
+
`All samples returned null for ${MAX_ALL_NULL_ATTEMPTS} consecutive attempts, pages likely have no page numbers`
|
|
3073
|
+
);
|
|
3074
|
+
break;
|
|
3075
|
+
}
|
|
3076
|
+
} else {
|
|
3077
|
+
consecutiveAllNullAttempts = 0;
|
|
3078
|
+
}
|
|
3062
3079
|
const pattern = this.detectPattern(samples);
|
|
3063
3080
|
if (pattern.pattern !== "unknown" /* UNKNOWN */) {
|
|
3064
3081
|
this.log(
|
|
@@ -3075,9 +3092,29 @@ var PageRangeParser = class extends VisionLLMComponent {
|
|
|
3075
3092
|
`Pattern detection failed, attempt ${attempt + 1}/${this.MAX_PATTERN_RETRIES + 1}`
|
|
3076
3093
|
);
|
|
3077
3094
|
}
|
|
3078
|
-
|
|
3079
|
-
|
|
3095
|
+
const allValidSamples = allSamples.filter((s) => s.startPageNo !== null);
|
|
3096
|
+
if (allValidSamples.length >= 2) {
|
|
3097
|
+
const finalPattern = this.detectPattern(allSamples);
|
|
3098
|
+
if (finalPattern.pattern !== "unknown" /* UNKNOWN */) {
|
|
3099
|
+
this.log(
|
|
3100
|
+
"info",
|
|
3101
|
+
`Pattern detected from accumulated samples: ${finalPattern.pattern}`
|
|
3102
|
+
);
|
|
3103
|
+
return {
|
|
3104
|
+
pageRangeMap: this.applyPattern(pageNos, finalPattern),
|
|
3105
|
+
usage: usageList
|
|
3106
|
+
};
|
|
3107
|
+
}
|
|
3108
|
+
}
|
|
3109
|
+
this.log(
|
|
3110
|
+
"warn",
|
|
3111
|
+
`Could not detect page pattern after ${consecutiveAllNullAttempts >= MAX_ALL_NULL_ATTEMPTS ? consecutiveAllNullAttempts : this.MAX_PATTERN_RETRIES + 1} attempts for group with ${pageNos.length} pages, marking as failed`
|
|
3080
3112
|
);
|
|
3113
|
+
const fallbackMap = {};
|
|
3114
|
+
for (const pageNo of pageNos) {
|
|
3115
|
+
fallbackMap[pageNo] = { startPageNo: 0, endPageNo: 0 };
|
|
3116
|
+
}
|
|
3117
|
+
return { pageRangeMap: fallbackMap, usage: usageList };
|
|
3081
3118
|
}
|
|
3082
3119
|
/**
|
|
3083
3120
|
* Select random samples from page numbers
|