opennlp.tools.ml.naivebayes

## Class Probability<T>

- java.lang.Object
- - opennlp.tools.ml.naivebayes.Probability<T>

- Type Parameters:
    `T` - the label (category) class
  Direct Known Subclasses:
    LogProbability

      public class Probability<T>
      extends Object

  Class implementing the probability for a label.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Probability(T label)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addIn(double probability)` Compounds the existing probability mass on the label with the new probability passed in to the method.
    `Double` | `get()` Returns the probability associated with a label
    `T` | `getLabel()` Returns the probabilities associated with all labels
    `Double` | `getLog()` Returns the log probability associated with a label
    `boolean` | `isLarger(Probability probability)` Checks if a probability is greater than the old one.
    `void` | `set(double probability)` Assigns a probability to a label, discarding any previously assigned probability.
    `void` | `set(Probability probability)` Assigns a probability to a label, discarding any previously assigned probability.
    `void` | `setIfLarger(double probability)` Assigns a probability to a label, discarding any previously assigned probability, if the new probability is greater than the old one.
    `void` | `setIfLarger(Probability probability)` Assigns a probability to a label, discarding any previously assigned probability, if the new probability is greater than the old one.
    `void` | `setLog(double probability)` Assigns a log probability to a label, discarding any previously assigned probability.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### Probability

          public Probability(T label)

  - ### Method Detail

    - #### set

          public void set(double probability)

      Assigns a probability to a label, discarding any previously assigned probability.
      Parameters:
        `probability` - the probability to assign

    - #### set

          public void set(Probability probability)

      Assigns a probability to a label, discarding any previously assigned probability.
      Parameters:
        `probability` - the probability to assign

    - #### setIfLarger

          public void setIfLarger(double probability)

      Assigns a probability to a label, discarding any previously assigned probability, if the new probability is greater than the old one.
      Parameters:
        `probability` - the probability to assign

    - #### setIfLarger

          public void setIfLarger(Probability probability)

      Assigns a probability to a label, discarding any previously assigned probability, if the new probability is greater than the old one.
      Parameters:
        `probability` - the probability to assign

    - #### isLarger

          public boolean isLarger(Probability probability)

      Checks if a probability is greater than the old one.
      Parameters:
        `probability` - the probability to assign

    - #### setLog

          public void setLog(double probability)

      Assigns a log probability to a label, discarding any previously assigned probability.
      Parameters:
        `probability` - the log probability to assign

    - #### addIn

          public void addIn(double probability)

      Compounds the existing probability mass on the label with the new probability passed in to the method.
      Parameters:
        `probability` - the probability weight to add

    - #### get

          public Double get()

      Returns the probability associated with a label
      Returns:
        the probability associated with the label

    - #### getLog

          public Double getLog()

      Returns the log probability associated with a label
      Returns:
        the log probability associated with the label

    - #### getLabel

          public T getLabel()

      Returns the probabilities associated with all labels
      Returns:
        the HashMap of labels and their probabilities

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2026 The Apache Software Foundation. All rights reserved.