mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-13 04:13:35 +08:00
fix: honor parser params and image VLM system_prompt in Go ingestion (#17334)
## Summary Fix the Go ingestion pipeline so that several parser setup switches and the image VLM prompt are actually honored end-to-end (previously the DSL fields existed but the Go code never read them). - **DOCX** (`docx_parser.go`, `docx_postprocess.go`): read `remove_toc` and `remove_header_footer`; apply to both JSON and markdown output paths (outline-based TOC removal with a text-heuristic fallback, plus header/footer section filtering). - **HTML** (`html_parser.go`, `html_postprocess.go`, `text_toc.go`): read `remove_header_footer` (pre-parse strip of `<header>`/`<footer>` and ARIA `banner`/`contentinfo`) and `remove_toc` (post-parse `remove_contents_table` heuristic). - **Markdown** (`markdown_parser.go`): read `flatten_media_to_text` and force media blocks to text when enabled. - **Image VLM** (`media_dispatch.go`): read `system_prompt` instead of `prompt` so the user-configured image VLM prompt is no longer silently dropped (`prompt` remains the video family key). All flags are wired through `ConfigureFromSetup`, which the dispatch layer already invokes for every family, so the behavior is live rather than dead code. ## Test plan - New unit tests: `docx_postprocess_test.go`, `html_parser_test.go`, `text_toc_test.go`, `markdown_parser_test.go`, `media_dispatch_test.go`. - `bash build.sh --test ./internal/parser/parser/... ./internal/ingestion/component/...` ## Notes - The `File` component is excluded from this migration scope. - Relates to the Python→Go parity diff (Parser 1.8–1.11, 1.15).
This commit is contained in:
@@ -25,7 +25,10 @@ import (
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
||||
type HTMLParser struct{}
|
||||
type HTMLParser struct {
|
||||
RemoveHeaderFooter bool
|
||||
RemoveTOC bool
|
||||
}
|
||||
|
||||
func NewHTMLParser() *HTMLParser {
|
||||
return &HTMLParser{}
|
||||
@@ -35,6 +38,21 @@ func (p *HTMLParser) String() string {
|
||||
return "HTMLParser"
|
||||
}
|
||||
|
||||
// ConfigureFromSetup reads the HTML family setup map. Mirrors the
|
||||
// Python parser.py HTML setup keys: remove_header_footer (pre-parse
|
||||
// tag strip) and remove_toc (post-parse text heuristic).
|
||||
func (p *HTMLParser) ConfigureFromSetup(setup map[string]any) {
|
||||
if p == nil || setup == nil {
|
||||
return
|
||||
}
|
||||
if v, ok := setup["remove_header_footer"].(bool); ok {
|
||||
p.RemoveHeaderFooter = v
|
||||
}
|
||||
if v, ok := setup["remove_toc"].(bool); ok {
|
||||
p.RemoveTOC = v
|
||||
}
|
||||
}
|
||||
|
||||
// ParseWithResult emits one item per block-level HTML element
|
||||
// (headings, paragraphs, lists, pre blocks). The walker is a
|
||||
// pure-Go replacement for the previous `fmt.Printf` debug output:
|
||||
@@ -49,12 +67,27 @@ func (p *HTMLParser) String() string {
|
||||
// separate ck_type — the python HtmlParser collapses inline
|
||||
// formatting into the parent block's text.
|
||||
func (p *HTMLParser) ParseWithResult(ctx context.Context, filename string, data []byte) ParseResult {
|
||||
// remove_header_footer: pre-parse strip of <header>/<footer> tags
|
||||
// and ARIA role=banner/contentinfo elements (mirrors Python
|
||||
// parser.py:1083-1084 remove_header_footer_html_blob).
|
||||
if p.RemoveHeaderFooter {
|
||||
cleaned, err := stripHTMLHeaderFooter(data)
|
||||
if err != nil {
|
||||
return ParseResult{Err: fmt.Errorf("html remove_header_footer: %w", err)}
|
||||
}
|
||||
data = cleaned
|
||||
}
|
||||
doc, err := html.Parse(bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return ParseResult{Err: fmt.Errorf("html parse: %w", err)}
|
||||
}
|
||||
var items []map[string]any
|
||||
walkHTMLBlocks(doc, &items)
|
||||
// remove_toc: post-parse text heuristic (mirrors Python
|
||||
// parser.py:1087-1088 remove_toc → remove_contents_table).
|
||||
if p.RemoveTOC {
|
||||
items = removeContentsTable(items, false)
|
||||
}
|
||||
if items == nil {
|
||||
items = []map[string]any{{"text": "", "doc_type_kwd": "text"}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user