Class FileSystemDocumentLoader
java.lang.Object
dev.langchain4j.data.document.loader.FileSystemDocumentLoader
-
Method Summary
Modifier and TypeMethodDescriptionstatic DocumentloadDocument(String filePath) Loads aDocumentfrom the specified file path.static DocumentloadDocument(String filePath, DocumentParser documentParser) Loads aDocumentfrom the specified file path.static DocumentloadDocument(Path filePath) static DocumentloadDocument(Path filePath, DocumentParser documentParser) loadDocuments(String directoryPath) LoadsDocuments from the specified directory.loadDocuments(String directoryPath, DocumentParser documentParser) LoadsDocuments from the specified directory.loadDocuments(String directoryPath, PathMatcher pathMatcher) Loads matchingDocuments from the specified directory.loadDocuments(String directoryPath, PathMatcher pathMatcher, DocumentParser documentParser) Loads matchingDocuments from the specified directory.loadDocuments(Path directoryPath) LoadsDocuments from the specified directory.loadDocuments(Path directoryPath, DocumentParser documentParser) LoadsDocuments from the specified directory.loadDocuments(Path directoryPath, PathMatcher pathMatcher) Loads matchingDocuments from the specified directory.loadDocuments(Path directoryPath, PathMatcher pathMatcher, DocumentParser documentParser) Loads matchingDocuments from the specified directory.loadDocumentsRecursively(String directoryPath) Recursively loadsDocuments from the specified directory and its subdirectories.loadDocumentsRecursively(String directoryPath, DocumentParser documentParser) Recursively loadsDocuments from the specified directory and its subdirectories.loadDocumentsRecursively(String directoryPath, PathMatcher pathMatcher) Recursively loads matchingDocuments from the specified directory and its subdirectories.loadDocumentsRecursively(String directoryPath, PathMatcher pathMatcher, DocumentParser documentParser) Recursively loads matchingDocuments from the specified directory and its subdirectories.loadDocumentsRecursively(Path directoryPath) Recursively loadsDocuments from the specified directory and its subdirectories.loadDocumentsRecursively(Path directoryPath, DocumentParser documentParser) Recursively loadsDocuments from the specified directory and its subdirectories.loadDocumentsRecursively(Path directoryPath, PathMatcher pathMatcher) Recursively loads matchingDocuments from the specified directory and its subdirectories.loadDocumentsRecursively(Path directoryPath, PathMatcher pathMatcher, DocumentParser documentParser) Recursively loads matchingDocuments from the specified directory and its subdirectories.
-
Method Details
-
loadDocument
Loads aDocumentfrom the specified filePath.
The file is parsed using the specifiedDocumentParser.
ReturnedDocumentcontains all the textual information from the file.- Parameters:
filePath- The path to the file.documentParser- The parser to be used for parsing text from the file.- Returns:
- document
- Throws:
IllegalArgumentException- If specified path is not a file.- See Also:
-
loadDocument
Loads aDocumentfrom the specified filePath.
The file is parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactory). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
ReturnedDocumentcontains all the textual information from the file.- Parameters:
filePath- The path to the file.- Returns:
- document
- Throws:
IllegalArgumentException- If specified path is not a file.- See Also:
-
loadDocument
Loads aDocumentfrom the specified file path.
The file is parsed using the specifiedDocumentParser.
ReturnedDocumentcontains all the textual information from the file.- Parameters:
filePath- The path to the file.documentParser- The parser to be used for parsing text from the file.- Returns:
- document
- Throws:
IllegalArgumentException- If specified path is not a file.- See Also:
-
loadDocument
Loads aDocumentfrom the specified file path.
The file is parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactory). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
ReturnedDocumentcontains all the textual information from the file.- Parameters:
filePath- The path to the file.- Returns:
- document
- Throws:
IllegalArgumentException- If specified path is not a file.- See Also:
-
loadDocuments
LoadsDocuments from the specified directory. Does not use recursion.
The files are parsed using the specifiedDocumentParser.
Skips anyDocuments that fail to load.- Parameters:
directoryPath- The path to the directory with files.documentParser- The parser to be used for parsing text from each file.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.- See Also:
-
loadDocuments
LoadsDocuments from the specified directory. Does not use recursion.
The files are parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactory). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
Skips anyDocuments that fail to load.- Parameters:
directoryPath- The path to the directory with files.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.- See Also:
-
loadDocuments
LoadsDocuments from the specified directory. Does not use recursion.
The files are parsed using the specifiedDocumentParser.
Skips anyDocuments that fail to load.- Parameters:
directoryPath- The path to the directory with files.documentParser- The parser to be used for parsing text from each file.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.- See Also:
-
loadDocuments
LoadsDocuments from the specified directory. Does not use recursion.
The files are parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactory). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
Skips anyDocuments that fail to load.- Parameters:
directoryPath- The path to the directory with files.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.- See Also:
-
loadDocuments
public static List<Document> loadDocuments(Path directoryPath, PathMatcher pathMatcher, DocumentParser documentParser) Loads matchingDocuments from the specified directory. Does not use recursion.
The files are parsed using the specifiedDocumentParser.
Skips anyDocuments that fail to load.- Parameters:
directoryPath- The path to the directory with files.pathMatcher- Only files whose paths match the providedPathMatcherwill be loaded. For example, usingFileSystems.getDefault().getPathMatcher("glob:*.txt")will load all files fromdirectoryPathwith atxtextension. When traversing the directory, each file path is converted from absolute to relative (relative todirectoryPath) before being matched by apathMatcher. Thus,pathMatchershould use relative patterns.documentParser- The parser to be used for parsing text from each file.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.- See Also:
-
loadDocuments
Loads matchingDocuments from the specified directory. Does not use recursion.
The files are parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactory). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
Skips anyDocuments that fail to load.- Parameters:
directoryPath- The path to the directory with files.pathMatcher- Only files whose paths match the providedPathMatcherwill be loaded. For example, usingFileSystems.getDefault().getPathMatcher("glob:*.txt")will load all files fromdirectoryPathwith atxtextension. When traversing the directory, each file path is converted from absolute to relative (relative todirectoryPath) before being matched by apathMatcher. Thus,pathMatchershould use relative patterns.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.- See Also:
-
loadDocuments
public static List<Document> loadDocuments(String directoryPath, PathMatcher pathMatcher, DocumentParser documentParser) Loads matchingDocuments from the specified directory. Does not use recursion.
The files are parsed using the specifiedDocumentParser.
Skips anyDocuments that fail to load.- Parameters:
directoryPath- The path to the directory with files.pathMatcher- Only files whose paths match the providedPathMatcherwill be loaded. For example, usingFileSystems.getDefault().getPathMatcher("glob:*.txt")will load all files fromdirectoryPathwith atxtextension. When traversing the directory, each file path is converted from absolute to relative (relative todirectoryPath) before being matched by apathMatcher. Thus,pathMatchershould use relative patterns.documentParser- The parser to be used for parsing text from each file.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.- See Also:
-
loadDocuments
Loads matchingDocuments from the specified directory. Does not use recursion.
The files are parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactory). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
Skips anyDocuments that fail to load.- Parameters:
directoryPath- The path to the directory with files.pathMatcher- Only files whose paths match the providedPathMatcherwill be loaded. For example, usingFileSystems.getDefault().getPathMatcher("glob:*.txt")will load all files fromdirectoryPathwith atxtextension. When traversing the directory, each file path is converted from absolute to relative (relative todirectoryPath) before being matched by apathMatcher. Thus,pathMatchershould use relative patterns.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.- See Also:
-
loadDocumentsRecursively
public static List<Document> loadDocumentsRecursively(Path directoryPath, DocumentParser documentParser) Recursively loadsDocuments from the specified directory and its subdirectories.
The files are parsed using the specifiedDocumentParser.
Skips anyDocuments that fail to load.- Parameters:
directoryPath- The path to the directory with files.documentParser- The parser to be used for parsing text from each file.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.- See Also:
-
loadDocumentsRecursively
Recursively loadsDocuments from the specified directory and its subdirectories.
The files are parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactory). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
Skips anyDocuments that fail to load.- Parameters:
directoryPath- The path to the directory with files.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.- See Also:
-
loadDocumentsRecursively
public static List<Document> loadDocumentsRecursively(String directoryPath, DocumentParser documentParser) Recursively loadsDocuments from the specified directory and its subdirectories.
The files are parsed using the specifiedDocumentParser.
Skips anyDocuments that fail to load.- Parameters:
directoryPath- The path to the directory with files.documentParser- The parser to be used for parsing text from each file.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.- See Also:
-
loadDocumentsRecursively
Recursively loadsDocuments from the specified directory and its subdirectories.
The files are parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactory). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
Skips anyDocuments that fail to load.- Parameters:
directoryPath- The path to the directory with files.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.- See Also:
-
loadDocumentsRecursively
public static List<Document> loadDocumentsRecursively(Path directoryPath, PathMatcher pathMatcher, DocumentParser documentParser) Recursively loads matchingDocuments from the specified directory and its subdirectories.
The files are parsed using the specifiedDocumentParser.
Skips anyDocuments that fail to load.- Parameters:
directoryPath- The path to the directory with files.pathMatcher- Only files whose paths match the providedPathMatcherwill be loaded. For example, usingFileSystems.getDefault().getPathMatcher("glob:**.txt")will load all files fromdirectoryPathand its subdirectories with atxtextension. When traversing the directory tree, each file path is converted from absolute to relative (relative todirectoryPath) before being matched by apathMatcher. Thus,pathMatchershould use relative patterns. Please be aware that*.txtpattern (with a single asterisk) will match files only in thedirectoryPath, but it will not match files from the subdirectories ofdirectoryPath.documentParser- The parser to be used for parsing text from each file.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.- See Also:
-
loadDocumentsRecursively
Recursively loads matchingDocuments from the specified directory and its subdirectories.
The files are parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactory). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
Skips anyDocuments that fail to load.- Parameters:
directoryPath- The path to the directory with files.pathMatcher- Only files whose paths match the providedPathMatcherwill be loaded. For example, usingFileSystems.getDefault().getPathMatcher("glob:**.txt")will load all files fromdirectoryPathand its subdirectories with atxtextension. When traversing the directory tree, each file path is converted from absolute to relative (relative todirectoryPath) before being matched by apathMatcher. Thus,pathMatchershould use relative patterns. Please be aware that*.txtpattern (with a single asterisk) will match files only in thedirectoryPath, but it will not match files from the subdirectories ofdirectoryPath.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.- See Also:
-
loadDocumentsRecursively
public static List<Document> loadDocumentsRecursively(String directoryPath, PathMatcher pathMatcher, DocumentParser documentParser) Recursively loads matchingDocuments from the specified directory and its subdirectories.
The files are parsed using the specifiedDocumentParser.
Skips anyDocuments that fail to load.- Parameters:
directoryPath- The path to the directory with files.pathMatcher- Only files whose paths match the providedPathMatcherwill be loaded. For example, usingFileSystems.getDefault().getPathMatcher("glob:**.txt")will load all files fromdirectoryPathand its subdirectories with atxtextension. When traversing the directory tree, each file path is converted from absolute to relative (relative todirectoryPath) before being matched by apathMatcher. Thus,pathMatchershould use relative patterns. Please be aware that*.txtpattern (with a single asterisk) will match files only in thedirectoryPath, but it will not match files from the subdirectories ofdirectoryPath.documentParser- The parser to be used for parsing text from each file.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.- See Also:
-
loadDocumentsRecursively
public static List<Document> loadDocumentsRecursively(String directoryPath, PathMatcher pathMatcher) Recursively loads matchingDocuments from the specified directory and its subdirectories.
The files are parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactory). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
Skips anyDocuments that fail to load.- Parameters:
directoryPath- The path to the directory with files.pathMatcher- Only files whose paths match the providedPathMatcherwill be loaded. For example, usingFileSystems.getDefault().getPathMatcher("glob:**.txt")will load all files fromdirectoryPathand its subdirectories with atxtextension. When traversing the directory tree, each file path is converted from absolute to relative (relative todirectoryPath) before being matched by apathMatcher. Thus,pathMatchershould use relative patterns. Please be aware that*.txtpattern (with a single asterisk) will match files only in thedirectoryPath, but it will not match files from the subdirectories ofdirectoryPath.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.- See Also:
-