kikocis/GraphRAG-SDK public
| 1 | from typing import Iterator |
| 2 | from graphrag_sdk.document import Document |
| 3 | |
| 4 | class TextLoader(): |
| 5 | """ |
| 6 | Load Text |
| 7 | """ |
| 8 | |
| 9 | def __init__(self, path: str) -> None: |
| 10 | """ |
| 11 | Initialize loader |
| 12 | |
| 13 | Parameters: |
| 14 | path (str): path to Text. |
| 15 | """ |
| 16 | |
| 17 | self.path = path |
| 18 | |
| 19 | def load(self) -> Iterator[Document]: |
| 20 | """ |
| 21 | Load Text |
| 22 | |
| 23 | Returns: |
| 24 | Iterator[Document]: document iterator |
| 25 | """ |
| 26 | |
| 27 | with open(self.path, 'r') as f: |
| 28 | yield Document( |
| 29 | f.read() |
| 30 | ) |