Class SvmDoccatModel
- All Implemented Interfaces:
Serializable
SvmModel together with the feature vocabulary, category label
mappings, corpus statistics, and configuration required for classification.
Persistence uses Java object serialization via serialize(OutputStream)
and deserialize(InputStream). Reads are guarded by an
ObjectInputFilter that allow-lists only the
classes reachable from a legitimate SvmDoccatModel graph and bounds
graph depth, references, and array length. Foreign payloads are rejected
with InvalidClassException before being materialised.
Treat the filter as defense-in-depth, not as a license to deserialize from untrusted sources: callers should still ensure the input stream originates from a location they trust.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResource limits applied to theObjectInputFilterused bydeserialize(InputStream, DeserializationLimits). -
Method Summary
Modifier and TypeMethodDescriptionstatic SvmDoccatModelstatic SvmDoccatModelintde.hhn.mi.domain.SvmModelvoidserialize(OutputStream out) Serializes this model to the givenOutputStreamusing Java object serialization.
-
Method Details
-
getSvmModel
public de.hhn.mi.domain.SvmModel getSvmModel()- Returns:
- The underlying
SvmModel.
-
getFeatureVocabulary
- Returns:
- An unmodifiable mapping from feature strings to their numeric indices.
-
getIndexToCategory
- Returns:
- An unmodifiable mapping from numeric category labels to category names.
-
getCategoryToIndex
- Returns:
- An unmodifiable mapping from category names to numeric labels.
-
getIdfValues
- Returns:
- An unmodifiable mapping from feature strings to their IDF values.
-
getFeatureMinValues
- Returns:
- An unmodifiable mapping from feature index to its minimum value in the training corpus.
-
getFeatureMaxValues
- Returns:
- An unmodifiable mapping from feature index to its maximum value in the training corpus.
-
getConfiguration
- Returns:
- The
SvmDoccatConfigurationused for this model.
-
getLanguageCode
- Returns:
- The ISO language code associated with this model.
-
getNumberOfCategories
public int getNumberOfCategories()- Returns:
- The number of categories in this model.
-
serialize
Serializes this model to the givenOutputStreamusing Java object serialization. The resulting stream can be read back withdeserialize(InputStream).- Parameters:
out- TheOutputStreamto write to. Must not benull.- Throws:
IOException- Thrown if IO errors occurred during serialization.IllegalArgumentException- ifoutisnull.
-
deserialize
Deserializes aSvmDoccatModelfrom the givenInputStreamusingdefaultresource limits.The stream is filtered via an
ObjectInputFilterthat allow-lists only the classes required to reconstruct anSvmDoccatModel, plus resource limits on graph depth, references, and array length. Foreign payloads are rejected withInvalidClassExceptionbeforeObjectInputStream.readObject()returns.Callers should still treat this method as defense-in-depth: only invoke it on streams from trusted sources.
If the default limits are too tight for an unusually large model — for example, a model with more than 10000000L entries in a single map — use
deserialize(InputStream, DeserializationLimits)to supply higher limits. The class allow-list is intentionally not configurable; loosening it would defeat the purpose of the filter.- Parameters:
in- TheInputStreamto read from. Must not benull.- Returns:
- A valid
SvmDoccatModelinstance. - Throws:
IOException- Thrown if IO errors occurred during deserialization, includingInvalidClassExceptionwhen the stream contains a class outside the allow-list or exceeds a resource limit.ClassNotFoundException- Thrown if required classes are not found.IllegalArgumentException- ifinisnull.
-
deserialize
public static SvmDoccatModel deserialize(InputStream in, SvmDoccatModel.DeserializationLimits limits) throws IOException, ClassNotFoundException Deserializes aSvmDoccatModelfrom the givenInputStreamusing the suppliedresource limits.Use this overload when the
default limitsreject a legitimate model — for example, models trained with very large feature vocabularies. The class allow-list applied to the stream is the same as fordeserialize(InputStream); only the numeric limits change.- Parameters:
in- TheInputStreamto read from. Must not benull.limits- TheSvmDoccatModel.DeserializationLimitsto apply. Must not benull.- Returns:
- A valid
SvmDoccatModelinstance. - Throws:
IOException- Thrown if IO errors occurred during deserialization, includingInvalidClassExceptionwhen the stream contains a class outside the allow-list or exceeds one of the supplied limits.ClassNotFoundException- Thrown if required classes are not found.IllegalArgumentException- ifinorlimitsisnull.
-