Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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[] { });
        }
Ejemplo n.º 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'.");
            }
        }
Ejemplo n.º 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'.");
            }
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 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());
            }
        }
Ejemplo n.º 8
0
 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);
 }
Ejemplo n.º 9
0
        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'.");
            }
        }
Ejemplo n.º 10
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));
                //_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);
        }
Ejemplo n.º 12
0
        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);
                }
            }
        }
Ejemplo n.º 13
0
 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)));
Ejemplo n.º 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);
        }
Ejemplo n.º 15
0
 private void FindStreetNamesByNameToggleAbreviations(AddressMatchBuilder results, Dictionary <string, List <StreetNameLatestItem> > municipalitiesWithStreetNames) =>
 FindStreetNamesBy(results, municipalitiesWithStreetNames,
                   (exisitingStreetName, requestedStreetName) => exisitingStreetName.EqIgnoreCase(requestedStreetName.ToggleAbbreviations()), StraatnaamMatchLevel.ExactMatchReplaceAbbreviations);
Ejemplo n.º 16
0
 protected override IReadOnlyList <TResult> BuildResultsInternal(AddressMatchBuilder results) => results.AllAddresses().Select(_mapper.Map).ToList();
Ejemplo n.º 17
0
 protected override bool ShouldProceed(AddressMatchBuilder builder) => !IsValidMatch(builder);
Ejemplo n.º 18
0
 private static void FindStreetNamesByInputContainsStreetName(AddressMatchBuilder results, IReadOnlyDictionary <string, List <StreetNameLatestItem> > municipalitiesWithStreetNames)
 => FindStreetNamesBy(
     results,
     municipalitiesWithStreetNames,
     (exisitingStreetName, requestedStreetName) => requestedStreetName.ContainsIgnoreCase(exisitingStreetName));
Ejemplo n.º 19
0
 private void FindStreetNamesByFuzzyMatchToggleAbreviations(AddressMatchBuilder results, IReadOnlyDictionary <string, List <StreetNameLatestItem> > municipalitiesWithStreetNames)
 => FindStreetNamesBy(
     results,
     municipalitiesWithStreetNames,
     (exisitingStreetName, requestedStreetName) => exisitingStreetName.EqFuzzyMatchToggleAbreviations(requestedStreetName, _config.FuzzyMatchThreshold));
Ejemplo n.º 20
0
 private static void FindStreetNamesByNameToggleAbreviations(AddressMatchBuilder results, IReadOnlyDictionary <string, List <StreetNameLatestItem> > municipalitiesWithStreetNames)
 => FindStreetNamesBy(
     results,
     municipalitiesWithStreetNames,
     (exisitingStreetName, requestedStreetName) => exisitingStreetName.EqIgnoreCase(requestedStreetName.ToggleAbbreviations()));
Ejemplo n.º 21
0
 protected override IReadOnlyList <TResult> BuildResultsInternal(AddressMatchBuilder results) =>
 results.Select(g => g.Municipality).Select(_mapper.Map).ToList();
Ejemplo n.º 22
0
 protected override IReadOnlyList <TResult> BuildResultsInternal(AddressMatchBuilder results) =>
 results.AllStreetNames().Select(w => _mapper.Map(w.StreetName)).ToList();
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 25
0
 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>();
Ejemplo n.º 27
0
 protected override bool IsValidMatch(AddressMatchBuilder matchResult) => matchResult.AllAddresses().Any();
Ejemplo n.º 28
0
 protected override bool ShouldProceed(AddressMatchBuilder matchResult) => IsValidMatch(matchResult);
Ejemplo n.º 29
0
 //adresmatcher is the latest, so should never proceed
 protected override bool ShouldProceed(AddressMatchBuilder matchResult) => false;
Ejemplo n.º 30
0
 private void FindStreetNamesByFuzzyMatch(AddressMatchBuilder results, Dictionary <string, List <StreetNameLatestItem> > municipalitiesWithStreetNames) =>
 FindStreetNamesBy(results, municipalitiesWithStreetNames,
                   (exisitingStreetName, requestedStreetName) => exisitingStreetName.EqFuzzyMatch(requestedStreetName, _config.FuzzyMatchThreshold), StraatnaamMatchLevel.FuzzyMatch);