Пример #1
0
        internal static Pair <int, string> FindLevMatch(EventType[] eventTypes, string propertyName)
        {
            string bestMatch     = null;
            int    bestMatchDiff = int.MaxValue;

            for (int i = 0; i < eventTypes.Length; i++)
            {
                if (eventTypes[i] == null)
                {
                    continue;
                }
                var props = eventTypes[i].PropertyDescriptors;
                for (int j = 0; j < props.Count; j++)
                {
                    int diff = LevenshteinDistance.ComputeLevenshteinDistance(propertyName, props[j].PropertyName);
                    if (diff < bestMatchDiff)
                    {
                        bestMatchDiff = diff;
                        bestMatch     = props[j].PropertyName;
                    }
                }
            }

            if (bestMatchDiff < int.MaxValue)
            {
                return(new Pair <int, string>(bestMatchDiff, bestMatch));
            }
            return(null);
        }
Пример #2
0
            public Pair <int, string> GetSuggestion()
            {
                // find a near match, textually
                String bestMatch     = null;
                var    bestMatchDiff = int.MaxValue;

                for (var i = 0; i < _eventTypes.Length; i++)
                {
                    if (_streamNames[i] != null)
                    {
                        var diff = LevenshteinDistance.ComputeLevenshteinDistance(_streamNames[i], _streamName);
                        if (diff < bestMatchDiff)
                        {
                            bestMatchDiff = diff;
                            bestMatch     = _streamNames[i];
                        }
                    }

                    if (_eventTypes[i] == null)
                    {
                        continue;
                    }

                    // If the stream name is the event type name, that is also acceptable
                    if (_eventTypes[i].Name != null)
                    {
                        var diff = LevenshteinDistance.ComputeLevenshteinDistance(_eventTypes[i].Name, _streamName);
                        if (diff < bestMatchDiff)
                        {
                            bestMatchDiff = diff;
                            bestMatch     = _eventTypes[i].Name;
                        }
                    }
                }

                Pair <int, string> suggestion = null;

                if (bestMatchDiff < int.MaxValue)
                {
                    suggestion = new Pair <int, string>(bestMatchDiff, bestMatch);
                }
                return(suggestion);
            }
Пример #3
0
        internal static Pair <int, string> FindLevMatch(string propertyName, EventType eventType)
        {
            string bestMatch     = null;
            int    bestMatchDiff = int.MaxValue;
            var    props         = eventType.PropertyDescriptors;

            for (int j = 0; j < props.Count; j++)
            {
                int diff = LevenshteinDistance.ComputeLevenshteinDistance(propertyName, props[j].PropertyName);
                if (diff < bestMatchDiff)
                {
                    bestMatchDiff = diff;
                    bestMatch     = props[j].PropertyName;
                }
            }

            if (bestMatchDiff < int.MaxValue)
            {
                return(new Pair <int, string>(bestMatchDiff, bestMatch));
            }
            return(null);
        }
Пример #4
0
        protected internal static Pair<int, string> FindLevMatch(
            string propertyName,
            EventType eventType)
        {
            string bestMatch = null;
            var bestMatchDiff = int.MaxValue;
            var props = eventType.PropertyDescriptors;
            for (var j = 0; j < props.Count; j++) {
                var itemPropName = props[j].PropertyName;
                var diff = LevenshteinDistance.ComputeLevenshteinDistance(propertyName, itemPropName);
                if (diff < bestMatchDiff) {
                    bestMatchDiff = diff;
                    bestMatch = props[j].PropertyName;
                }
            }

            if (bestMatchDiff < int.MaxValue) {
                return new Pair<int, string>(bestMatchDiff, bestMatch);
            }

            return null;
        }