36 lines
850 B
C#
36 lines
850 B
C#
using System.Collections;
|
|
|
|
namespace Common.Distance;
|
|
|
|
public readonly struct DistanceComparer<T> : IDistanceComparer<T>
|
|
where T : IEnumerable
|
|
{
|
|
/// <inheritdoc />
|
|
public T Reference { get; }
|
|
|
|
/// <inheritdoc />
|
|
public T? Hypothesis { get; }
|
|
|
|
/// <inheritdoc />
|
|
public double Distance { get; }
|
|
|
|
public DistanceComparer(T reference) : this(reference, default)
|
|
{
|
|
}
|
|
|
|
public DistanceComparer(T reference, T? hypothesis)
|
|
{
|
|
Reference = reference;
|
|
Hypothesis = hypothesis;
|
|
Distance = Calculator.GetDistance(Reference, Hypothesis);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override string ToString() => Hypothesis switch
|
|
{
|
|
null => "`null`",
|
|
var hyp when Equals(hyp, Reference) => Hypothesis.ToString() ?? string.Empty,
|
|
_ => $"<strong style='color: orange;' title='CER: {Distance}'>{Hypothesis}</strong>"
|
|
};
|
|
}
|