fileparser

package
v0.2.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package fileparser 提供从各种文件格式中提取结构化文档的能力。 所有解析器输出统一的 document.Document 结构,供上层 RAG/检索引擎消费。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CSVParser

type CSVParser struct{}

CSVParser CSV 文件解析器

func NewCSVParser

func NewCSVParser() *CSVParser

func (*CSVParser) Name

func (p *CSVParser) Name() string

func (*CSVParser) Parse

func (p *CSVParser) Parse(reader io.Reader, source string) (*document.Document, error)

type HTMLParser

type HTMLParser struct{}

HTMLParser HTML 文档解析器(基于简单的正则 + 有限的 XML 解析)

func NewHTMLParser

func NewHTMLParser() *HTMLParser

func (*HTMLParser) Name

func (p *HTMLParser) Name() string

func (*HTMLParser) Parse

func (p *HTMLParser) Parse(reader io.Reader, source string) (*document.Document, error)

简单的 HTML 解析策略:先移除 script/style,再提取标题,最后把内容按 <p>/<h>/<table>/<li> 等标签拆分

type JSONParser

type JSONParser struct{}

JSONParser JSON 文件解析器

func NewJSONParser

func NewJSONParser() *JSONParser

func (*JSONParser) Name

func (p *JSONParser) Name() string

func (*JSONParser) Parse

func (p *JSONParser) Parse(reader io.Reader, source string) (*document.Document, error)

type MarkdownParser

type MarkdownParser struct{}

MarkdownParser Markdown 文档解析器

func NewMarkdownParser

func NewMarkdownParser() *MarkdownParser

func (*MarkdownParser) Name

func (p *MarkdownParser) Name() string

func (*MarkdownParser) Parse

func (p *MarkdownParser) Parse(reader io.Reader, source string) (*document.Document, error)

type PDFParser

type PDFParser struct{}

PDFParser PDF 文件解析器 使用 ledongthuc/pdf 库按页提取文本

func NewPDFParser

func NewPDFParser() *PDFParser

func (*PDFParser) Name

func (p *PDFParser) Name() string

func (*PDFParser) Parse

func (p *PDFParser) Parse(reader io.Reader, source string) (*document.Document, error)

type Parser

type Parser interface {
	// Parse 从 reader 解析内容为结构化文档,source 用于错误提示与标题
	Parse(reader io.Reader, source string) (*document.Document, error)

	// Name 返回解析器名称(用于调试)
	Name() string
}

Parser 文件解析器接口

type ParserManager

type ParserManager struct {
	// contains filtered or unexported fields
}

ParserManager 根据文件扩展名选择合适的解析器

func NewManager

func NewManager() *ParserManager

NewManager 创建一个默认的解析器管理器,注册所有支持的格式

func (*ParserManager) GetParserByExtension

func (pm *ParserManager) GetParserByExtension(ext string) Parser

GetParserByExtension 根据扩展名返回对应的解析器

func (*ParserManager) GetParserBySource

func (pm *ParserManager) GetParserBySource(source string) Parser

GetParserBySource 根据文件路径选择解析器

func (*ParserManager) ParseByReader

func (pm *ParserManager) ParseByReader(reader io.Reader, source string) (*document.Document, error)

ParseByReader 使用指定扩展名的解析器来解析 reader

func (*ParserManager) ParseFromPath

func (pm *ParserManager) ParseFromPath(path string) (*document.Document, error)

ParseFromPath 打开文件并解析

func (*ParserManager) SupportedExtensions

func (pm *ParserManager) SupportedExtensions() []string

SupportedExtensions 返回当前管理器支持的所有扩展名

type TextParser

type TextParser struct{}

TextParser 纯文本文件解析器

func NewTextParser

func NewTextParser() *TextParser

func (*TextParser) Name

func (p *TextParser) Name() string

func (*TextParser) Parse

func (p *TextParser) Parse(reader io.Reader, source string) (*document.Document, error)

type WordParser

type WordParser struct{}

WordParser DOCX 文件解析器 DOCX 文件本质是 ZIP 包,内有 word/document.xml 等资源

func NewWordParser

func NewWordParser() *WordParser

func (*WordParser) Name

func (p *WordParser) Name() string

func (*WordParser) Parse

func (p *WordParser) Parse(reader io.Reader, source string) (*document.Document, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL