Example #1
0
    public static Truthness GetLessThanTruthness(long a, long b)
    {
        var distance = DistanceHelper.GetDistanceToEquality(a, b);

        return(new Truthness(
                   a < b ? 1d : 1d / (1.1d + distance),
                   a >= b ? 1d : 1d / (1.1d + distance)
                   ));
    }
Example #2
0
    public static Truthness GetEqualityTruthness(double a, double b)
    {
        var distance           = DistanceHelper.GetDistanceToEquality(a, b);
        var normalizedDistance = NormalizeValue(distance);

        return(new Truthness(
                   1d - normalizedDistance,
                   a != b ? 1d : 0d
                   ));
    }
Example #3
0
    public static double GetDistanceToEquality(DateTime a, DateTime b)
    {
        if (a.Equals(null))
        {
            throw new ArgumentNullException(nameof(a));
        }
        if (b.Equals(null))
        {
            throw new ArgumentNullException(nameof(b));
        }

        return(DistanceHelper.GetDistanceToEquality(ConvertToTimestamp(a), ConvertToTimestamp(b)));
    }
Example #4
0
    public static double GetDistance(object left, object right)
    {
        if (left.Equals(null))
        {
            throw new ArgumentNullException(nameof(left));
        }
        if (right.Equals(null))
        {
            throw new ArgumentNullException(nameof(right));
        }

        double distance;

        if (left is string && right is string)
        {
            // TODO Add string specialization info for left and right

            // String
            var a = (string)left;
            var b = right.ToString();
            distance = GetLeftAlignmentDistance(a, b);
        }
        else if (left is byte && right is byte)
        {
            // Byte
            var a = (byte)left;
            var b = (byte)right;
            distance = DistanceHelper.GetDistanceToEquality(Convert.ToInt64(a), Convert.ToInt64(b));
        }
        else if (left is short && right is short)
        {
            // Short
            var a = (short)left;
            var b = (short)right;
            distance = DistanceHelper.GetDistanceToEquality(Convert.ToInt64(a), Convert.ToInt64(b));
        }
        else if (left is int && right is int)
        {
            // Integer
            var a = (int)left;
            var b = (int)right;
            distance = GetDistanceToEquality(a, b);
        }
        else if (left is long && right is long)
        {
            // Long
            var a = (long)left;
            var b = (long)right;
            distance = GetDistanceToEquality(a, b);
        }
        else if (left is float && right is float)
        {
            // Float
            var a = (float)left;
            var b = (float)right;
            distance = GetDistanceToEquality(a, b);
        }
        else if (left is double && right is double)
        {
            // Double
            var a = (double)left;
            var b = (double)right;
            distance = GetDistanceToEquality(a, b);
        }
        else if (left is char && right is char)
        {
            // Character
            var a = (char)left;
            var b = (char)right;
            distance = GetDistanceToEquality(a, b);
        }
        else if (left is DateTime && right is DateTime)
        {
            // DateTime
            var a = (DateTime)left;
            var b = (DateTime)right;
            distance = GetDistanceToEquality(a, b);
        }
        else
        {
            distance = double.MaxValue;
        }

        return(distance);
    }