Esempio n. 1
0
        public string FindBuilding(string building, string city, string street)
        {
            string commandText = @"select distinct building from hot_water where city=@c and street=@s";
            Dictionary <string, string> parameters = new Dictionary <string, string>
            {
                { "c", city },
                { "s", street }
            };
            var fetchedData = FetchData(commandText, parameters).Select(t => t[0]).ToArray();

            double minMatch = 99;
            double match;
            string matchedString = "";

            foreach (var e in fetchedData)
            {
                match = ComparisonMetrics.JaccardDistance(e, building);
                if (match < minMatch)
                {
                    minMatch      = match;
                    matchedString = e;
                }
            }

            if (minMatch == 99)
            {
                return(null);
            }
            return(matchedString);
        }
Esempio n. 2
0
        public void WhenMatchingStrings_ShouldReturnExpectedValue(double pValue, double expectedValue)
        {
            const string kevin = "kevin";

            var result = ComparisonMetrics.JaroWinklerDistanceWithPrefixScale(kevin, kevin, pValue);

            Assert.Equal(expectedValue, result);
        }
Esempio n. 3
0
        public void WhenDifferentStrings_ShouldReturnExpectedValue(double pValue, double expectedValue)
        {
            const string kevin     = "kevin";
            const string abcxyz123 = "abcxyz123";

            var result = ComparisonMetrics.JaroWinklerDistanceWithPrefixScale(kevin, abcxyz123, pValue);

            Assert.Equal(expectedValue, result);
        }
Esempio n. 4
0
        private async Task <BsonDocument> FindApproximateProduct(string name)
        {
            var revCollection = _database.GetCollection <BsonDocument>("reviews");

            using (var cursor = await revCollection.FindAsync(new BsonDocument()))
            {
                while (await cursor.MoveNextAsync())
                {
                    foreach (var document in cursor.Current)
                    {
                        if (ComparisonMetrics.ApproximatelyEquals(document["name"].AsString, name, new[] { FuzzyStringComparisonOptions.UseLevenshteinDistance }.ToList(), FuzzyStringComparisonTolerance.SuperStrong))
                        {
                            return(document);
                        }
                    }
                }
            }
            return(null);
        }