CsvLoader class
A document loader for loading documents from CSV or TSV files.
It reads the CSV file specified by filePath and transforms each row into
a Document
object.
You can customize the fields that you want to extract or rename them using fieldsOverride. The field, text, and line delimiters can also be customized using fieldDelimiter, fieldTextDelimiter, fieldTextEndDelimiter, and eol.
The fields are added to the page content in the following format:
{field1Name}: {field1Value}
{field2Name}: {field2Value}
...
{fieldNName}: {fieldNValue}
You can specify a sourceField to use as the source metadata field for each document. Otherwise, the filePath will be used as source.
For loading TSV files, set the fieldDelimiter as \t
.
Example:
final loader = CsvLoader('path/to/file.csv');
final documents = await loader.load();
Constructors
-
CsvLoader.new(String filePath, {List<
String> ? fields, List<String> ? fieldsOverride, String fieldDelimiter = ',', String fieldTextDelimiter = '"', String? fieldTextEndDelimiter, String eol = '\n', String? sourceField, Map<String, dynamic> metadataBuilder(Map<String, dynamic> row, Map<String, dynamic> rowMetadata)?}) - A document loader for loading documents from CSV or TSV files.
Properties
- eol → String
-
The end-of-line character used to separate rows in the CSV file. The eol
is optional for the last row.
final
- fieldDelimiter → String
-
The delimiter used to separate fields in the CSV file.
final
-
fields
→ List<
String> ? -
Optional field to specify which fields from the row to extract and add to
the page content of the document.
final
-
fieldsOverride
↔ List<
String> ? -
Optional field to override the field names from the CSV file.
getter/setter pair
- fieldTextDelimiter → String
-
The delimiter which (optionally) surrounds text / fields.
final
- fieldTextEndDelimiter → String?
-
Optional end delimiter for text. This allows text to be quoted with
different start / end delimiters: Example: «abc».
final
- filePath → String
-
The file path of the CSV file to be loaded.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
metadataBuilder
→ Map<
String, dynamic> Function(Map<String, dynamic> row, Map<String, dynamic> rowMetadata)? -
An optional function to build custom metadata for each document based on
the row content and the default metadata.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sourceField → String?
-
Optional field to specify a source for the document created from each
row. Otherwise filePath will be used as the source for all documents
created from the CSV file.
final
Methods
-
lazyLoad(
) → Stream< Document> - Loads documents lazily.
-
load(
) → Future< List< Document> > -
Loads a list of documents.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited