Esempio n. 1
0
        public bool IsDuplicate()
        {
            int    len1  = unifFirstString.Length;
            int    len2  = unifSecondString.Length;
            double avLen = (len1 + len2) / 2.0;

            int    levenDist            = LevenshteinDistanceExtensions.LevenshteinDistance(unifSecondString, unifFirstString);
            double dicecoef             = DiceCoefficientExtensions.DiceCoefficient(unifFirstString, unifSecondString);
            Tuple <string, double> subs = LongestCommonSubsequenceExtensions.LongestCommonSubsequence(unifFirstString, unifSecondString);
            string metFirst             = DoubleMetaphoneExtensions.ToDoubleMetaphone(unifFirstString);
            string metSecond            = DoubleMetaphoneExtensions.ToDoubleMetaphone(unifSecondString);
            int    metLevDist           = LevenshteinDistanceExtensions.LevenshteinDistance(metFirst, metSecond);

            if (levenDist / avLen < 0.2 && dicecoef > 0.8)
            {
                return(true);
            }
            else if (dicecoef > 0.9)
            {
                return(true);
            }
            else if (subs.Item2 > 0.75)
            {
                return(true);
            }
            else if (metLevDist == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        public List <InstrumentSearchModel> getFilteredInstruments(string filter, List <InstrumentSearchModel> instrumentList, string selectedMatchAlgo, double threshold)
        {
            List <InstrumentModel> instruments    = new List <InstrumentModel>();
            InstrumentListDAO      instrumentData = new InstrumentListDAO();

            try
            {
                //Get all instruments
                instruments = instrumentData.GetData();
            }
            catch (DAOException ex)
            {
                if (ex.GetErrorCode() == DAOException.FILE_NA)
                {
                    throw new ServiceException(ServiceException.DATA_ACCESS_ERROR, "Could not get data for instruments", ex);
                }
                else if (ex.GetErrorCode() == DAOException.FILE_PARSE_ERROR)
                {
                    throw new ServiceException(ServiceException.DATA_ACCESS_ERROR, "Could not get data for instruments", ex);
                }
                else if (ex.GetErrorCode() == DAOException.UNKNOWN_ERROR)
                {
                    throw new ServiceException(ServiceException.UNKNOWN_ERROR, "Could not get data for instruments", ex);
                }
            }

            List <InstrumentSearchModel> filteredInstruments = new List <InstrumentSearchModel>();

            if (instruments != null)
            {
                //Fuzzy logic filtering
                foreach (InstrumentModel instrument in instruments)
                {
                    double distance;
                    if (selectedMatchAlgo == "Levenshtein Distance")
                    {
                        distance = (double)distanceCalc.CalculateLevenshteinDistance(filter, instrument.InstrumentName);
                    }
                    else if (selectedMatchAlgo == "Dice Coefficient")
                    {
                        distance = Math.Round(DiceCoefficientExtensions.DiceCoefficient(filter, instrument.InstrumentName), 2) * 100;
                    }
                    else
                    {
                        throw new ArgumentException("Could not find matching algorithm supplied please try again");
                    }

                    if (distance >= threshold)
                    {
                        InstrumentSearchModel instrumentSearch = new InstrumentSearchModel(instrument.Identifier, instrument.InstrumentName, distance);
                        filteredInstruments.Add(instrumentSearch);
                    }
                }
            }

            return(filteredInstruments.OrderByDescending(x => x.MatchLikelihood).ToList());
        }