protected override AddressMatchBuilder DoMatchInternal(AddressMatchBuilder results)
        {
            List <HouseNumberWithSubaddress> houseNumberWithSubaddresses = new List <HouseNumberWithSubaddress>();

            if (!string.IsNullOrEmpty(results.Query.BoxNumber))
            {
                houseNumberWithSubaddresses.Add(new HouseNumberWithSubaddress(results.Query.HouseNumber, results.Query.BoxNumber, null));
            }
            else
            {
                houseNumberWithSubaddresses.AddRange(_sanitizer.Sanitize(results.Query.StreetName, results.Query.HouseNumber, results.Query.Index));
            }

            foreach (var municipalityWrapper in results)
            {
                foreach (var streetNameWrapper in municipalityWrapper)
                {
                    foreach (var houseNumberWithSubaddress in houseNumberWithSubaddresses)
                    {
                        streetNameWrapper.AddAddresses(_latestQueries.GetLatestAddressesBy(streetNameWrapper.StreetName.PersistentLocalId, houseNumberWithSubaddress.HouseNumber, houseNumberWithSubaddress.BoxNumber).ToList());
                    }
                }
            }

            return(results);
        }
        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[] { });
        }
Beispiel #3
0
        private void FindStreetNamesByKadStreetCode(AddressMatchBuilder results)
        {
            if (string.IsNullOrWhiteSpace(results?.Query.KadStreetNameCode))
            {
                return;
            }

            foreach (var municipalityWrapper in results)
            {
                municipalityWrapper
                .AddStreetNames(
                    _streetNameService
                    .GetStreetNamesByKadStreet(
                        results.Query.KadStreetNameCode,
                        municipalityWrapper.NisCode));
            }

            var searchName = results
                             ?.Query
                             ?.StreetName
                             ?.RemoveDiacritics();

            if (!string.IsNullOrEmpty(results?.Query?.StreetName) &&
                !results.AllStreetNames().Any(w =>
                                              !string.IsNullOrWhiteSpace(w.StreetName.NameDutchSearch) && w.StreetName.NameDutchSearch.EqIgnoreCase(searchName) ||
                                              !string.IsNullOrWhiteSpace(w.StreetName.NameFrenchSearch) && w.StreetName.NameFrenchSearch.EqIgnoreCase(searchName) ||
                                              !string.IsNullOrWhiteSpace(w.StreetName.NameGermanSearch) && w.StreetName.NameGermanSearch.EqIgnoreCase(searchName) ||
                                              !string.IsNullOrWhiteSpace(w.StreetName.NameEnglishSearch) && w.StreetName.NameEnglishSearch.EqIgnoreCase(searchName)))
            {
                _warnings.AddWarning("7", "Geen overeenkomst tussen 'KadStraatcode' en 'Straatnaam'.");
            }
        }
