@heripo/pdf-parser 0.1.27 → 0.1.29
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/README.ko.md +95 -18
- package/README.md +96 -18
- package/dist/index.cjs +41 -77
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +41 -77
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.ko.md
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
- [설치](#설치)
|
|
22
22
|
- [사용법](#사용법)
|
|
23
23
|
- [OCR 전략 시스템](#ocr-전략-시스템)
|
|
24
|
+
- [Review Assistance](#review-assistance)
|
|
24
25
|
- [문서 유형 검증](#문서-유형-검증)
|
|
25
26
|
- [대용량 PDF 청크 변환](#대용량-pdf-청크-변환)
|
|
26
27
|
- [이미지 PDF 폴백](#이미지-pdf-폴백)
|
|
@@ -30,18 +31,20 @@
|
|
|
30
31
|
- [시스템 의존성 상세](#시스템-의존성-상세)
|
|
31
32
|
- [API 문서](#api-문서)
|
|
32
33
|
- [문제 해결](#문제-해결)
|
|
34
|
+
- [후원](#후원)
|
|
33
35
|
- [라이선스](#라이선스)
|
|
34
36
|
|
|
35
37
|
## 주요 기능
|
|
36
38
|
|
|
37
39
|
- **고품질 OCR**: Docling SDK를 활용한 문서 인식 (ocrmac / Apple Vision Framework)
|
|
38
|
-
-
|
|
40
|
+
- **한국어 보고서 VLM 보정**: 한국어 보고서를 자동 감지하고 모든 페이지에 VLM 텍스트 보정을 적용
|
|
39
41
|
- **Apple Silicon 최적화**: M1/M2/M3/M4/M5 칩에서 GPU 가속 지원
|
|
40
42
|
- **자동 환경 설정**: Python 가상환경 및 docling-serve 자동 설치
|
|
41
43
|
- **이미지 추출**: PDF 내 이미지 자동 추출 및 저장
|
|
42
44
|
- **문서 유형 검증**: LLM 기반 고고학 보고서 여부 검증 (선택)
|
|
43
45
|
- **청크 변환**: 대용량 PDF를 청크로 분할하여 안정적으로 처리
|
|
44
46
|
- **이미지 PDF 폴백**: 변환 실패 시 이미지 기반 PDF로 자동 재시도
|
|
47
|
+
- **Review Assistance**: 선택적 page-level VLM review로 audit proposal을 기록하고 고신뢰도 수정만 자동 적용
|
|
45
48
|
- **AbortSignal 지원**: 진행 중인 파싱 작업 취소
|
|
46
49
|
- **서버 크래시 복구**: ECONNREFUSED 발생 시 docling-serve 자동 재시작
|
|
47
50
|
|
|
@@ -49,7 +52,7 @@
|
|
|
49
52
|
|
|
50
53
|
### 시스템 요구사항
|
|
51
54
|
|
|
52
|
-
- **macOS** with Apple Silicon (M1/M2/M3) - 최적 성능을 위해 권장
|
|
55
|
+
- **macOS** with Apple Silicon (M1/M2/M3/M4/M5) - 최적 성능을 위해 권장
|
|
53
56
|
- **macOS** with Intel - 지원되지만 속도가 느림
|
|
54
57
|
- **Linux/Windows** - 현재 지원하지 않음
|
|
55
58
|
|
|
@@ -61,7 +64,7 @@
|
|
|
61
64
|
brew install node
|
|
62
65
|
```
|
|
63
66
|
|
|
64
|
-
#### 2. pnpm >=
|
|
67
|
+
#### 2. pnpm >= 10.0.0
|
|
65
68
|
|
|
66
69
|
```bash
|
|
67
70
|
npm install -g pnpm
|
|
@@ -123,13 +126,13 @@ brew install imagemagick ghostscript
|
|
|
123
126
|
|
|
124
127
|
```bash
|
|
125
128
|
# npm으로 설치
|
|
126
|
-
npm install @heripo/pdf-parser
|
|
129
|
+
npm install @heripo/pdf-parser @heripo/logger
|
|
127
130
|
|
|
128
131
|
# pnpm으로 설치
|
|
129
|
-
pnpm add @heripo/pdf-parser
|
|
132
|
+
pnpm add @heripo/pdf-parser @heripo/logger
|
|
130
133
|
|
|
131
134
|
# yarn으로 설치
|
|
132
|
-
yarn add @heripo/pdf-parser
|
|
135
|
+
yarn add @heripo/pdf-parser @heripo/logger
|
|
133
136
|
```
|
|
134
137
|
|
|
135
138
|
## 사용법
|
|
@@ -140,7 +143,12 @@ yarn add @heripo/pdf-parser
|
|
|
140
143
|
import { Logger } from '@heripo/logger';
|
|
141
144
|
import { PDFParser } from '@heripo/pdf-parser';
|
|
142
145
|
|
|
143
|
-
const logger = Logger(
|
|
146
|
+
const logger = new Logger({
|
|
147
|
+
debug: (...args) => console.debug('[heripo]', ...args),
|
|
148
|
+
info: (...args) => console.info('[heripo]', ...args),
|
|
149
|
+
warn: (...args) => console.warn('[heripo]', ...args),
|
|
150
|
+
error: (...args) => console.error('[heripo]', ...args),
|
|
151
|
+
});
|
|
144
152
|
|
|
145
153
|
// PDFParser 인스턴스 생성 (logger는 필수)
|
|
146
154
|
const pdfParser = new PDFParser({
|
|
@@ -154,13 +162,13 @@ await pdfParser.init();
|
|
|
154
162
|
// PDF 파싱
|
|
155
163
|
const tokenUsageReport = await pdfParser.parse(
|
|
156
164
|
'file:///path/to/report.pdf', // PDF URL (file:// 또는 http://)
|
|
157
|
-
'report-001',
|
|
165
|
+
'report-001', // 리포트 ID
|
|
158
166
|
async (outputPath) => {
|
|
159
167
|
// 변환 완료 콜백
|
|
160
168
|
console.log('PDF 변환 완료:', outputPath);
|
|
161
169
|
},
|
|
162
|
-
false,
|
|
163
|
-
{},
|
|
170
|
+
false, // cleanupAfterCallback
|
|
171
|
+
{}, // PDFConvertOptions
|
|
164
172
|
);
|
|
165
173
|
|
|
166
174
|
// 토큰 사용량 리포트 (LLM 사용이 없으면 null)
|
|
@@ -201,6 +209,15 @@ const tokenUsageReport = await pdfParser.parse(
|
|
|
201
209
|
// 문서 유형 검증
|
|
202
210
|
documentValidationModel: openai('gpt-5.1'),
|
|
203
211
|
|
|
212
|
+
// 선택적 page-level review assistance
|
|
213
|
+
reviewAssistance: {
|
|
214
|
+
enabled: true,
|
|
215
|
+
autoApplyThreshold: 0.85,
|
|
216
|
+
proposalThreshold: 0.5,
|
|
217
|
+
outputLanguage: 'ko-KR',
|
|
218
|
+
},
|
|
219
|
+
onReviewAssistanceProgress: (event) => console.log(event),
|
|
220
|
+
|
|
204
221
|
// 대용량 PDF 청크 변환
|
|
205
222
|
chunkedConversion: true,
|
|
206
223
|
chunkSize: 50,
|
|
@@ -233,16 +250,16 @@ await pdfParser.dispose();
|
|
|
233
250
|
|
|
234
251
|
**ocrmac(Apple Vision Framework)은 매우 우수한 OCR 엔진입니다** -- 무료이고, GPU 가속을 지원하며, 고품질 결과를 제공합니다. 수천~수백만 권의 고고학 보고서를 처리할 때 이만한 솔루션이 없습니다.
|
|
235
252
|
|
|
236
|
-
**그러나
|
|
253
|
+
**그러나 한국어 고고학 보고서는 문자 체계 인식 보정이 자주 필요합니다.** 한자 복원, CJK mojibake, 음독 치환, 기관명 등은 표준 OCR만으로 안정적으로 처리하기 어렵습니다. VLM을 기본 OCR 엔진으로 쓰는 대신, 빠른 ocrmac 파이프라인을 먼저 실행한 뒤 한국어 보고서에 VLM 텍스트 보정을 적용합니다.
|
|
237
254
|
|
|
238
|
-
### 2단계 감지 (`OcrStrategySampler`)
|
|
255
|
+
### 2단계 한국어 감지 (`OcrStrategySampler`)
|
|
239
256
|
|
|
240
|
-
1. **텍스트 레이어 사전 검사** (비용 없음): `pdftotext`로 문서의 텍스트 레이어를 추출하여
|
|
241
|
-
2. **VLM 샘플링** (필요 시에만): 최대 15페이지를 샘플링(앞뒤 10%는 표지·부록으로 제외)하여 Vision LLM으로
|
|
257
|
+
1. **텍스트 레이어 사전 검사** (비용 없음): `pdftotext`로 문서의 텍스트 레이어를 추출하여 한글을 확인합니다. 한글이 있으면 즉시 한국어 문서로 판별합니다.
|
|
258
|
+
2. **VLM 샘플링** (필요 시에만): 최대 15페이지를 샘플링(앞뒤 10%는 표지·부록으로 제외)하여 Vision LLM으로 언어를 판정합니다. `ko-KR` 감지 시 즉시 종료합니다.
|
|
242
259
|
|
|
243
|
-
###
|
|
260
|
+
### 전체 문서 보정 (`VlmTextCorrector`)
|
|
244
261
|
|
|
245
|
-
|
|
262
|
+
한국어 보고서가 감지되면, 모든 페이지를 VLM에 전송하여 보정합니다:
|
|
246
263
|
|
|
247
264
|
- 각 페이지의 OCR 텍스트 요소와 표 셀을 추출
|
|
248
265
|
- `pdftotext` 참조 텍스트를 품질 기준으로 활용
|
|
@@ -261,7 +278,7 @@ const tokenUsageReport = await pdfParser.parse(
|
|
|
261
278
|
// OCR 전략 샘플링 활성화 (Vision LLM 모델 제공)
|
|
262
279
|
strategySamplerModel: openai('gpt-5.1'),
|
|
263
280
|
|
|
264
|
-
// VLM 텍스트 보정 모델 (
|
|
281
|
+
// VLM 텍스트 보정 모델 (한국어 보고서 감지 시 필요)
|
|
265
282
|
vlmProcessorModel: openai('gpt-5.1'),
|
|
266
283
|
|
|
267
284
|
// VLM 페이지 처리 동시성 (기본값: 1)
|
|
@@ -273,6 +290,42 @@ const tokenUsageReport = await pdfParser.parse(
|
|
|
273
290
|
);
|
|
274
291
|
```
|
|
275
292
|
|
|
293
|
+
## Review Assistance
|
|
294
|
+
|
|
295
|
+
`reviewAssistance`는 Docling 변환 후 선택적으로 실행되는 page-level VLM
|
|
296
|
+
review입니다. 렌더링된 페이지 이미지, 텍스트, 테이블, 캡션, 그림, reading
|
|
297
|
+
order, role, bounding box, 도메인 패턴을 점검하고, 고신뢰도 수정만
|
|
298
|
+
`result.json`에 적용하면서 audit report를 남깁니다.
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
const tokenUsageReport = await pdfParser.parse(
|
|
302
|
+
'file:///path/to/input.pdf',
|
|
303
|
+
'report-001',
|
|
304
|
+
async (outputPath) => console.log(outputPath),
|
|
305
|
+
false,
|
|
306
|
+
{
|
|
307
|
+
strategySamplerModel: openai('gpt-5.1'),
|
|
308
|
+
vlmProcessorModel: openai('gpt-5.1'),
|
|
309
|
+
reviewAssistance: {
|
|
310
|
+
enabled: true,
|
|
311
|
+
autoApplyThreshold: 0.85,
|
|
312
|
+
proposalThreshold: 0.5,
|
|
313
|
+
maxRetries: 3,
|
|
314
|
+
temperature: 0,
|
|
315
|
+
outputLanguage: 'ko-KR',
|
|
316
|
+
},
|
|
317
|
+
onReviewAssistanceProgress: (event) => {
|
|
318
|
+
console.log(event.substage, event.status, event.pageNo);
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
);
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Review Assistance는 로컬 `file://` PDF와 `vlmProcessorModel` 또는
|
|
325
|
+
`strategySamplerModel`이 필요합니다. 고신뢰도 수정은 `result.json`에 적용하고,
|
|
326
|
+
원본 snapshot은 `result_review_origin.json`, `result_ocr_origin.json`에 보존하며,
|
|
327
|
+
페이지별 결정, 이슈, proposal, 요약 count는 `review_assistance.json`에 기록합니다.
|
|
328
|
+
|
|
276
329
|
## 문서 유형 검증
|
|
277
330
|
|
|
278
331
|
LLM 기반으로 PDF가 고고학 발굴조사보고서인지 검증하는 선택적 기능입니다. `documentValidationModel`을 제공하면 파서가 PDF에서 텍스트를 추출하고 LLM을 사용하여 문서 유형을 확인한 후 처리합니다. 검증에 실패하면 `InvalidDocumentTypeError`가 발생합니다.
|
|
@@ -404,7 +457,7 @@ try {
|
|
|
404
457
|
### 핵심 장점
|
|
405
458
|
|
|
406
459
|
- **비용**: 클라우드 OCR 대비 100배 이상 저렴 (무료)
|
|
407
|
-
- **성능**: Apple Silicon M1/M2/M3에서 GPU 가속으로 빠른 처리
|
|
460
|
+
- **성능**: Apple Silicon M1/M2/M3/M4/M5에서 GPU 가속으로 빠른 처리
|
|
408
461
|
- **품질**: 복잡한 레이아웃의 문서도 정확히 인식
|
|
409
462
|
- **프라이버시**: 문서가 외부 서버로 전송되지 않음
|
|
410
463
|
|
|
@@ -525,6 +578,10 @@ type PDFConvertOptions = {
|
|
|
525
578
|
document_timeout?: number; // 문서 처리 타임아웃 (초)
|
|
526
579
|
documentValidationModel?: LanguageModel; // 문서 유형 검증용 LLM
|
|
527
580
|
|
|
581
|
+
// Review Assistance
|
|
582
|
+
reviewAssistance?: boolean | ReviewAssistanceOptions; // 선택적 page-level review
|
|
583
|
+
onReviewAssistanceProgress?: (event: ReviewAssistanceProgressEvent) => void; // 진행 상황 callback
|
|
584
|
+
|
|
528
585
|
// 청크 변환 (대용량 PDF)
|
|
529
586
|
chunkedConversion?: boolean; // 청크 변환 활성화
|
|
530
587
|
chunkSize?: number; // 청크당 페이지 수
|
|
@@ -537,6 +594,19 @@ type PDFConvertOptions = {
|
|
|
537
594
|
};
|
|
538
595
|
```
|
|
539
596
|
|
|
597
|
+
### ReviewAssistanceOptions
|
|
598
|
+
|
|
599
|
+
```typescript
|
|
600
|
+
interface ReviewAssistanceOptions {
|
|
601
|
+
enabled?: boolean; // page-level review assistance 활성화
|
|
602
|
+
autoApplyThreshold?: number; // 자동 적용 최소 confidence (기본값: 0.85)
|
|
603
|
+
proposalThreshold?: number; // sidecar proposal 최소 confidence (기본값: 0.5)
|
|
604
|
+
maxRetries?: number; // page-level VLM 호출별 최대 재시도 횟수 (기본값: 3)
|
|
605
|
+
temperature?: number; // VLM 생성 temperature (기본값: 0)
|
|
606
|
+
outputLanguage?: string; // 사람이 읽는 review reason 언어 (기본값: en-US)
|
|
607
|
+
}
|
|
608
|
+
```
|
|
609
|
+
|
|
540
610
|
### ConvertWithStrategyResult
|
|
541
611
|
|
|
542
612
|
```typescript
|
|
@@ -665,6 +735,13 @@ Docling SDK의 로컬 OCR은 macOS에서 Apple Metal GPU 가속을 활용해 성
|
|
|
665
735
|
- [@heripo/document-processor](../document-processor) - 문서 구조 분석 및 LLM 처리
|
|
666
736
|
- [@heripo/model](../model) - 데이터 모델 및 타입 정의
|
|
667
737
|
|
|
738
|
+
## 후원
|
|
739
|
+
|
|
740
|
+
heripo lab의 오픈소스 연구를 후원하려면 다음 경로를 이용할 수 있습니다:
|
|
741
|
+
|
|
742
|
+
- [Open Collective](https://opencollective.com/heripo-project): 전반적인 프로젝트 후원
|
|
743
|
+
- [fairy.hada.io/@heripo](https://fairy.hada.io/@heripo): 한국인 개인 후원자를 위한 원화 결제
|
|
744
|
+
|
|
668
745
|
## 라이선스
|
|
669
746
|
|
|
670
747
|
이 패키지는 [Apache License 2.0](../../LICENSE) 라이선스 하에 배포됩니다.
|
package/README.md
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
- [Installation](#installation)
|
|
22
22
|
- [Usage](#usage)
|
|
23
23
|
- [OCR Strategy System](#ocr-strategy-system)
|
|
24
|
+
- [Review Assistance](#review-assistance)
|
|
24
25
|
- [Document Type Validation](#document-type-validation)
|
|
25
26
|
- [Large PDF Chunked Conversion](#large-pdf-chunked-conversion)
|
|
26
27
|
- [Image PDF Fallback](#image-pdf-fallback)
|
|
@@ -30,18 +31,20 @@
|
|
|
30
31
|
- [System Dependencies Details](#system-dependencies-details)
|
|
31
32
|
- [API Documentation](#api-documentation)
|
|
32
33
|
- [Troubleshooting](#troubleshooting)
|
|
34
|
+
- [Sponsor](#sponsor)
|
|
33
35
|
- [License](#license)
|
|
34
36
|
|
|
35
37
|
## Key Features
|
|
36
38
|
|
|
37
39
|
- **High-Quality OCR**: Document recognition using Docling SDK (ocrmac / Apple Vision Framework)
|
|
38
|
-
- **
|
|
40
|
+
- **Korean Report VLM Correction**: Automatically detects Korean reports and applies VLM text correction to all pages
|
|
39
41
|
- **Apple Silicon Optimized**: GPU acceleration on M1/M2/M3/M4/M5 chips
|
|
40
42
|
- **Automatic Environment Setup**: Automatic Python virtual environment and docling-serve installation
|
|
41
43
|
- **Image Extraction**: Automatic extraction and saving of images from PDFs
|
|
42
44
|
- **Document Type Validation**: Optional LLM-based validation that a PDF is an archaeological report
|
|
43
45
|
- **Chunked Conversion**: Split large PDFs into chunks for reliable processing
|
|
44
46
|
- **Image PDF Fallback**: Automatic fallback to image-based PDF when conversion fails
|
|
47
|
+
- **Review Assistance**: Optional page-level VLM review that writes audit proposals and can auto-apply high-confidence fixes
|
|
45
48
|
- **AbortSignal Support**: Cancel ongoing parsing operations
|
|
46
49
|
- **Server Crash Recovery**: Automatic restart of docling-serve on ECONNREFUSED
|
|
47
50
|
|
|
@@ -49,7 +52,7 @@
|
|
|
49
52
|
|
|
50
53
|
### System Requirements
|
|
51
54
|
|
|
52
|
-
- **macOS** with Apple Silicon (M1/M2/M3) - Recommended for optimal performance
|
|
55
|
+
- **macOS** with Apple Silicon (M1/M2/M3/M4/M5) - Recommended for optimal performance
|
|
53
56
|
- **macOS** with Intel - Supported but slower
|
|
54
57
|
- **Linux/Windows** - Currently not supported
|
|
55
58
|
|
|
@@ -61,7 +64,7 @@
|
|
|
61
64
|
brew install node
|
|
62
65
|
```
|
|
63
66
|
|
|
64
|
-
#### 2. pnpm >=
|
|
67
|
+
#### 2. pnpm >= 10.0.0
|
|
65
68
|
|
|
66
69
|
```bash
|
|
67
70
|
npm install -g pnpm
|
|
@@ -123,13 +126,13 @@ This setup runs only once and may take 5-10 minutes depending on internet connec
|
|
|
123
126
|
|
|
124
127
|
```bash
|
|
125
128
|
# Install with npm
|
|
126
|
-
npm install @heripo/pdf-parser
|
|
129
|
+
npm install @heripo/pdf-parser @heripo/logger
|
|
127
130
|
|
|
128
131
|
# Install with pnpm
|
|
129
|
-
pnpm add @heripo/pdf-parser
|
|
132
|
+
pnpm add @heripo/pdf-parser @heripo/logger
|
|
130
133
|
|
|
131
134
|
# Install with yarn
|
|
132
|
-
yarn add @heripo/pdf-parser
|
|
135
|
+
yarn add @heripo/pdf-parser @heripo/logger
|
|
133
136
|
```
|
|
134
137
|
|
|
135
138
|
## Usage
|
|
@@ -140,7 +143,12 @@ yarn add @heripo/pdf-parser
|
|
|
140
143
|
import { Logger } from '@heripo/logger';
|
|
141
144
|
import { PDFParser } from '@heripo/pdf-parser';
|
|
142
145
|
|
|
143
|
-
const logger = Logger(
|
|
146
|
+
const logger = new Logger({
|
|
147
|
+
debug: (...args) => console.debug('[heripo]', ...args),
|
|
148
|
+
info: (...args) => console.info('[heripo]', ...args),
|
|
149
|
+
warn: (...args) => console.warn('[heripo]', ...args),
|
|
150
|
+
error: (...args) => console.error('[heripo]', ...args),
|
|
151
|
+
});
|
|
144
152
|
|
|
145
153
|
// Create PDFParser instance (logger is required)
|
|
146
154
|
const pdfParser = new PDFParser({
|
|
@@ -154,13 +162,13 @@ await pdfParser.init();
|
|
|
154
162
|
// Parse PDF
|
|
155
163
|
const tokenUsageReport = await pdfParser.parse(
|
|
156
164
|
'file:///path/to/report.pdf', // PDF URL (file:// or http://)
|
|
157
|
-
'report-001',
|
|
165
|
+
'report-001', // Report ID
|
|
158
166
|
async (outputPath) => {
|
|
159
167
|
// Conversion complete callback
|
|
160
168
|
console.log('PDF conversion complete:', outputPath);
|
|
161
169
|
},
|
|
162
|
-
false,
|
|
163
|
-
{},
|
|
170
|
+
false, // cleanupAfterCallback
|
|
171
|
+
{}, // PDFConvertOptions
|
|
164
172
|
);
|
|
165
173
|
|
|
166
174
|
// Token usage report (null when no LLM usage)
|
|
@@ -201,6 +209,15 @@ const tokenUsageReport = await pdfParser.parse(
|
|
|
201
209
|
// Document validation
|
|
202
210
|
documentValidationModel: openai('gpt-5.1'),
|
|
203
211
|
|
|
212
|
+
// Optional page-level review assistance
|
|
213
|
+
reviewAssistance: {
|
|
214
|
+
enabled: true,
|
|
215
|
+
autoApplyThreshold: 0.85,
|
|
216
|
+
proposalThreshold: 0.5,
|
|
217
|
+
outputLanguage: 'en-US',
|
|
218
|
+
},
|
|
219
|
+
onReviewAssistanceProgress: (event) => console.log(event),
|
|
220
|
+
|
|
204
221
|
// Chunked conversion for large PDFs
|
|
205
222
|
chunkedConversion: true,
|
|
206
223
|
chunkSize: 50,
|
|
@@ -233,16 +250,16 @@ await pdfParser.dispose();
|
|
|
233
250
|
|
|
234
251
|
**ocrmac (Apple Vision Framework) is an excellent OCR engine** -- it's free, GPU-accelerated, and delivers high-quality results. For processing thousands to millions of archaeological reports, there's no better solution.
|
|
235
252
|
|
|
236
|
-
**However,
|
|
253
|
+
**However, Korean archaeological reports often need script-aware correction.** Hanja restoration, CJK mojibake, phonetic substitutions, and institution names can be unreliable with standard OCR alone. Rather than using VLM as the primary OCR engine, the system runs the fast ocrmac pipeline first and then applies VLM text correction to Korean reports.
|
|
237
254
|
|
|
238
|
-
### Two-Stage Detection (`OcrStrategySampler`)
|
|
255
|
+
### Two-Stage Korean Detection (`OcrStrategySampler`)
|
|
239
256
|
|
|
240
|
-
1. **Text Layer Pre-Check** (zero cost): Extracts the document's text layer using `pdftotext` and checks for
|
|
241
|
-
2. **VLM Sampling** (only when needed): Samples up to 15 pages (trimming 10% from front/back to skip covers and appendices) and analyzes them with a Vision LLM. Uses early exit
|
|
257
|
+
1. **Text Layer Pre-Check** (zero cost): Extracts the document's text layer using `pdftotext` and checks for Hangul. If Hangul is present, the document is immediately treated as Korean.
|
|
258
|
+
2. **VLM Sampling** (only when needed): Samples up to 15 pages (trimming 10% from front/back to skip covers and appendices) and analyzes them with a Vision LLM. Uses early exit when `ko-KR` is detected.
|
|
242
259
|
|
|
243
|
-
###
|
|
260
|
+
### Full-Document Correction (`VlmTextCorrector`)
|
|
244
261
|
|
|
245
|
-
When
|
|
262
|
+
When a Korean report is detected, every page is sent to the VLM for correction:
|
|
246
263
|
|
|
247
264
|
- Extracts OCR text elements and table cells from each page
|
|
248
265
|
- Uses `pdftotext` reference text as a quality anchor
|
|
@@ -261,7 +278,7 @@ const tokenUsageReport = await pdfParser.parse(
|
|
|
261
278
|
// Enable OCR strategy sampling (provide a Vision LLM model)
|
|
262
279
|
strategySamplerModel: openai('gpt-5.1'),
|
|
263
280
|
|
|
264
|
-
// VLM model for text correction (required when
|
|
281
|
+
// VLM model for text correction (required when Korean reports are detected)
|
|
265
282
|
vlmProcessorModel: openai('gpt-5.1'),
|
|
266
283
|
|
|
267
284
|
// Concurrency for VLM page processing (default: 1)
|
|
@@ -273,6 +290,43 @@ const tokenUsageReport = await pdfParser.parse(
|
|
|
273
290
|
);
|
|
274
291
|
```
|
|
275
292
|
|
|
293
|
+
## Review Assistance
|
|
294
|
+
|
|
295
|
+
`reviewAssistance` enables an optional page-level VLM review after Docling
|
|
296
|
+
conversion. It inspects rendered page images, text, tables, captions, pictures,
|
|
297
|
+
reading order, roles, bounding boxes, and domain patterns, then writes an audit
|
|
298
|
+
report while applying only high-confidence fixes.
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
const tokenUsageReport = await pdfParser.parse(
|
|
302
|
+
'file:///path/to/input.pdf',
|
|
303
|
+
'report-001',
|
|
304
|
+
async (outputPath) => console.log(outputPath),
|
|
305
|
+
false,
|
|
306
|
+
{
|
|
307
|
+
strategySamplerModel: openai('gpt-5.1'),
|
|
308
|
+
vlmProcessorModel: openai('gpt-5.1'),
|
|
309
|
+
reviewAssistance: {
|
|
310
|
+
enabled: true,
|
|
311
|
+
autoApplyThreshold: 0.85,
|
|
312
|
+
proposalThreshold: 0.5,
|
|
313
|
+
maxRetries: 3,
|
|
314
|
+
temperature: 0,
|
|
315
|
+
outputLanguage: 'en-US',
|
|
316
|
+
},
|
|
317
|
+
onReviewAssistanceProgress: (event) => {
|
|
318
|
+
console.log(event.substage, event.status, event.pageNo);
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
);
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
Review Assistance requires a local `file://` PDF and either
|
|
325
|
+
`vlmProcessorModel` or `strategySamplerModel`. It updates `result.json` with
|
|
326
|
+
auto-applied fixes, keeps snapshots in `result_review_origin.json` and
|
|
327
|
+
`result_ocr_origin.json`, and writes `review_assistance.json` containing
|
|
328
|
+
per-page decisions, issues, proposals, and summary counts.
|
|
329
|
+
|
|
276
330
|
## Document Type Validation
|
|
277
331
|
|
|
278
332
|
Optional LLM-based validation that a PDF is an archaeological investigation report. When `documentValidationModel` is provided, the parser extracts text from the PDF and uses the LLM to verify the document type before processing. If validation fails, an `InvalidDocumentTypeError` is thrown.
|
|
@@ -404,7 +458,7 @@ Archaeological excavation report PDFs have the following characteristics:
|
|
|
404
458
|
### Key Advantages
|
|
405
459
|
|
|
406
460
|
- **Cost**: 100x+ cheaper than cloud OCR (free)
|
|
407
|
-
- **Performance**: Fast processing with GPU acceleration on Apple Silicon M1/M2/M3
|
|
461
|
+
- **Performance**: Fast processing with GPU acceleration on Apple Silicon M1/M2/M3/M4/M5
|
|
408
462
|
- **Quality**: Accurate recognition even for complex documents
|
|
409
463
|
- **Privacy**: Documents are not sent to external servers
|
|
410
464
|
|
|
@@ -525,6 +579,10 @@ type PDFConvertOptions = {
|
|
|
525
579
|
document_timeout?: number; // Document processing timeout in seconds
|
|
526
580
|
documentValidationModel?: LanguageModel; // LLM for document type validation
|
|
527
581
|
|
|
582
|
+
// Review Assistance
|
|
583
|
+
reviewAssistance?: boolean | ReviewAssistanceOptions; // Optional page-level review
|
|
584
|
+
onReviewAssistanceProgress?: (event: ReviewAssistanceProgressEvent) => void; // Progress callback
|
|
585
|
+
|
|
528
586
|
// Chunked conversion (large PDFs)
|
|
529
587
|
chunkedConversion?: boolean; // Enable chunked conversion
|
|
530
588
|
chunkSize?: number; // Pages per chunk
|
|
@@ -537,6 +595,19 @@ type PDFConvertOptions = {
|
|
|
537
595
|
};
|
|
538
596
|
```
|
|
539
597
|
|
|
598
|
+
### ReviewAssistanceOptions
|
|
599
|
+
|
|
600
|
+
```typescript
|
|
601
|
+
interface ReviewAssistanceOptions {
|
|
602
|
+
enabled?: boolean; // Enable page-level review assistance
|
|
603
|
+
autoApplyThreshold?: number; // Minimum confidence for direct mutation (default: 0.85)
|
|
604
|
+
proposalThreshold?: number; // Minimum confidence for sidecar proposal (default: 0.5)
|
|
605
|
+
maxRetries?: number; // Max retries per page-level VLM call (default: 3)
|
|
606
|
+
temperature?: number; // VLM generation temperature (default: 0)
|
|
607
|
+
outputLanguage?: string; // Human-readable review reason language (default: en-US)
|
|
608
|
+
}
|
|
609
|
+
```
|
|
610
|
+
|
|
540
611
|
### ConvertWithStrategyResult
|
|
541
612
|
|
|
542
613
|
```typescript
|
|
@@ -665,6 +736,13 @@ If you have ideas for supporting Linux while maintaining both performance and co
|
|
|
665
736
|
- [@heripo/document-processor](../document-processor) - Document structure analysis and LLM processing
|
|
666
737
|
- [@heripo/model](../model) - Data models and type definitions
|
|
667
738
|
|
|
739
|
+
## Sponsor
|
|
740
|
+
|
|
741
|
+
If you'd like to support heripo lab's open-source research, you can sponsor us through:
|
|
742
|
+
|
|
743
|
+
- [Open Collective](https://opencollective.com/heripo-project) for general project sponsorship.
|
|
744
|
+
- [fairy.hada.io/@heripo](https://fairy.hada.io/@heripo) for Korean individual supporters who prefer KRW payments.
|
|
745
|
+
|
|
668
746
|
## License
|
|
669
747
|
|
|
670
748
|
This package is distributed under the [Apache License 2.0](../../LICENSE).
|