Package com.bytedesk.kbase.llm_file
Class FileService
java.lang.Object
com.bytedesk.kbase.llm_file.FileService
解析文件内容
https://tika.apache.org/3.2.1/formats.html
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate booleancleanDocumentText(String text) 清理文档文本,移除可能导致问题的特殊字符extractContentSummary(List<org.springframework.ai.document.Document> documents, int maxLength) 智能截取文档内容摘要private StringgetFileExtension(String fileName) private String返回 OCR 使用的 Tesseract 语言设置,默认中英混合。private booleanisImageExt(String ext) private booleanisTikaPreferred(String ext) 根据扩展名判定是否优先交由 Tika 解析。List<org.springframework.ai.document.Document>parseFileContent(UploadEntity upload) https://docs.spring.io/spring-ai/reference/api/etl-pipeline.htmlList<org.springframework.ai.document.Document>readByTika(org.springframework.core.io.Resource resource) List<org.springframework.ai.document.Document>readByTikaWithOcr(org.springframework.core.io.Resource resource, String ocrLanguage) 使用 Apache Tika + Tesseract 进行 OCR 解析,适用扫描 PDF 或图片。List<org.springframework.ai.document.Document>readHtml(org.springframework.core.io.Resource resource) List<org.springframework.ai.document.Document>readJson(org.springframework.core.io.Resource resource) List<org.springframework.ai.document.Document>readMarkdown(org.springframework.core.io.Resource resource) List<org.springframework.ai.document.Document>readPdfPage(org.springframework.core.io.Resource resource) List<org.springframework.ai.document.Document>readPdfParagraph(org.springframework.core.io.Resource resource) List<org.springframework.ai.document.Document>readTxt(org.springframework.core.io.Resource resource)
-
Field Details
-
uploadRestService
-
-
Constructor Details
-
FileService
public FileService()
-
-
Method Details
-
parseFileContent
https://docs.spring.io/spring-ai/reference/api/etl-pipeline.html -
readPdfPage
public List<org.springframework.ai.document.Document> readPdfPage(org.springframework.core.io.Resource resource) -
readPdfParagraph
public List<org.springframework.ai.document.Document> readPdfParagraph(org.springframework.core.io.Resource resource) -
readJson
public List<org.springframework.ai.document.Document> readJson(org.springframework.core.io.Resource resource) -
readMarkdown
public List<org.springframework.ai.document.Document> readMarkdown(org.springframework.core.io.Resource resource) -
readTxt
public List<org.springframework.ai.document.Document> readTxt(org.springframework.core.io.Resource resource) -
readHtml
public List<org.springframework.ai.document.Document> readHtml(org.springframework.core.io.Resource resource) -
readByTika
public List<org.springframework.ai.document.Document> readByTika(org.springframework.core.io.Resource resource) -
readByTikaWithOcr
public List<org.springframework.ai.document.Document> readByTikaWithOcr(org.springframework.core.io.Resource resource, String ocrLanguage) 使用 Apache Tika + Tesseract 进行 OCR 解析,适用扫描 PDF 或图片。 依赖系统已安装 tesseract 可执行程序与对应语言数据,默认使用 chi_sim+eng。 -
extractContentSummary
public String extractContentSummary(List<org.springframework.ai.document.Document> documents, int maxLength) 智能截取文档内容摘要- Parameters:
documents- 文档列表maxLength- 最大长度- Returns:
- 截取后的内容摘要
-
cleanDocumentText
清理文档文本,移除可能导致问题的特殊字符- Parameters:
text- 原始文本- Returns:
- 清理后的文本
-
getFileExtension
-
allBlank
-
isImageExt
-
getOcrLanguage
返回 OCR 使用的 Tesseract 语言设置,默认中英混合。 可后续改为读取配置或环境变量。 -
isTikaPreferred
根据扩展名判定是否优先交由 Tika 解析。 覆盖范围参考 Tika 2.9.0 支持清单(示例集合,非穷举)。
-