-
Notifications
You must be signed in to change notification settings - Fork 0
Confidence Struct
Represents a subject and its associated confidence score as a percentage.
Namespace: Rheo.Storage.Analyzing.Models.Result
Assembly: Rheo.Storage.dll
public readonly struct Confidence<T> : IEquatable<Confidence<T>>
where T : notnullT
The type of the subject to which the confidence score applies. Must be non-null.
| Constructor | Description |
|---|---|
| Confidence(T, Double) | Initializes a new instance of the Confidence<T> struct with the specified subject and confidence value. |
| Property | Type | Description |
|---|---|---|
| Subject | T | Gets the subject associated with this instance. |
| Value | Double | Gets the confidence score as a percentage. |
| Method | Description |
|---|---|
| Equals(Confidence<T>) | Determines whether the specified Confidence<T> is equal to the current instance. |
| Equals(Object) | Determines whether the specified object is equal to the current instance. |
| GetHashCode() | Returns the hash code for this instance. |
| ToString() | Returns a string representation of the confidence. |
| Operator | Description |
|---|---|
| Equality(Confidence<T>, Confidence<T>) | Determines whether two Confidence<T> instances are equal. |
| Inequality(Confidence<T>, Confidence<T>) | Determines whether two Confidence<T> instances are not equal. |
Use this struct to associate a confidence value with a specific subject, such as a prediction, classification, or result. The confidence score indicates the degree of certainty or reliability for the given subject. This type is immutable and thread-safe.
The struct implements value equality based on the subject only, not the confidence value. This means two instances with the same subject but different values are considered equal.
Initializes a new instance of the Confidence<T> struct with the specified subject and confidence value.
public Confidence(T subject, double value)subject T
The subject for which the confidence score is calculated. Cannot be null.
value Double
The confidence score as a percentage, typically between 0.0 and 100.0.
Gets the subject associated with this instance.
public T Subject { get; init; }T
The subject of the confidence score.
Gets the confidence score as a percentage.
public double Value { get; init; }The confidence value as a percentage (0.0 to 100.0).
The confidence score is calculated as the ratio of the current score to the total score, expressed as a percentage. If the total score is zero, the confidence is zero.
Determines whether the specified Confidence<T> is equal to the current instance.
public bool Equals(Confidence<T> other)other Confidence<T>
The Confidence<T> to compare with the current instance.
true if the subjects are equal; otherwise, false.
Equality is based solely on the subject, not the confidence value.
Determines whether the specified object is equal to the current instance.
public override bool Equals(object? obj)obj Object
The object to compare with the current instance.
true if the object is a Confidence<T> with an equal subject; otherwise, false.
Returns the hash code for this instance.
public override int GetHashCode()A hash code based on the subject.
Returns a string representation of the confidence.
public override string ToString()A string in the format: Subject (Value%)
Determines whether two Confidence<T> instances are equal.
public static bool operator ==(Confidence<T> left, Confidence<T> right)left Confidence<T>
The first instance to compare.
right Confidence<T>
The second instance to compare.
true if the instances are equal; otherwise, false.
Determines whether two Confidence<T> instances are not equal.
public static bool operator !=(Confidence<T> left, Confidence<T> right)left Confidence<T>
The first instance to compare.
right Confidence<T>
The second instance to compare.
true if the instances are not equal; otherwise, false.
The following example demonstrates how to create and use confidence instances:
using Rheo.Storage.Analyzing.Models;
using Rheo.Storage.Analyzing.Models.Result;
var pngDef = new Definition { FileType = "PNG Image", MimeType = "image/png" };
var confidence = new Confidence<Definition>(pngDef, 95.5);
Console.WriteLine($"Subject: {confidence.Subject.FileType}");
Console.WriteLine($"Confidence: {confidence.Value}%");
Console.WriteLine(confidence.ToString());
// Output: PNG Image, image/png, [] (95.50%)The following example shows equality comparison:
using Rheo.Storage.Analyzing.Models.Result;
var conf1 = new Confidence<string>("PNG", 95.0);
var conf2 = new Confidence<string>("PNG", 85.0);
var conf3 = new Confidence<string>("JPEG", 95.0);
Console.WriteLine(conf1 == conf2); // True (same subject)
Console.WriteLine(conf1 == conf3); // False (different subject)
Console.WriteLine(conf1.Value == conf2.Value); // False (different values)The following example demonstrates using confidence with different types:
using Rheo.Storage.Analyzing.Models.Result;
// Confidence with string
var extensionConfidence = new Confidence<string>(".png", 75.0);
Console.WriteLine(extensionConfidence);
// Output: .png (75.00%)
// Confidence with int
var priorityConfidence = new Confidence<int>(100, 90.0);
Console.WriteLine(priorityConfidence);
// Output: 100 (90.00%)The following example shows how confidence instances work in collections:
using Rheo.Storage.Analyzing.Models.Result;
var confidences = new List<Confidence<string>>
{
new Confidence<string>("PNG", 95.0),
new Confidence<string>("JPEG", 85.0),
new Confidence<string>("GIF", 75.0)
};
// Sort by confidence value
var sorted = confidences.OrderByDescending(c => c.Value).ToList();
foreach (var c in sorted)
{
Console.WriteLine(c);
}
// Output:
// PNG (95.00%)
// JPEG (85.00%)
// GIF (75.00%)This struct is immutable and thread-safe.
-
Storage Objects
-
Storage Information
-
Platform-Specific
-
Content-Type Analysis
-
Results
-
Models
-
-
Events & Progress