TextReader¶
Overview¶
The TextReader
class is designed to read text files with specified encoding. It can optionally autodetect file encoding if the specified encoding fails. This class is part of the Euler Graph Database and extends the BaseReader
class.
Arguments¶
file_path
(str): Path to the file to load.encoding
(Optional[str]): File encoding to use. IfNone
, the file will be loaded with the default system encoding.autodetect_encoding
(bool): Whether to try to autodetect the file encoding if the specified encoding fails. Default isFalse
.
Example Usage¶
Here's an example demonstrating how to use the TextReader
class:
from euler.reader.text_reader import TextReader
Initialize the TextReader with file path, encoding, and autodetect_encoding¶
reader = TextReader(file_path="example.txt", encoding="utf-8", autodetect_encoding=True)
Load the document¶
documents = reader.load()
Print the loaded documents¶
for doc in documents:
print(doc.text)
print(doc.metadata)