mirror of
https://github.com/hwchase17/langchain.git
synced 2025-08-09 13:00:34 +00:00
community[patch]: Implement lazy_load() for EverNoteLoader (#18538)
Covered by `test_evernote_loader.py`
This commit is contained in:
parent
d7dd3cd248
commit
a6b5d45e31
@ -40,10 +40,10 @@ class EverNoteLoader(BaseLoader):
|
|||||||
self.file_path = file_path
|
self.file_path = file_path
|
||||||
self.load_single_document = load_single_document
|
self.load_single_document = load_single_document
|
||||||
|
|
||||||
def load(self) -> List[Document]:
|
def _lazy_load(self) -> Iterator[Document]:
|
||||||
"""Load documents from EverNote export file."""
|
for note in self._parse_note_xml(self.file_path):
|
||||||
documents = [
|
if note.get("content") is not None:
|
||||||
Document(
|
yield Document(
|
||||||
page_content=note["content"],
|
page_content=note["content"],
|
||||||
metadata={
|
metadata={
|
||||||
**{
|
**{
|
||||||
@ -54,19 +54,18 @@ class EverNoteLoader(BaseLoader):
|
|||||||
**{"source": self.file_path},
|
**{"source": self.file_path},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
for note in self._parse_note_xml(self.file_path)
|
|
||||||
if note.get("content") is not None
|
|
||||||
]
|
|
||||||
|
|
||||||
|
def lazy_load(self) -> Iterator[Document]:
|
||||||
|
"""Load documents from EverNote export file."""
|
||||||
if not self.load_single_document:
|
if not self.load_single_document:
|
||||||
return documents
|
yield from self._lazy_load()
|
||||||
|
else:
|
||||||
return [
|
yield Document(
|
||||||
Document(
|
page_content="".join(
|
||||||
page_content="".join([document.page_content for document in documents]),
|
[document.page_content for document in self._lazy_load()]
|
||||||
|
),
|
||||||
metadata={"source": self.file_path},
|
metadata={"source": self.file_path},
|
||||||
)
|
)
|
||||||
]
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _parse_content(content: str) -> str:
|
def _parse_content(content: str) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user