Class ClassPathDocumentLoader
java.lang.Object
dev.langchain4j.data.document.loader.ClassPathDocumentLoader
DocumentLoader implementation for loading documents using a ClassPathSource- Author:
- Eric Deandrea
-
Method Summary
Modifier and TypeMethodDescriptionstatic DocumentloadDocument(String pathOnClasspath) Loads aDocumentfrom the specified file path.static DocumentloadDocument(String pathOnClasspath, DocumentParser documentParser) Loads aDocumentfrom the specified file path.static DocumentloadDocument(String pathOnClasspath, DocumentParser documentParser, ClassLoader classLoader) Loads aDocumentfrom the specified file path using a given class loader.static DocumentloadDocument(String pathOnClasspath, ClassLoader classLoader) Loads aDocumentfrom the specified file path using a given class loader.loadDocuments(String directoryOnClasspath) LoadsDocuments from the specified directory using a given class loader.loadDocuments(String directoryOnClasspath, DocumentParser documentParser) LoadsDocuments from the specified directory.loadDocuments(String directoryOnClasspath, DocumentParser documentParser, ClassLoader classLoader) LoadsDocuments from the specified directory using a given class loader.loadDocuments(String directoryOnClasspath, ClassLoader classLoader) LoadsDocuments from the specified directory.loadDocuments(String directoryOnClasspath, PathMatcher pathMatcher) Loads matchingDocuments from the specified directory.loadDocuments(String directoryOnClasspath, PathMatcher pathMatcher, DocumentParser documentParser) Loads matchingDocuments from the specified directory.loadDocuments(String directoryOnClasspath, PathMatcher pathMatcher, DocumentParser documentParser, ClassLoader classLoader) Loads matchingDocuments from the specified directory using a given class loader.loadDocuments(String directoryOnClasspath, PathMatcher pathMatcher, ClassLoader classLoader) Loads matchingDocuments from the specified directory using a given class loader.loadDocumentsRecursively(String directoryOnClasspath) Recursively loadsDocuments from the specified directory and its subdirectories.loadDocumentsRecursively(String directoryOnClasspath, DocumentParser documentParser) Recursively loadsDocuments from the specified directory and its subdirectories.loadDocumentsRecursively(String directoryOnClasspath, DocumentParser documentParser, ClassLoader classLoader) Recursively loadsDocuments from the specified directory and its subdirectories using a given class loader.loadDocumentsRecursively(String directoryOnClasspath, ClassLoader classLoader) Recursively loadsDocuments from the specified directory and its subdirectories using a specified classloader.loadDocumentsRecursively(String directoryOnClasspath, PathMatcher pathMatcher) Recursively loads matchingDocuments from the specified directory and its subdirectories.loadDocumentsRecursively(String directoryOnClasspath, PathMatcher pathMatcher, DocumentParser documentParser) Recursively loads matchingDocuments from the specified directory and its subdirectories.loadDocumentsRecursively(String directoryOnClasspath, PathMatcher pathMatcher, DocumentParser documentParser, ClassLoader classLoader) Recursively loads matchingDocuments from the specified directory and its subdirectories using a given class loader.loadDocumentsRecursively(String directoryOnClasspath, PathMatcher pathMatcher, ClassLoader classLoader) Recursively loads matchingDocuments from the specified directory and its subdirectories using a given class loader.
-
Method Details
-
loadDocument
Loads aDocumentfrom the specified file path.
The file is parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactoru). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
ReturnedDocumentcontains all the textual information from the file.- Parameters:
pathOnClasspath- The path on the classpath to the file.- Returns:
- document
- Throws:
IllegalArgumentException- If specified path is not a file.
-
loadDocument
Loads aDocumentfrom the specified file path using a given class loader.
The file is parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactoru). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
ReturnedDocumentcontains all the textual information from the file.- Parameters:
pathOnClasspath- The path on the classpath to the file.classLoader- The classloader to use when loading classes- Returns:
- document
- Throws:
IllegalArgumentException- If specified path is not a file.
-
loadDocument
Loads aDocumentfrom the specified file path.
The file is parsed using the specifiedDocumentParser.
ReturnedDocumentcontains all the textual information from the file.- Parameters:
pathOnClasspath- The path on the classpath 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.
-
loadDocument
public static Document loadDocument(String pathOnClasspath, DocumentParser documentParser, ClassLoader classLoader) Loads aDocumentfrom the specified file path using a given class loader.
The file is parsed using the specifiedDocumentParser.
ReturnedDocumentcontains all the textual information from the file.- Parameters:
pathOnClasspath- The path on the classpath to the file.documentParser- The parser to be used for parsing text from the file.classLoader- The class loader to use when loading classes- Returns:
- document
- Throws:
IllegalArgumentException- If specified path is not a file.
-
loadDocuments
LoadsDocuments from the specified directory using a given class loader. Does not use recursion.
The files are parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactoru). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
Skips anyDocuments that fail to load.- Parameters:
directoryOnClasspath- The path to the directory on the classpath with files.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.
-
loadDocuments
LoadsDocuments from the specified directory. Does not use recursion.
The files are parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactoru). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
Skips anyDocuments that fail to load.- Parameters:
directoryOnClasspath- The path to the directory on the classpath with files.classLoader- The class loader to use when looking things up- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.
-
loadDocuments
public static List<Document> loadDocuments(String directoryOnClasspath, DocumentParser documentParser) LoadsDocuments from the specified directory. Does not use recursion.
The files are parsed using the specifiedDocumentParser.
Skips anyDocuments that fail to load.- Parameters:
directoryOnClasspath- The path to the directory on the classpath 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.
-
loadDocuments
public static List<Document> loadDocuments(String directoryOnClasspath, DocumentParser documentParser, ClassLoader classLoader) LoadsDocuments from the specified directory using a given class loader. Does not use recursion.
The files are parsed using the specifiedDocumentParser.
Skips anyDocuments that fail to load.- Parameters:
directoryOnClasspath- The path to the directory on the classpath with files.documentParser- The parser to be used for parsing text from each file.classLoader- The class loader to use when looking things up- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.
-
loadDocuments
Loads matchingDocuments from the specified directory. Does not use recursion.
The files are parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactoru). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
Skips anyDocuments that fail to load.- Parameters:
directoryOnClasspath- The path to the directory on the classpath 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.
-
loadDocuments
public static List<Document> loadDocuments(String directoryOnClasspath, PathMatcher pathMatcher, ClassLoader classLoader) Loads matchingDocuments from the specified directory using a given class loader. Does not use recursion.
The files are parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactoru). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
Skips anyDocuments that fail to load.- Parameters:
directoryOnClasspath- The path to the directory on the classpath 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.classLoader- The class loader to use- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.
-
loadDocuments
public static List<Document> loadDocuments(String directoryOnClasspath, 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:
directoryOnClasspath- The path to the directory on the classpath 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.
-
loadDocuments
public static List<Document> loadDocuments(String directoryOnClasspath, PathMatcher pathMatcher, DocumentParser documentParser, ClassLoader classLoader) Loads matchingDocuments from the specified directory using a given class loader. Does not use recursion.
The files are parsed using the specifiedDocumentParser.
Skips anyDocuments that fail to load.- Parameters:
directoryOnClasspath- The path to the directory on the classpath 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.classLoader- The class loader to use when looking things up- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.
-
loadDocumentsRecursively
Recursively loadsDocuments from the specified directory and its subdirectories.
The files are parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactoru). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
Skips anyDocuments that fail to load.- Parameters:
directoryOnClasspath- The path to the directory on the classpath with files.- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.
-
loadDocumentsRecursively
public static List<Document> loadDocumentsRecursively(String directoryOnClasspath, ClassLoader classLoader) Recursively loadsDocuments from the specified directory and its subdirectories using a specified classloader.
The files are parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactoru). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
Skips anyDocuments that fail to load.- Parameters:
directoryOnClasspath- The path to the directory on the classpath with files.classLoader- The class loader to use when looking things up- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.
-
loadDocumentsRecursively
public static List<Document> loadDocumentsRecursively(String directoryOnClasspath, 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:
directoryOnClasspath- The path to the directory on the classpath 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.
-
loadDocumentsRecursively
public static List<Document> loadDocumentsRecursively(String directoryOnClasspath, DocumentParser documentParser, ClassLoader classLoader) Recursively loadsDocuments from the specified directory and its subdirectories using a given class loader.
The files are parsed using the specifiedDocumentParser.
Skips anyDocuments that fail to load.- Parameters:
directoryOnClasspath- The path to the directory on the classpath with files.documentParser- The parser to be used for parsing text from each file.classLoader- The class loader to use- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.
-
loadDocumentsRecursively
public static List<Document> loadDocumentsRecursively(String directoryOnClasspath, PathMatcher pathMatcher) Recursively loads matchingDocuments from the specified directory and its subdirectories.
The files are parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactoru). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
Skips anyDocuments that fail to load.- Parameters:
directoryOnClasspath- The path to the directory on the classpath 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.
-
loadDocumentsRecursively
public static List<Document> loadDocumentsRecursively(String directoryOnClasspath, PathMatcher pathMatcher, ClassLoader classLoader) Recursively loads matchingDocuments from the specified directory and its subdirectories using a given class loader.
The files are parsed using the defaultDocumentParser. The defaultDocumentParseris loaded through SPI (seeDocumentParserFactoru). If noDocumentParserFactoryis available in the classpath, aTextDocumentParseris used.
Skips anyDocuments that fail to load.- Parameters:
directoryOnClasspath- The path to the directory on the classpath 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.classLoader- The class loader to use- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.
-
loadDocumentsRecursively
public static List<Document> loadDocumentsRecursively(String directoryOnClasspath, 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:
directoryOnClasspath- The path to the directory on the classpath 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.
-
loadDocumentsRecursively
public static List<Document> loadDocumentsRecursively(String directoryOnClasspath, PathMatcher pathMatcher, DocumentParser documentParser, ClassLoader classLoader) Recursively loads matchingDocuments from the specified directory and its subdirectories using a given class loader.
The files are parsed using the specifiedDocumentParser.
Skips anyDocuments that fail to load.- Parameters:
directoryOnClasspath- The path to the directory on the classpath 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.classLoader- The class loader to use when looking things up- Returns:
- list of documents
- Throws:
IllegalArgumentException- If specified path is not a directory.
-