mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-02 05:47:31 +08:00
Align Go parser backends and PDF pipeline with Python (#16676)
Ports remaining Go parser wiring and PDF backends, adds tenant-aware VLM dispatch, aligns post-processing with Python, and adds end-to-end pipeline coverage with a generated six-page PDF.
This commit is contained in:
38
internal/parser/parser/pdf_parser_plaintext_cgo.go
Normal file
38
internal/parser/parser/pdf_parser_plaintext_cgo.go
Normal file
@@ -0,0 +1,38 @@
|
||||
//go:build cgo
|
||||
|
||||
package parser
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"ragflow/internal/deepdoc/parser/pdf/pdfoxide"
|
||||
)
|
||||
|
||||
func parsePDFWithPlainText(filename string, data []byte, parser *PDFParser) ParseResult {
|
||||
if len(data) == 0 {
|
||||
return emptyPDFResult(filename)
|
||||
}
|
||||
doc, err := pdfoxide.OpenBytes(data)
|
||||
if err != nil {
|
||||
return ParseResult{Err: fmt.Errorf("parser: plain_text open: %w", err)}
|
||||
}
|
||||
defer doc.Close()
|
||||
|
||||
pageCount, err := doc.PageCount()
|
||||
if err != nil {
|
||||
return ParseResult{Err: fmt.Errorf("parser: plain_text page count: %w", err)}
|
||||
}
|
||||
items := make([]map[string]any, 0, pageCount)
|
||||
for page := 0; page < pageCount; page++ {
|
||||
text, err := doc.GetPageText(page)
|
||||
if err != nil {
|
||||
return ParseResult{Err: fmt.Errorf("parser: plain_text page %d: %w", page+1, err)}
|
||||
}
|
||||
items = append(items, map[string]any{
|
||||
"text": text,
|
||||
"doc_type_kwd": "text",
|
||||
"page_number": page + 1,
|
||||
})
|
||||
}
|
||||
return pdfItemsToResult(filename, items, parser.OutputFormat, pageCount)
|
||||
}
|
||||
Reference in New Issue
Block a user