Exemplo n.º 1
0
        public static bool IsMatch(object v1, object v2)
        {
            // This function is only used by variant 2 rows with subrows.
            // When the updater handles those this will go away and the rest
            // of its functions merged into the ColumnComparer family.
            if (IsPrimitive(v1) && IsPrimitive(v2))
            {
                if (v1.GetType() != v2.GetType())
                {
                    return(false);
                }

                decimal d1 = ToDecimal(v1);
                decimal d2 = ToDecimal(v2);

                return(d1 == d2);
            }

            if (v1 is Quad && v2 is Quad)
            {
                return(Equals(v1, v2));
            }

            string s1 = null, s2 = null;

            if (v1 is Text.XivString)
            {
                s1 = ((Text.XivString)v1).ToString();
            }
            else if (v1 is string)
            {
                s1 = (string)v1;
            }

            if (v2 is Text.XivString)
            {
                s2 = ((Text.XivString)v2).ToString();
            }
            else if (v2 is string)
            {
                s2 = (string)v2;
            }

            if (s1 == null || s2 == null)
            {
                return(false);
            }


            double maxDistance = Math.Ceiling(StringColumnComparer.RelativeLevenshteinDistance * (s1.Length + s2.Length) / 2.0);
            int    d           = StringColumnComparer.ComputeLevenshtein(s1, s2);

            return(d <= maxDistance);
        }
        public static ColumnComparer Create(Column column, IEnumerable <Column> candidates)
        {
            ColumnComparer comparer;
            Type           type = column.Reader.Type;

            if (Comparer.IsPrimitiveType(type) || type == typeof(Quad))
            {
                comparer = new PrimitiveColumnComparer();
            }
            else if (type == typeof(Text.XivString) || type == typeof(string))
            {
                comparer = new StringColumnComparer();
            }
            else
            {
                return(null);
            }

            comparer._compatibleColumnsByIndex = candidates.Select(c => comparer.IsCompatibleType(type, c.Reader.Type)).ToArray();
            return(comparer);
        }