45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
"""Route file extensions to parsers."""
|
|||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
from rag_cut.parsers.base import BaseParser
|
||
|
|
from rag_cut.parsers.word_parser import WordParser
|
||
|
|
from rag_cut.parsers.image_parser import ImageParser
|
||
|
|
from rag_cut.parsers.pdf_parser import PdfParser
|
||
|
|
from rag_cut.parsers.ppt_parser import PptParser
|
||
|
|
from rag_cut.parsers.text_parser import TextParser
|
||
|
|
from rag_cut.parsers.xlsx_parser import SpreadsheetParser
|
||
|
|
|
||
|
|
PARSERS: dict[str, BaseParser] = {
|
||
|
|
".docx": WordParser(),
|
||
|
|
".doc": WordParser(),
|
||
|
|
".pdf": PdfParser(),
|
||
|
|
".ppt": PptParser(),
|
||
|
|
".pptx": PptParser(),
|
||
|
|
".ppsx": PptParser(),
|
||
|
|
".xlsx": SpreadsheetParser(),
|
||
|
|
".xls": SpreadsheetParser(),
|
||
|
|
".csv": SpreadsheetParser(),
|
||
|
|
".md": TextParser(),
|
||
|
|
".txt": TextParser(),
|
||
|
|
".html": TextParser(),
|
||
|
|
".htm": TextParser(),
|
||
|
|
".json": TextParser(),
|
||
|
|
".xml": TextParser(),
|
||
|
|
".log": TextParser(),
|
||
|
|
".jpg": ImageParser(),
|
||
|
|
".jpeg": ImageParser(),
|
||
|
|
".png": ImageParser(),
|
||
|
|
".bmp": ImageParser(),
|
||
|
|
".gif": ImageParser(),
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def get_parser(path: Path) -> BaseParser:
|
||
|
|
ext = path.suffix.lower()
|
||
|
|
if ext not in PARSERS:
|
||
|
|
raise ValueError(f"Unsupported file type: {ext}")
|
||
|
|
return PARSERS[ext]
|