Class ApacheTikaDocumentParser.Builder
java.lang.Object
dev.langchain4j.data.document.parser.apache.tika.ApacheTikaDocumentParser.Builder
- Enclosing class:
ApacheTikaDocumentParser
Builder for
ApacheTikaDocumentParser.
Options that are not set (or set to null) use their default values.
Each supplier is called once for every parsed document, so the content handler and metadata suppliers should return a new object on every call: these objects collect the text and the metadata of a single document.
- Since:
- 1.25.0
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Creates the parser.contentHandlerSupplier(@Nullable Supplier<ContentHandler> contentHandlerSupplier) Sets the supplier of the TikaContentHandlerthat collects the text of the documents.includeMetadata(@Nullable Boolean includeMetadata) Sets whether the metadata that Tika extracts (for example the author or the content type) is added to the parsedDocument.maxCharacters(@Nullable Integer maxCharacters) Sets the maximum number of characters of text that the parser extracts from a document.metadataSupplier(@Nullable Supplier<org.apache.tika.metadata.Metadata> metadataSupplier) Sets the supplier of the TikaMetadatathat is passed to the Tika parser.parseContextSupplier(@Nullable Supplier<org.apache.tika.parser.ParseContext> parseContextSupplier) Sets the supplier of the TikaParseContextthat is passed to the Tika parser.parserSupplier(@Nullable Supplier<org.apache.tika.parser.Parser> parserSupplier) Sets the supplier of the TikaParserthat reads the documents.
-
Method Details
-
parserSupplier
public ApacheTikaDocumentParser.Builder parserSupplier(@Nullable Supplier<org.apache.tika.parser.Parser> parserSupplier) Sets the supplier of the TikaParserthat reads the documents. The supplier is called once for every parsed document.- Parameters:
parserSupplier- the supplier of the Tika parser;nullmeans the default, anAutoDetectParser- Returns:
- this builder
- Since:
- 1.25.0
-
contentHandlerSupplier
public ApacheTikaDocumentParser.Builder contentHandlerSupplier(@Nullable Supplier<ContentHandler> contentHandlerSupplier) Sets the supplier of the TikaContentHandlerthat collects the text of the documents. The supplier is called once for every parsed document, and the text of the document is thetoString()of the handler after parsing.Your own content handler decides how much text is collected, so this option cannot be used together with
maxCharacters(Integer). To limit the text, set the limit on your handler, for examplenew BodyContentHandler(limit).- Parameters:
contentHandlerSupplier- the supplier of the content handler;nullmeans the default, aBodyContentHandlerthat extracts at mostmaxCharacters(Integer)characters- Returns:
- this builder
- Since:
- 1.25.0
-
metadataSupplier
public ApacheTikaDocumentParser.Builder metadataSupplier(@Nullable Supplier<org.apache.tika.metadata.Metadata> metadataSupplier) Sets the supplier of the TikaMetadatathat is passed to the Tika parser. The supplier is called once for every parsed document.- Parameters:
metadataSupplier- the supplier of the Tika metadata;nullmeans the default, an emptyMetadata- Returns:
- this builder
- Since:
- 1.25.0
-
parseContextSupplier
public ApacheTikaDocumentParser.Builder parseContextSupplier(@Nullable Supplier<org.apache.tika.parser.ParseContext> parseContextSupplier) Sets the supplier of the TikaParseContextthat is passed to the Tika parser. The supplier is called once for every parsed document.- Parameters:
parseContextSupplier- the supplier of the Tika parse context;nullmeans the default, an emptyParseContext- Returns:
- this builder
- Since:
- 1.25.0
-
includeMetadata
Sets whether the metadata that Tika extracts (for example the author or the content type) is added to the parsedDocument.- Parameters:
includeMetadata- whether to include the metadata;nullmeans the default,false- Returns:
- this builder
- Since:
- 1.25.0
-
maxCharacters
Sets the maximum number of characters of text that the parser extracts from a document. The count includes the line breaks and other whitespace that Tika adds to the text, for example after each paragraph. If a document contains more text,ApacheTikaDocumentParser.parse(InputStream)throws aRuntimeExceptionwhose cause is Tika'sWriteLimitReachedException.This option applies to the default content handler, so it cannot be used together with
contentHandlerSupplier(Supplier).- Parameters:
maxCharacters- the maximum number of characters, a positive number, or-1for no limit;nullmeans the default, 10,000,000- Returns:
- this builder
- Since:
- 1.25.0
-
build
Creates the parser.- Returns:
- a new
ApacheTikaDocumentParser - Throws:
IllegalArgumentException- ifmaxCharacters(Integer)is not a positive number or-1, or if bothmaxCharacters(Integer)andcontentHandlerSupplier(Supplier)are set- Since:
- 1.25.0
-