Beispiel #4
0
        private void FindStreetNamesByRrStreetCode(AddressMatchBuilder results)
        {
            var streetName = _streetNameService
                             .GetStreetNameByRrStreet(
                results.Query.RrStreetCode,
                results.Query.PostalCode);

            if (streetName != null)
            {
                results
                .Where(g => g.PostalCode == results.Query.PostalCode)
                .ToList()
                .ForEach(g => g.AddStreetName(streetName));
            }

            var searchName = results
                             ?.Query
                             ?.StreetName
                             ?.RemoveDiacritics();

            if (!string.IsNullOrEmpty(results?.Query?.StreetName) &&
                !results.AllStreetNames().Any(w =>
                                              !string.IsNullOrWhiteSpace(w.StreetName.NameDutchSearch) && w.StreetName.NameDutchSearch.EqIgnoreCase(searchName) ||
                                              !string.IsNullOrWhiteSpace(w.StreetName.NameFrenchSearch) && w.StreetName.NameFrenchSearch.EqIgnoreCase(searchName) ||
                                              !string.IsNullOrWhiteSpace(w.StreetName.NameGermanSearch) && w.StreetName.NameGermanSearch.EqIgnoreCase(searchName) ||
                                              !string.IsNullOrWhiteSpace(w.StreetName.NameEnglishSearch) && w.StreetName.NameEnglishSearch.EqIgnoreCase(searchName)))
            {
                _warnings.AddWarning("7", "Geen overeenkomst tussen 'RrStraatcode' en 'Straatnaam'.");
            }
        }
        public override IReadOnlyList <TResult> BuildResults(AddressMatchBuilder builder)
        {
            List <TResult> results = builder.AllAddresses().Take(_maxNumberOfResults).Select(_mapper.Map).ToList();

            results.ForEach(s => s.Score = 100);

            return(results);
        }
        protected override AddressMatchBuilder DoMatchInternal(AddressMatchBuilder results)
        {
            if (!string.IsNullOrEmpty(results.Query.KadStreetNameCode))
            {
                FindStreetNamesByKadStreetCode(results);
            }

            if (!string.IsNullOrEmpty(results.Query.RrStreetCode) && !string.IsNullOrEmpty(results.Query.PostalCode))
            {
                FindStreetNamesByRrStreetCode(results);
            }

            if (!string.IsNullOrEmpty(results.Query.StreetName))
            {
                Dictionary <string, List <StreetNameLatestItem> > municipalityWithStreetNames =
                    _latestQueries.GetLatestStreetNamesBy(results.Select(g => g.Name).ToArray()).GroupBy(s => s.NisCode).ToDictionary(g => g.Key, g => g.ToList());

                FindStreetNamesByName(results, municipalityWithStreetNames);

                if (!IsValidMatch(results))
                {
                    FindStreetNamesByNameToggleAbreviations(results, municipalityWithStreetNames);
                }
                if (!IsValidMatch(results))
                {
                    FindStreetNamesByFuzzyMatch(results, municipalityWithStreetNames);
                }
                if (!IsValidMatch(results))
                {
                    FindStreetNamesByFuzzyMatchToggleAbreviations(results, municipalityWithStreetNames);
                }
                if (!IsValidMatch(results) && results.Query.StreetName.Length > 3)
                {
                    FindStreetNamesByStreetNameContainsInput(results, municipalityWithStreetNames);
                }
                if (!IsValidMatch(results) && results.Query.StreetName.Length > 3)
                {
                    FindStreetNamesByInputContainsStreetName(results, municipalityWithStreetNames);
                }
            }

            if (!IsValidMatch(results))
            {
                _warnings.AddWarning("10", "'Straatnaam' niet interpreteerbaar.");
                //foreach (var gemeente in results)
                //    _telemetry.TrackStraatnaamMatch(gemeente.Naam, results.Query.Straatnaam, results.Query.KadStraatcode, results.Query.RrStraatcode, 0, (int)StraatnaamMatchLevel.NoMatch);
            }
            else if (results.AllStreetNames().Count() > _config.MaxStreetNamesThreshold)
            {
                _warnings.AddWarning("100", "Uw zoekopdracht is te generiek");
                results.ClearAllStreetNames();
            }

            return(results);
        }
