Class Utf16SpecialistEncodingDetector

java.lang.Object
org.apache.tika.ml.chardetect.Utf16SpecialistEncodingDetector
All Implemented Interfaces:
Serializable, org.apache.tika.config.SelfConfiguring, org.apache.tika.detect.EncodingDetector, StatisticalSpecialist

public class Utf16SpecialistEncodingDetector extends Object implements org.apache.tika.detect.EncodingDetector, StatisticalSpecialist
UTF-16 specialist detector of the mixture-of-experts charset detection architecture. Uses a tiny dense-feature maxent model paired with Utf16ColumnFeatureExtractor to produce a column-asymmetry-based judgment of UTF-16-LE vs UTF-16-BE.

HTML-immune by construction

The feature set the model consumes (12 per-column byte-range counts) captures the 2-byte alignment asymmetry that UTF-16 content produces and HTML content cannot — HTML has no 2-byte alignment, so any byte range appears with equal expected frequency at even vs odd positions. No amount of HTML markup can fire this specialist. See Utf16ColumnFeatureExtractor for the detailed argument.

Stage 1 of the MoE migration

Runs alongside the existing MojibusterEncodingDetector rather than replacing any piece of it. Emits a single EncodingResult.ResultType.STATISTICAL candidate for the meta arbiter (JunkFilterEncodingDetector) to weigh against the other detectors in the chain. The existing WideUnicodeDetector-based structural UTF-16 detection inside Mojibuster is not removed yet — both can operate in parallel during Stage 1 validation.

Model loading

The default constructor loads a trained model from the classpath at DEFAULT_MODEL_RESOURCE. If the resource is absent or malformed, construction throws IOException — the detector never operates in a no-op state because silent no-ops produce wrong answers without any indication that something's wrong. Deploy the detector only when a trained model is bundled; remove it from the chain otherwise.

Probe size

Reads up to MAX_PROBE_BYTES bytes. UTF-16 column-asymmetry signal stabilises quickly — even ~100 bytes is usually enough for a strong call. Default 512 is generous.

See Also:
  • Field Details

    • DEFAULT_MODEL_RESOURCE

      public static final String DEFAULT_MODEL_RESOURCE
      Default classpath resource for the trained UTF-16 specialist model. Missing resource → detector is a noop (logged once at construction).
      See Also:
    • MAX_PROBE_BYTES

      public static final int MAX_PROBE_BYTES
      Default number of probe bytes read.
      See Also:
    • SPECIALIST_NAME

      public static final String SPECIALIST_NAME
      Specialist name used in SpecialistOutput for provenance.
      See Also:
  • Constructor Details

    • Utf16SpecialistEncodingDetector

      public Utf16SpecialistEncodingDetector() throws IOException
      Load the model from the default classpath location.
      Throws:
      IOException - if the model resource is missing or malformed — the detector does not operate in a no-op state.
  • Method Details