mirror of
https://github.com/hwchase17/langchain
synced 2024-10-29 17:07:25 +00:00
220a7076ac
Inspo https://twitter.com/danielgross/status/1651695062307274754?s=46&t=1zHLap5WG4I_kQPPjfW9fA Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
89 lines
2.4 KiB
Python
89 lines
2.4 KiB
Python
from pathlib import Path
|
|
|
|
from langchain.document_loaders import (
|
|
PDFMinerLoader,
|
|
PDFMinerPDFasHTMLLoader,
|
|
PyMuPDFLoader,
|
|
UnstructuredPDFLoader,
|
|
)
|
|
from langchain.document_loaders.pdf import MathpixPDFLoader
|
|
|
|
|
|
def test_unstructured_pdf_loader() -> None:
|
|
"""Test unstructured loader."""
|
|
file_path = Path(__file__).parent.parent / "examples/hello.pdf"
|
|
loader = UnstructuredPDFLoader(str(file_path))
|
|
docs = loader.load()
|
|
|
|
assert len(docs) == 1
|
|
|
|
|
|
def test_pdfminer_loader() -> None:
|
|
"""Test PDFMiner loader."""
|
|
file_path = Path(__file__).parent.parent / "examples/hello.pdf"
|
|
loader = PDFMinerLoader(str(file_path))
|
|
docs = loader.load()
|
|
|
|
assert len(docs) == 1
|
|
|
|
file_path = Path(__file__).parent.parent / "examples/layout-parser-paper.pdf"
|
|
loader = PDFMinerLoader(str(file_path))
|
|
|
|
docs = loader.load()
|
|
assert len(docs) == 1
|
|
|
|
|
|
def test_pdfminer_pdf_as_html_loader() -> None:
|
|
"""Test PDFMinerPDFasHTMLLoader."""
|
|
file_path = Path(__file__).parent.parent / "examples/hello.pdf"
|
|
loader = PDFMinerPDFasHTMLLoader(str(file_path))
|
|
docs = loader.load()
|
|
|
|
assert len(docs) == 1
|
|
|
|
file_path = Path(__file__).parent.parent / "examples/layout-parser-paper.pdf"
|
|
loader = PDFMinerPDFasHTMLLoader(str(file_path))
|
|
|
|
docs = loader.load()
|
|
assert len(docs) == 1
|
|
|
|
|
|
def test_pymupdf_loader() -> None:
|
|
"""Test PyMuPDF loader."""
|
|
file_path = Path(__file__).parent.parent / "examples/hello.pdf"
|
|
loader = PyMuPDFLoader(str(file_path))
|
|
|
|
docs = loader.load()
|
|
assert len(docs) == 1
|
|
|
|
file_path = Path(__file__).parent.parent / "examples/layout-parser-paper.pdf"
|
|
loader = PyMuPDFLoader(str(file_path))
|
|
|
|
docs = loader.load()
|
|
assert len(docs) == 16
|
|
assert loader.web_path is None
|
|
|
|
web_path = "https://people.sc.fsu.edu/~jpeterson/hello_world.pdf"
|
|
loader = PyMuPDFLoader(web_path)
|
|
|
|
docs = loader.load()
|
|
assert loader.web_path == web_path
|
|
assert loader.file_path != web_path
|
|
assert len(docs) == 1
|
|
|
|
|
|
def test_mathpix_loader() -> None:
|
|
file_path = Path(__file__).parent.parent / "examples/hello.pdf"
|
|
loader = MathpixPDFLoader(str(file_path))
|
|
docs = loader.load()
|
|
|
|
assert len(docs) == 1
|
|
print(docs[0].page_content)
|
|
|
|
file_path = Path(__file__).parent.parent / "examples/layout-parser-paper.pdf"
|
|
loader = MathpixPDFLoader(str(file_path))
|
|
|
|
docs = loader.load()
|
|
assert len(docs) == 1
|
|
print(docs[0].page_content)
|