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

Capitalized names have strange behavior #48

Open
dxdc opened this issue Jul 21, 2020 · 3 comments
Open

Capitalized names have strange behavior #48

dxdc opened this issue Jul 21, 2020 · 3 comments

Comments

@dxdc
Copy link

dxdc commented Jul 21, 2020

Found some bugs having to do with capitalized names and multiple middle names. Sharing some examples here, it seems the initials get incorporated somehow.

Names for testing:

  • SOFIA GARCIA DE LA MANCHA
  • DA LAT
  • JUANITA MARIA DE SUR
  • Garcia Marques, Gabriel

The last example should be listed as "Last, First" so "Gabriel" should just be the first name and "Garcia Marques" should be listed as the last name.

Output:

(
    [firstname] => Sofia
    [middlename] => Garcia
    [initials] => D E L A
    [lastname] => Mancha
)
(
    [firstname] => D
    [initials] => A
    [lastname] => Lat
)
(
    [firstname] => Juanita
    [middlename] => Maria
    [initials] => D E
    [lastname] => Sur
)
(
    [firstname] => Garcia Gabriel
    [lastname] => Marques
)
<?php

require_once __DIR__ . '/vendor/autoload.php';

$parser = new TheIconic\NameParser\Parser();
$namesToTest = array( 'SOFIA GARCIA DE LA MANCHA', 'DA LAT', 'JUANITA MARIA DE SUR', 'Garcia Marques, Gabriel' );

foreach ( $namesToTest as $input ) {

    $name = $parser->parse( $input );
    echo $name->getSalutation();
    echo $name->getFirstname();
    echo $name->getLastname();
    echo $name->getMiddlename();
    echo $name->getNickname();
    echo $name->getInitials();
    echo $name->getSuffix();

    print_r( $name->getAll() );

    echo $name;
}
@dxdc
Copy link
Author

dxdc commented Jul 21, 2020

Btw, one potential "fix" for the capitalized names is this:

    if ( $input === strtoupper( $input ) ) {
        $input = ucwords( strtolower( $input ) );
    }

@luads
Copy link

luads commented Jul 21, 2020

@dxdc have you tried adjusting the combined initials setting?

@dxdc
Copy link
Author

dxdc commented Jul 21, 2020

good call @luads!

$parser->setMaxCombinedInitials(1);

achieves the same result as:

    if ( $input === strtoupper( $input ) ) {
        $input = ucwords( strtolower( $input ) );
    }

It might be worth (?) temporarily overriding any user-defined setting for setMaxCombinedInitials and using 1 for any case where $input === strtoupper( $input )... just a thought.

So, that leaves just examples like:

  • Garcia Marques, Gabriel
  • Pérez Quiñones, Manuel A.

This kind of "two surname" structure is common in Mexican last names, for example. Not sure the best way to handle it... although maybe it should be treated the same way as the name would be without the comma, i.e.

  • Gabriel Garcia Marques
  • Manuel A. Pérez Quiñones

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants