46 lines
948 B
C#
46 lines
948 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()
|
|
{
|
|
var str = Hypothesis?.ToString();
|
|
|
|
if (Hypothesis is var hyp && Equals(hyp, Reference))
|
|
{
|
|
return str ?? string.Empty;
|
|
}
|
|
|
|
// Enable for HTML/MD only
|
|
// return $"<strong style='color: orange;' title='REf: {Reference}, CER: {Distance}'>{str ?? "-"}</strong>";
|
|
|
|
return str ?? "-";
|
|
}
|
|
}
|