Beispiel #7
0
        private static void FindStreetNamesBy(
            AddressMatchBuilder results,
            IReadOnlyDictionary <string, List <StreetNameLatestItem> > municipalitiesWithStreetNames,
            Func <string, string, bool> comparer)
        {
            foreach (var municipalityWrapper in results)
            {
                if (string.IsNullOrWhiteSpace(municipalityWrapper.NisCode))
                {
                    continue;
                }

                if (!municipalitiesWithStreetNames.ContainsKey(municipalityWrapper.NisCode))
                {
                    continue;
                }

                var municipalityWithStreetNames = municipalitiesWithStreetNames[municipalityWrapper.NisCode];

                var searchName = results
                                 ?.Query
                                 ?.StreetName;

                if (string.IsNullOrWhiteSpace(searchName))
                {
                    continue;
                }

                var matchingStreetName = municipalityWithStreetNames
                                         .Where(s =>
                                                !string.IsNullOrWhiteSpace(s.NameDutch) && comparer(s.NameDutch, searchName) ||
                                                !string.IsNullOrWhiteSpace(s.NameFrench) && comparer(s.NameFrench, searchName) ||
                                                !string.IsNullOrWhiteSpace(s.NameGerman) && comparer(s.NameGerman, searchName) ||
                                                !string.IsNullOrWhiteSpace(s.NameEnglish) && comparer(s.NameEnglish, searchName))
                                         .ToList();

                municipalityWrapper.AddStreetNames(matchingStreetName);

                if (matchingStreetName.Any())
                {
                    continue;
                }

                searchName = searchName.RemoveDiacritics() !;

                municipalityWrapper.AddStreetNames(
                    municipalityWithStreetNames
                    .Where(s =>
                           !string.IsNullOrWhiteSpace(s.NameDutchSearch) && comparer(s.NameDutchSearch, searchName) ||
                           !string.IsNullOrWhiteSpace(s.NameFrenchSearch) && comparer(s.NameFrenchSearch, searchName) ||
                           !string.IsNullOrWhiteSpace(s.NameGermanSearch) && comparer(s.NameGermanSearch, searchName) ||
                           !string.IsNullOrWhiteSpace(s.NameEnglishSearch) && comparer(s.NameEnglishSearch, searchName))
                    .ToList());
            }
        }
 protected override AddressMatchBuilder DoMatchInternal(AddressMatchBuilder builder)
 {
     if (!string.IsNullOrEmpty(builder.Query.HouseNumber) && !string.IsNullOrEmpty(builder.Query.RrStreetCode))
     {
         IEnumerable <AddressDetailItem> rrAddresses = _kadRrService.GetAddressesBy(builder.Query.HouseNumber, builder.Query.Index, builder.Query.RrStreetCode, builder.Query.PostalCode).ToList();
         if (rrAddresses.Any())
         {
             builder.AddRrAddresses(rrAddresses);
             _warnings.AddWarning("21", "De adressen in het resultaat werden gevonden via een rechtstreekse link naar het opgegeven rijksregister adres.");
         }
     }
     return(builder);
 }
        private void FindStreetNamesByKadStreetCode(AddressMatchBuilder results)
        {
            foreach (var municipalityWrapper in results)
            {
                municipalityWrapper.AddStreetNames(_streetNameService.GetStreetNamesByKadStreet(results.Query.KadStreetNameCode, municipalityWrapper.NisCode));
                //_telemetry.TrackStraatnaamMatch(gemeente.Naam, results.Query.Straatnaam, results.Query.KadStraatcode, results.Query.RrStraatcode, gemeente.Count(), (int)StraatnaamMatchLevel.KadStraatCode);
            }

            if (!string.IsNullOrEmpty(results.Query.StreetName) && !results.AllStreetNames().Any(w => w.StreetName.NameDutch.EqIgnoreCase(results.Query.StreetName)))
            {
                _warnings.AddWarning("7", "Geen overeenkomst tussen 'KadStraatcode' en 'Straatnaam'.");
            }
        }
        private void FindStreetNamesByRrStreetCode(AddressMatchBuilder results)
        {
            var streetName = _streetNameService.GetStreetNameByRrStreet(results.Query.RrStreetCode, results.Query.PostalCode);

            if (streetName != null)
            {
                results.Where(g => g.PostalCode == results.Query.PostalCode).ToList().ForEach(g => g.AddStreetName(streetName));
                //_telemetry.TrackStraatnaamMatch(results.Where(g => g.Postcode == results.Query.Postcode).FirstOrDefault()?.Naam, results.Query.Straatnaam, results.Query.KadStraatcode, results.Query.RrStraatcode, 1, (int)StraatnaamMatchLevel.RrStraatCode);
            }

            if (!string.IsNullOrEmpty(results.Query.StreetName) && !results.AllStreetNames().Any(w => w.StreetName.NameDutch.EqIgnoreCase(results.Query.StreetName)))
            {
                _warnings.AddWarning("7", "Geen overeenkomst tussen 'RrStraatcode' en 'Straatnaam'.");
            }
        }
        public override IReadOnlyList <TResult> Process(AddressMatchBuilder seed)
        {
            IReadOnlyList <TResult> results = base.Process(seed);

            if (results == null)
            {
                return(new List <TResult>());
            }

            //_telemetry.TrackAdresMatch(seed.Query.MunicipalityName, seed.Query.NisCode, seed.Query.PostalCode, seed.Query.StreetName, seed.Query.KadStreetNameCode, seed.Query.RrStreetCode, seed.Query.HouseNumber, seed.Query.Index, results.Count);
            //if (results.Any())
            //    _telemetry.TrackHighestScore(results.First().Score);

            return(results);
        }
        private void FindStreetNamesBy(AddressMatchBuilder results, Dictionary <string, List <StreetNameLatestItem> > municipalitiesWithStreetNames, Func <string, string, bool> comparer, StraatnaamMatchLevel level)
        {
            foreach (var municipalityWrapper in results)
            {
                if (municipalitiesWithStreetNames.ContainsKey(municipalityWrapper.NisCode))
                {
                    var municipalityWithStreetNames = municipalitiesWithStreetNames[municipalityWrapper.NisCode];

                    var matchingStreetName = municipalityWithStreetNames.Where(s => comparer(s.GetDefaultName(municipalityWrapper.Municipality.PrimaryLanguage), results.Query.StreetName));
                    municipalityWrapper.AddStreetNames(matchingStreetName);

                    //if (matchingStreetName.Any())
                    //    _telemetry.TrackStraatnaamMatch(municipalityWrapper.Naam, results.Query.Straatnaam, results.Query.KadStraatcode, results.Query.RrStraatcode, matchingStreetName.Count(), (int)level);
                }
            }
        }
 private IEnumerable <Tuple <string, MunicipalityLatestItem> > FilterByPartOfMunicipality(
     IEnumerable <MunicipalityLatestItem> municipalities,
     AddressMatchBuilder results)
 => _latestQueries
 .GetAllPostalInfo()
 .Where(postalInfo => postalInfo
        .PostalNames
        .Any(postalName =>
             postalName.PostalName != null &&
             postalName.PostalName.EqIgnoreCaseAndDiacritics(results.Query.MunicipalityName)))
 .Select(postalInfo => new
 {
     PostalCode     = postalInfo.PostalCode,
     MissingNisCode = results.ContainsNisCode(postalInfo.NisCode)
                 ? null
                 : postalInfo.NisCode,
 })
 .SelectMany(x => municipalities
             .Where(g => g.NisCode == x.MissingNisCode)
             .Select(g => new Tuple <string, MunicipalityLatestItem>(x.PostalCode, g)));
