Skip to content

Conversation

CarlosManuelRodr
Copy link
Contributor

@CarlosManuelRodr CarlosManuelRodr commented Jul 31, 2025

Rationale

Hi. While using this library I observed that names similar to the default postnominals such as "Ruvin Phidd" cannot be parsed correctly, throwing the exception

com.tupilabs.human_name_parser.ParseException: Couldn't find a last name in '{ruvin}'.

The cause is that the default postnominals

    public static final List<String> DEFAULT_POSTNOMINALS = Collections.unmodifiableList(
            Arrays.asList(
                    "phd",
                    "ph.d.",
                    "ph.d",
                    "esq",
                    "esquire",
                    "apr",
                    "rph",
                    "pe",
                    "md",
                    "ma",
                    "dmd",
                    "cme",
                    "dds",
                    "cpa",
                    "dvm"));

contains periods (.), which are interpreted as wildcard characters when parsed as regular expressions. As a result, unexpected matches occur during name parsing. The fix included on this PR addresses this problem by formatting the default values on the build() step of HumanNameParserBuilder.

Changes

  • Added method formatToRegex to HumanNameParserBuilder and modified build() to format the default values.
  • Created unit test testLastNameNotMistakenForPostnominal at BuilderTest that catches this problem.

@CarlosManuelRodr CarlosManuelRodr changed the title Fix lastname mistaken for postnominal Fix for HumanNameParser incorrectly interprets some name components as postnominals Jul 31, 2025
Copy link
Member

@kinow kinow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @CarlosManuelRodr ! I will prepare a new release today or over the weekend.

@kinow kinow merged commit b80a89e into tupilabs:master Aug 1, 2025
1 check passed
@kinow kinow added this to the 0.3 milestone Aug 1, 2025
@kinow kinow self-assigned this Aug 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants