Package org.apache.tika.parser.inference
Class InferenceDispatcher
java.lang.Object
org.apache.tika.parser.inference.InferenceDispatcher
- All Implemented Interfaces:
TransientParseState,ParseHook
Matches offered units against the inference bindings and runs the tasks. Built once at
config load and run as a
ParseHook: every document, top-level or embedded, is
offered once by the auto-detect parser. Units are buffered per binding for the whole top-level parse and flushed at its end, so a
document is one request per binding, not one per unit; the buffer is bounded by each
binding's maxChunks and maxBytes, and its bytes live in files the
dispatcher owns until the flush. At the flush every unit is aimed at the metadata that is
still read: under the recursive wrapper, the copy it kept for the unit's document (an
inline part or a page render lands on its parent); outside it, where the parse hands back
one metadata object and the embedded documents' own are discarded, the top-level document.
A request narrows the bindings through InferenceSelection. Failures mark the
document and never fail the parse. TEXT is not offered during the parse: whoever holds the
finished metadata list runs text(java.util.List<org.apache.tika.metadata.Metadata>, org.apache.tika.parser.ParseContext) over it.- Since:
- Apache Tika 4.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA binding resolved to its engine and tasks. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoiddiscard(ParseContext context) Clears the buffer and its files without running anything.voidend(Metadata root, boolean failed, ParseContext context) Runs the buffered units, or drops them when the parse failed: no engine call for a document nobody gets.voidflush(Metadata root, ParseContext context) Runs every binding's tasks over its buffered units; clears the buffer and its files.getBound()voidAfter the document's parser ran cleanly.voidoffer(InputKind kind, MediaType type, Metadata target, Metadata parent, Path source, ParseContext context) Buffers the bytes atsourcefor every binding that takes them; dropped past a binding's budget.voidofferPage(MediaType type, Metadata document, Metadata parent, int page, Path bytes, ParseContext context) A page ofdocumentrendered by its own parser;pageis 1-based,bytesandparentas inParseHook.offer(org.apache.tika.mime.MediaType, org.apache.tika.metadata.Metadata, org.apache.tika.metadata.Metadata, java.nio.file.Path, org.apache.tika.parser.ParseContext).voidstart(Metadata root, ParseContext context) Resolves the request's selection once, at the top of the parse, so a misnamed binding fails the request rather than one embedded document.voidtext(List<Metadata> metadataList, ParseContext context) TheInputKind.TEXTstage.booleanwants(MediaType type, Metadata metadata, ParseContext context) Whether this hook wants the bytes of a document of this detected type.booleanwants(InputKind kind, MediaType type, ParseContext context) Whether any binding that runs for this request takes this kind and type.booleanwantsPages(MediaType renderType, Metadata document, ParseContext context) Whether this hook wants the pages of the document being parsed rendered as images of this type.
-
Constructor Details
-
InferenceDispatcher
-
-
Method Details
-
getBound
-
start
Resolves the request's selection once, at the top of the parse, so a misnamed binding fails the request rather than one embedded document.- Specified by:
startin interfaceParseHook- Throws:
TikaException
-
wants
Description copied from interface:ParseHookWhether this hook wants the bytes of a document of this detected type.- Specified by:
wantsin interfaceParseHook- Throws:
TikaException
-
offer
public void offer(MediaType type, Metadata metadata, Metadata parent, Path bytes, ParseContext context) throws IOException, TikaException Description copied from interface:ParseHookAfter the document's parser ran cleanly.bytesis the document pinned to a file for this call only;parentis the document it is embedded in, null at top level.- Specified by:
offerin interfaceParseHook- Throws:
IOExceptionTikaException
-
wantsPages
public boolean wantsPages(MediaType renderType, Metadata document, ParseContext context) throws TikaException Description copied from interface:ParseHookWhether this hook wants the pages of the document being parsed rendered as images of this type. Its parser asks once, before rendering anything for the hooks.- Specified by:
wantsPagesin interfaceParseHook- Throws:
TikaException
-
offerPage
public void offerPage(MediaType type, Metadata document, Metadata parent, int page, Path bytes, ParseContext context) throws IOException, TikaException Description copied from interface:ParseHookA page ofdocumentrendered by its own parser;pageis 1-based,bytesandparentas inParseHook.offer(org.apache.tika.mime.MediaType, org.apache.tika.metadata.Metadata, org.apache.tika.metadata.Metadata, java.nio.file.Path, org.apache.tika.parser.ParseContext).- Specified by:
offerPagein interfaceParseHook- Throws:
IOExceptionTikaException
-
end
Runs the buffered units, or drops them when the parse failed: no engine call for a document nobody gets. -
wants
Whether any binding that runs for this request takes this kind and type.- Throws:
TikaException
-
offer
public void offer(InputKind kind, MediaType type, Metadata target, Metadata parent, Path source, ParseContext context) throws IOException, TikaException Buffers the bytes atsourcefor every binding that takes them; dropped past a binding's budget. The top-level document's own file is referenced, since the stream that owns it is open until after the flush; anything else (an embedded document's spool, a page render) is copied into a file the dispatcher owns before its parser deletes it.- Throws:
IOExceptionTikaException
-
flush
Runs every binding's tasks over its buffered units; clears the buffer and its files. -
discard
Clears the buffer and its files without running anything. -
text
TheInputKind.TEXTstage. Runs the TEXT bindings over the finished metadata list of a document tree, so every document's text goes to the engine in one pass and a batch may hold chunks of the container and of its attachments alike. Call it after the parse and before any metadata filters. A document that released other inputs to inference (TikaCoreProperties.INFERENCE_RELEASEDwithout TEXT) is skipped. Failures mark the first document of the list.- Throws:
TikaException
-