Beispiel #14
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);
        }
 private void FindStreetNamesByNameToggleAbreviations(AddressMatchBuilder results, Dictionary <string, List <StreetNameLatestItem> > municipalitiesWithStreetNames) =>
 FindStreetNamesBy(results, municipalitiesWithStreetNames,
                   (exisitingStreetName, requestedStreetName) => exisitingStreetName.EqIgnoreCase(requestedStreetName.ToggleAbbreviations()), StraatnaamMatchLevel.ExactMatchReplaceAbbreviations);
 protected override IReadOnlyList <TResult> BuildResultsInternal(AddressMatchBuilder results) => results.AllAddresses().Select(_mapper.Map).ToList();
 protected override bool ShouldProceed(AddressMatchBuilder builder) => !IsValidMatch(builder);
Beispiel #18
0
 private static void FindStreetNamesByInputContainsStreetName(AddressMatchBuilder results, IReadOnlyDictionary <string, List <StreetNameLatestItem> > municipalitiesWithStreetNames)
 => FindStreetNamesBy(
     results,
     municipalitiesWithStreetNames,
     (exisitingStreetName, requestedStreetName) => requestedStreetName.ContainsIgnoreCase(exisitingStreetName));
Beispiel #19
0
 private void FindStreetNamesByFuzzyMatchToggleAbreviations(AddressMatchBuilder results, IReadOnlyDictionary <string, List <StreetNameLatestItem> > municipalitiesWithStreetNames)
 => FindStreetNamesBy(
     results,
     municipalitiesWithStreetNames,
     (exisitingStreetName, requestedStreetName) => exisitingStreetName.EqFuzzyMatchToggleAbreviations(requestedStreetName, _config.FuzzyMatchThreshold));
