Class MojibusterEncodingDetector
- All Implemented Interfaces:
Serializable,SelfConfiguring,EncodingDetector
Order of operations:
- UTF-32 codepoint validity via
WideUnicodeDetector. 4-byte-aligned probes with valid Unicode codepoints in exactly one endian order are deterministically UTF-32. - UTF-16 column-asymmetry specialist. Stride-2 column histograms reliably distinguish UTF-16-LE / BE from other content — a question bigram NB fundamentally can't answer (LE and BE produce the same bigram multiset).
- Naive-Bayes bigram classifier. Handles the single-byte and multi-byte CJK classes where byte-bigrams are the natural discriminative signal.
BOM detection is NOT handled here. The canonical
location is org.apache.tika.detect.BOMDetector (tika-core),
SPI-registered, runs first in DefaultEncodingDetector's
chain and emits a DECLARATIVE candidate. This pipeline
composes with that detector externally, not internally.
Each prefix layer short-circuits when it produces a confident candidate. Conservative: only return at a layer when that layer's structural check is clean.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault SPI constructor: load the NB bigram model from the classpath atDEFAULT_MODEL_RESOURCE.MojibusterEncodingDetector(Path nbModelPath) -
Method Summary
Modifier and TypeMethodDescriptiondetect(byte[] probe) Byte-array entry point without metadata — same as passingnull.Byte-array entry point with optional metadata.detect(TikaInputStream tis, Metadata metadata, ParseContext parseContext) Detects the character encoding of the given text document.
-
Field Details
-
DEFAULT_MODEL_RESOURCE
Default NB bigram model on the classpath.- See Also:
-
-
Constructor Details
-
MojibusterEncodingDetector
Default SPI constructor: load the NB bigram model from the classpath atDEFAULT_MODEL_RESOURCE. The UTF-16 specialist loads its own model the same way.- Throws:
IOException
-
MojibusterEncodingDetector
- Throws:
IOException
-
-
Method Details
-
detect
public List<EncodingResult> detect(TikaInputStream tis, Metadata metadata, ParseContext parseContext) throws IOException Description copied from interface:EncodingDetectorDetects the character encoding of the given text document.Returns an empty list if the encoding cannot be determined. Returns a ranked list of candidates in descending confidence order otherwise. The first entry is always the best guess.
If the document input stream is not available, then the first argument may be
null. Otherwise the detector may read bytes from the start of the stream to help in encoding detection. The given stream is guaranteed to support themark featureand the detector is expected tomarkthe stream before reading any bytes from it, and toresetthe stream before returning. The stream must not be closed by the detector.The given input metadata is only read, not modified, by the detector.
- Specified by:
detectin interfaceEncodingDetector- Parameters:
tis- text document input stream, ornullmetadata- input metadata for the documentparseContext- the parse context- Returns:
- ranked list of encoding results, empty if unknown; never
null - Throws:
IOException- if the document input stream could not be read
-
detect
Byte-array entry point without metadata — same as passingnull. -
detect
Byte-array entry point with optional metadata. If metadata's content-type suggests HTML/XML (or is absent), HTML is stripped before the NB stage — but never before the wide-Unicode structural checks, which need byte alignment intact.
-