C
- the class of instances that represent the classification categoriespublic class ClassificationWithConfidenceBase<C> extends ClassificationBase<C> implements ClassificationWithConfidence<C>
ClassificationWithConfidence
interface.
Note that class uses a LinkedHashMap
as its internal storage,
so it is more memory-consuming than the ClassificationBase
.Modifier and Type | Field and Description |
---|---|
static float |
UNKNOWN_CONFIDENCE
Constant representing an unknown confidence
|
DEFAULT_INITIAL_CAPACITY
Modifier | Constructor and Description |
---|---|
|
ClassificationWithConfidenceBase(java.lang.Class<? extends C> categoriesClass,
float lowestConfidence,
float highestConfidence)
Creates an empty classification.
|
|
ClassificationWithConfidenceBase(java.lang.Class<? extends C> categoriesClass,
float lowestConfidence,
float highestConfidence,
int initialCapacity)
Creates an empty classification with the specified initial capacity.
|
protected |
ClassificationWithConfidenceBase(java.lang.Class<? extends C> categoriesClass,
float lowestConfidence,
float highestConfidence,
java.util.Map<C,java.lang.Float> storage)
Creates an empty classification with the given storage instance.
|
Modifier and Type | Method and Description |
---|---|
ClassificationWithConfidenceBase<C> |
add(C category)
Adds the given category to this classification.
|
ClassificationWithConfidenceBase<C> |
add(C category,
float confidence)
Adds the given category with confidence to this classification.
|
ClassificationWithConfidenceBase<C> |
addAll(ClassificationWithConfidence<C> classification)
Adds all the categories with confidence from the given classification into this.
|
ClassificationWithConfidenceBase<C> |
addAll(java.lang.Iterable<?> categories,
boolean ignoreIncompatibleCategory)
Adds the categories provided by the
Iterable to this classification. |
ClassificationWithConfidenceBase<C> |
addAll(java.lang.Iterable<?> categories,
float confidence,
boolean ignoreIncompatibleCategory)
Adds the categories provided by the
Iterable to this classification with the given confidence. |
ClassificationWithConfidenceBase<C> |
addAll(java.util.Iterator<?> categories,
boolean ignoreIncompatibleCategory)
Adds the categories provided by the iterator to this classification.
|
ClassificationWithConfidenceBase<C> |
addAll(java.util.Iterator<?> categories,
float confidence,
boolean ignoreIncompatibleCategory)
Adds the categories provided by the iterator to this classification with the given confidence.
|
ClassificationWithConfidenceBase<C> |
addArray(java.lang.Object array,
boolean ignoreIncompatibleCategory)
Adds the categories from a static array to this classification.
|
ClassificationWithConfidenceBase<C> |
addArray(java.lang.Object array,
float confidence,
boolean ignoreIncompatibleCategory)
Adds the categories from a static array to this classification with the given confidence.
|
protected java.lang.StringBuilder |
append(java.lang.StringBuilder str,
java.util.Iterator<C> iterator)
Appends the textual representation of the categories provided by the given
iterator.
|
protected void |
appendCategory(java.lang.StringBuilder str,
C category)
Internal method for the toString conversion that adds the category string.
|
float |
getConfidence(C category)
Returns the confidence for the given category.
|
float |
getHighestConfidence()
Returns the highest possible confidence of this classification.
|
float |
getLowestConfidence()
Returns the lowest possible confidence of this classification.
|
protected void |
checkValidConfidence(float confidence)
Check whether the given confidence is within the given boundaries.
|
protected boolean |
isUpdatingConfidence(java.lang.Float currentValue,
float newValue)
Returns whether the confidence value should be updated with the new value.
|
java.lang.String |
toString() |
boolean |
updateAllConfidences(ClassificationWithConfidence<C> classification)
Updates the all the categories with confidence in this classification.
|
boolean |
updateConfidence(C category,
float confidence)
Updates confidence of the given category.
|
castToStored, contains, createDefaultStorage, getStoredClass, iterator, remove, size
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
contains, getStoredClass, iterator, size
public static final float UNKNOWN_CONFIDENCE
public ClassificationWithConfidenceBase(java.lang.Class<? extends C> categoriesClass, float lowestConfidence, float highestConfidence)
categoriesClass
- the class of instances that represent the classification categorieslowestConfidence
- the lowest possible confidence of this classificationhighestConfidence
- the highest possible confidence of this classificationpublic ClassificationWithConfidenceBase(java.lang.Class<? extends C> categoriesClass, float lowestConfidence, float highestConfidence, int initialCapacity)
categoriesClass
- the class of instances that represent the classification categorieslowestConfidence
- the lowest possible confidence of this classificationhighestConfidence
- the highest possible confidence of this classificationinitialCapacity
- the initial capacity of the classificationprotected ClassificationWithConfidenceBase(java.lang.Class<? extends C> categoriesClass, float lowestConfidence, float highestConfidence, java.util.Map<C,java.lang.Float> storage) throws java.lang.NullPointerException, java.lang.IllegalArgumentException
categoriesClass
- the class of instances that represent the classification categorieslowestConfidence
- the lowest possible confidence of this classificationhighestConfidence
- the highest possible confidence of this classificationstorage
- the instance responsible for holding the objects in this classificationjava.lang.NullPointerException
- if the categoriesClass
or storage
is nulljava.lang.IllegalArgumentException
- if the specified initial capacity is negativepublic final ClassificationWithConfidenceBase<C> add(C category)
unknown confidence
.add
in class ClassificationBase<C>
category
- the category to addpublic final ClassificationWithConfidenceBase<C> addAll(java.util.Iterator<?> categories, boolean ignoreIncompatibleCategory) throws java.lang.ClassCastException
C
and null items are silently ignored.
Categories are added with unknown confidence
.addAll
in class ClassificationBase<C>
categories
- an iterator over the categories to addignoreIncompatibleCategory
- flag whether to silently ignore incompatible objects
from the iterator (true) or throw a ClassCastException
(false)java.lang.ClassCastException
- if there was an object incompatible with this classification categoriespublic final ClassificationWithConfidenceBase<C> addAll(java.lang.Iterable<?> categories, boolean ignoreIncompatibleCategory) throws java.lang.ClassCastException
Iterable
to this classification.
Note that the objects from the Iterable
are type-checked to be compatible with C
and null items are silently ignored.
Categories are added with unknown confidence
.addAll
in class ClassificationBase<C>
categories
- an Iterable
over the categories to addignoreIncompatibleCategory
- flag whether to silently ignore incompatible objects
from the iterator (true) or throw a ClassCastException
(false)java.lang.ClassCastException
- if there was an object incompatible with this classification categoriespublic final ClassificationWithConfidenceBase<C> addArray(java.lang.Object array, boolean ignoreIncompatibleCategory) throws java.lang.ClassCastException, java.lang.IllegalArgumentException
C
and null items are silently ignored.
Categories are added with unknown confidence
.addArray
in class ClassificationBase<C>
array
- a static array with the categories to addignoreIncompatibleCategory
- flag whether to silently ignore incompatible categories
from the array (true) or throw a ClassCastException
(false)java.lang.ClassCastException
- if there was an object incompatible with this classification categoriesjava.lang.IllegalArgumentException
- if the object array
is not a static arrayprotected final void checkValidConfidence(float confidence) throws java.lang.IllegalArgumentException
confidence
- the confidence to checkjava.lang.IllegalArgumentException
- if the given confidence is invalidpublic ClassificationWithConfidenceBase<C> add(C category, float confidence) throws java.lang.IllegalArgumentException
category
- the category to addconfidence
- the confidence of the category to addjava.lang.IllegalArgumentException
- if the confidence is not within the boundspublic ClassificationWithConfidenceBase<C> addAll(java.util.Iterator<?> categories, float confidence, boolean ignoreIncompatibleCategory) throws java.lang.ClassCastException
C
and null items are silently ignored.categories
- an iterator over the categories to addconfidence
- the confidence of the added categoriesignoreIncompatibleCategory
- flag whether to silently ignore incompatible categories
from the iterator (true) or throw a ClassCastException
(false)java.lang.ClassCastException
- if there was an object incompatible with this classification categoriespublic ClassificationWithConfidenceBase<C> addAll(java.lang.Iterable<?> categories, float confidence, boolean ignoreIncompatibleCategory) throws java.lang.ClassCastException
Iterable
to this classification with the given confidence.
Note that the objects from the Iterable
are type-checked to be compatible with C
and null items are silently ignored.categories
- an Iterable
over the categories to addconfidence
- the confidence of the added categoriesignoreIncompatibleCategory
- flag whether to silently ignore incompatible categories
from the iterator (true) or throw a ClassCastException
(false)java.lang.ClassCastException
- if there was an object incompatible with this classification categoriespublic ClassificationWithConfidenceBase<C> addAll(ClassificationWithConfidence<C> classification) throws java.lang.IllegalArgumentException
classification
- the classification with which to update this onejava.lang.IllegalArgumentException
- if the confidence is not within the boundspublic ClassificationWithConfidenceBase<C> addArray(java.lang.Object array, float confidence, boolean ignoreIncompatibleCategory) throws java.lang.ClassCastException, java.lang.IllegalArgumentException
C
and null items are silently ignored.array
- a static array with the categories to addconfidence
- the confidence of the added categoriesignoreIncompatibleCategory
- flag whether to silently ignore incompatible categories
from the array (true) or throw a ClassCastException
(false)java.lang.ClassCastException
- if there was an object incompatible with this classification categoriesjava.lang.IllegalArgumentException
- if the object array
is not a static arrayprotected boolean isUpdatingConfidence(java.lang.Float currentValue, float newValue)
currentValue
- the current confidence valuenewValue
- the new confidence valuepublic boolean updateConfidence(C category, float confidence) throws java.lang.IllegalArgumentException
category
- the category for which to update the confidenceconfidence
- the new confidence valuejava.lang.IllegalArgumentException
- if the confidence is not within the boundspublic boolean updateAllConfidences(ClassificationWithConfidence<C> classification) throws java.lang.IllegalArgumentException
classification
- the classification with which to update this onejava.lang.IllegalArgumentException
- if the confidence is not within the boundspublic float getConfidence(C category) throws java.util.NoSuchElementException
ClassificationWithConfidence
ClassificationWithConfidence.getLowestConfidence()
and
ClassificationWithConfidence.getHighestConfidence()
that represents the classification's
confidence about a particular category assignment.getConfidence
in interface ClassificationWithConfidence<C>
category
- the category for which to get the confidencejava.util.NoSuchElementException
- if the category is not in this classificationpublic float getLowestConfidence()
ClassificationWithConfidence
getLowestConfidence
in interface ClassificationWithConfidence<C>
public float getHighestConfidence()
ClassificationWithConfidence
getHighestConfidence
in interface ClassificationWithConfidence<C>
protected void appendCategory(java.lang.StringBuilder str, C category)
str
- the string to append the category string tocategory
- the category the textual representation of which to appendprotected java.lang.StringBuilder append(java.lang.StringBuilder str, java.util.Iterator<C> iterator)
str
- the string builder to createiterator
- the iterator for categoriespublic java.lang.String toString()
toString
in class ClassificationBase<C>