Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exotic Dutch addresses returns incorrect house number #31

Open
jpzetstra opened this issue Oct 24, 2019 · 3 comments
Open

Exotic Dutch addresses returns incorrect house number #31

jpzetstra opened this issue Oct 24, 2019 · 3 comments
Labels
bug Issues that describe an unexpected behaviour in an existing functionality. minor "bug" issues that are neither "critical" nor "major".

Comments

@jpzetstra
Copy link

I encountered some issues with the following Dutch addresses. I must say these addresses are quite exotic but nevertheless would be nice if it can be fixed :)

Laan 1940 – 1945 37 // Expected `37`, output `1940`
Laan 1940-’45 66 // Expected `66`, output `1940`
Laan ’40-’45 // Shouldn't give a house number
Plein 1940 2 // Expected `2`, output `1940 2`
1213-laan 11 // Can't split the address
16 april 1944 Pad 1 // Expected `1`, output `16`
1e Kruisweg 36 // Expected `36`, output `1e`
Langeloërduinen 3 46 // Expected `46` output `3 46`
Marienwaerdt 2e Dreef 2 // Expected `2` output `2e`
Provincialeweg N205 1 // Expected `1` output `205 1`
Rivium 2e Straat 59. // Expected `59` output `2e`

Article with the same issue and 'fix'.
https://www.rosettacode.org/wiki/Separate_the_house_number_from_the_street_name

@svenmuennich svenmuennich added bug Issues that describe an unexpected behaviour in an existing functionality. minor "bug" issues that are neither "critical" nor "major". labels Feb 3, 2020
@casperbakker
Copy link

Here is a case from Belgium that is the same situation as the 7th entry of this issue: 5e Regiment Lancierslaan 16

Street should be: 5e Regiment Lancierslaan
House number should be: 16

But it is processed as "streetName" => "Regiment Lancierslaan 16", "houseNumber" => "5e "

@it-can
Copy link

it-can commented Apr 28, 2023

@jpzetstra @casperbakker did you found a solution for this problem?

@jpzetstra
Copy link
Author

@it-can Sorry I can't remember how I've resolved the issue, it's already years ago. However maybe this helps you going in the right way. I've converted the solution, described in https://www.rosettacode.org/wiki/Separate_the_house_number_from_the_street_name to PHP.

<?php
class Address {
    
    public function isDigit($b) {
        return ('0' <= $b && $b <= '9');
    }
    
    public function separateHouseNumber($address) {
        $length = strlen($address);
        $fields = explode(' ', $address);
        $size = count($fields);
        $last = $fields[$size-1];
        $penult = $fields[$size-2];
        $house = '';
        if ($this->isDigit($last[0])) {
            $isdig = strlen($penult) && $this->isDigit($penult[0]);
            if ($size > 2 && $isdig && strpos($penult, "194") !== 0) {
                $house = $penult . ' ' . $last;
            } else {
                $house = $last;
            }
        } else if ($size > 2) {
            $house = $penult . ' ' . $last;
        }
        $street = rtrim(substr($address, 0, $length - strlen($house)), " ");
        return array($street, $house);
    }
}

$addresses = array(
    "Plataanstraat 5",
    "Straat 12",
    "Straat 12 II",
    "Dr. J. Straat   12",
    "Dr. J. Straat 12 a",
    "Dr. J. Straat 12-14",
    "Laan 1940 - 1945 37",
    "Plein 1940 2",
    "1213-laan 11",
    "16 april 1944 Pad 1",
    "1e Kruisweg 36",
    "Laan 1940-'45 66",
    "Laan '40-'45",
    "Langeloërduinen 3 46",
    "Marienwaerdt 2e Dreef 2",
    "Provincialeweg N205 1",
    "Rivium 2e Straat 59.",
    "Nieuwe gracht 20rd",
    "Nieuwe gracht 20rd 2",
    "Nieuwe gracht 20zw /2",
    "Nieuwe gracht 20zw/3",
    "Nieuwe gracht 20 zw/4",
    "Bahnhofstr. 4",
    "Wertstr. 10",
    "Lindenhof 1",
    "Nordesch 20",
    "Weilstr. 6",
    "Harthauer Weg 2",
    "Mainaustr. 49",
    "August-Horch-Str. 3",
    "Marktplatz 31",
    "Schmidener Weg 3",
    "Karl-Weysser-Str. 6"
);

echo "Street                   House Number\n";
echo "---------------------    ------------\n";
$address = new Address();
foreach ($addresses as $addr) {
    list($street, $house) = $address->separateHouseNumber($addr);
    if ($house == '') {
        $house = '(none)';
    }
    printf("%-22s   %s\n", $street, $house);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that describe an unexpected behaviour in an existing functionality. minor "bug" issues that are neither "critical" nor "major".
Projects
None yet
Development

No branches or pull requests

4 participants