Beispiel #20
0
 private static void FindStreetNamesByNameToggleAbreviations(AddressMatchBuilder results, IReadOnlyDictionary <string, List <StreetNameLatestItem> > municipalitiesWithStreetNames)
 => FindStreetNamesBy(
     results,
     municipalitiesWithStreetNames,
     (exisitingStreetName, requestedStreetName) => exisitingStreetName.EqIgnoreCase(requestedStreetName.ToggleAbbreviations()));
Beispiel #21
0
 protected override IReadOnlyList <TResult> BuildResultsInternal(AddressMatchBuilder results) =>
 results.Select(g => g.Municipality).Select(_mapper.Map).ToList();
 protected override IReadOnlyList <TResult> BuildResultsInternal(AddressMatchBuilder results) =>
 results.AllStreetNames().Select(w => _mapper.Map(w.StreetName)).ToList();
Beispiel #23
0
        private IEnumerable <MunicipalityLatestItem> FilterByName(IEnumerable <MunicipalityLatestItem> municipalities, AddressMatchBuilder results)
        {
            var municipalitiesByName = municipalities.Where(g => g.DefaultName.Value.EqIgnoreCase(results.Query.MunicipalityName)).ToList();

            if (!string.IsNullOrEmpty(results.Query.MunicipalityName) && !municipalitiesByName.Any())
            {
                _warnings.AddWarning("6", "Onbekende 'Gemeentenaam'.");
            }

            return(municipalitiesByName);
        }
Beispiel #24
0
        private IEnumerable <MunicipalityLatestItem> FilterByNisCode(IEnumerable <MunicipalityLatestItem> municipalities, AddressMatchBuilder results)
        {
            var municipalitiesByNisCode = municipalities.Where(g => g.NisCode.Equals(results.Query.NisCode)).ToList();

            if (!string.IsNullOrEmpty(results.Query.NisCode) && !municipalitiesByNisCode.Any())
            {
                _warnings.AddWarning("5", "Onbekende 'Niscode'.");
            }

            return(municipalitiesByNisCode);
        }
 private void FindStreetNamesByInputContainsStreetName(AddressMatchBuilder results, Dictionary <string, List <StreetNameLatestItem> > municipalitiesWithStreetNames) =>
 FindStreetNamesBy(results, municipalitiesWithStreetNames,
                   (exisitingStreetName, requestedStreetName) => requestedStreetName.ContainsIgnoreCase(exisitingStreetName), StraatnaamMatchLevel.MatchInputContainsStraatnaam);
 public override IReadOnlyList <TResult> Process(AddressMatchBuilder seed)
 => base.Process(seed) ?? new List <TResult>();
 protected override bool IsValidMatch(AddressMatchBuilder matchResult) => matchResult.AllAddresses().Any();
 protected override bool ShouldProceed(AddressMatchBuilder matchResult) => IsValidMatch(matchResult);
 //adresmatcher is the latest, so should never proceed
 protected override bool ShouldProceed(AddressMatchBuilder matchResult) => false;
 private void FindStreetNamesByFuzzyMatch(AddressMatchBuilder results, Dictionary <string, List <StreetNameLatestItem> > municipalitiesWithStreetNames) =>
 FindStreetNamesBy(results, municipalitiesWithStreetNames,
                   (exisitingStreetName, requestedStreetName) => exisitingStreetName.EqFuzzyMatch(requestedStreetName, _config.FuzzyMatchThreshold), StraatnaamMatchLevel.FuzzyMatch);