private IEnumerable <MunicipalityLatestItem> FilterByPostalCode(
            IEnumerable <MunicipalityLatestItem> municipalities,
            AddressMatchBuilder results)
        {
            if (string.IsNullOrWhiteSpace(results?.Query.PostalCode))
            {
                return(new List <MunicipalityLatestItem>());
            }

            var postalInfo = _latestQueries
                             .GetAllPostalInfo()
                             .FirstOrDefault(x => x.PostalCode == results.Query.PostalCode);

            if (postalInfo != null)
            {
                if (results.Any() && !results.ContainsNisCode(postalInfo.NisCode))
                {
                    _warnings.AddWarning("8", "Geen overeenkomst tussen 'Postcode' en 'Gemeentenaam'/'Niscode'.");
                }

                return(string.IsNullOrEmpty(postalInfo.NisCode)
                    ? new List <MunicipalityLatestItem>()
                    : municipalities.Where(g => g.NisCode != null && g.NisCode.Contains(postalInfo.NisCode)));
            }

            _warnings.AddWarning("4", "Onbekende 'Postcode'.");
            return(new MunicipalityLatestItem[] { });
        }
Esempio n. 2
0
        protected override AddressMatchBuilder DoMatchInternal(AddressMatchBuilder results)
        {
            var municipalities = _latestQueries.GetAllLatestMunicipalities().ToList();

            var municipalitiesByName = FilterByName(municipalities, results);

            var municipalitiesByNisCode = FilterByNisCode(municipalities, results);

            results.AddMunicipalities(municipalitiesByName.Union(municipalitiesByNisCode));
            if (results.Count() > 1)
            {
                _warnings.AddWarning("9", "Geen overeenkomst tussen 'Niscode' en 'Gemeentenaam'.");
            }

            if (!string.IsNullOrEmpty(results.Query.PostalCode))
            {
                results.AddMunicipalitiesByPostalCode(FilterByPostalcode(municipalities, results), results.Query.PostalCode);
            }

            if (!string.IsNullOrEmpty(results.Query.MunicipalityName) && !results.Any())
            {
                var municipalitiesByPostalCode = FilterByPartOfMunicipality(municipalities, results)
                                                 .GroupBy(municipalityPostCode => municipalityPostCode.Item1);

                foreach (var municipalitiesGroup in municipalitiesByPostalCode)
                {
                    results.AddMunicipalitiesByPostalCode(municipalitiesGroup.Select(municipalityPostCode => municipalityPostCode.Item2), municipalitiesGroup.Key);
                }

                if (!results.Any())
                {
                    var municipalitiesByFuzzyMatch = municipalities.Where(g => g.DefaultName.Value.EqFuzzyMatch(results.Query.MunicipalityName, _config.FuzzyMatchThreshold));
                    results.AddMunicipalities(municipalitiesByFuzzyMatch);
                }
            }

            //_telemetry.TrackGemeenteMatch(results.Query.Gemeentenaam, results.Query.Niscode, results.Query.Postcode, results.Count());

            return(results);
        }
Esempio n. 3
0
 protected override bool IsValidMatch(AddressMatchBuilder matchResult) => matchResult.Any();