Records list names in different orders: JOHN A SMITH,
SMITH JOHN A, SMITH, JOHN. Nothing in the
string says which order was used, so peopleparser guesses from how often
each token is used as a given name or as a surname. This article
explains that evidence, the rules that use it for names of two, three
and more tokens, and the rules that keep compound surnames
(VON KAMECKE, GARCIA LOPEZ) together.
The rules run after cleaning, on the tokens that are left once
titles, credentials and suffixes are gone (see
vignette("name-cleaning")).
The examples parse a few names with parse_names() and
show the name columns as a table:
library(peopleparser)
# parse names and show the name columns
show <- function( x ) {
vars <- c( "name", "first_name", "middle_name", "last_name" )
parse_names( x )[ vars ] |> knitr::kable()
}The evidence: first-name and surname counts
census.names counts how often each name is a first name
and how often a surname in U.S. Census Bureau name files (see
vignette("gender-scoring") for where the table comes from).
get_census_data() looks up each token:
x <- c( "JOHN", "SMITH", "JORDAN", "TAYLOR", "LESLIE", "TSHEPO" )
get_census_data( x ) |> knitr::kable()| name | ordinal | male_value | female_value | first_name_value | last_name_value |
|---|---|---|---|---|---|
| JOHN | 1 | 3118620 | 6503 | 3125123 | 37363 |
| SMITH | 2 | 4102 | 897 | 4999 | 2369644 |
| JORDAN | 3 | 329734 | 122596 | 452330 | 200984 |
| TAYLOR | 4 | 95501 | 293715 | 389216 | 723758 |
| LESLIE | 5 | 52838 | 237654 | 290492 | 24015 |
| TSHEPO | 6 | 0 | 0 | 0 | 0 |
Some tokens are clearly one or the other (JOHN,
SMITH), although in the 2020 lists even SMITH
is a rare given name. Others are both: JORDAN and
TAYLOR are common in both positions, and
LESLIE is a common surname too. TSHEPO is in
neither list.
check_if_surname() turns the counts into a yes/no: a
token reads as a surname when more than half of its count is in the
surname position. A token found in neither list reads as a surname.
data.frame( name = x, surname = check_if_surname(x) ) |> knitr::kable()| name | surname |
|---|---|
| JOHN | FALSE |
| SMITH | TRUE |
| JORDAN | FALSE |
| TAYLOR | TRUE |
| LESLIE | FALSE |
| TSHEPO | TRUE |
determine_surname() picks the single most likely surname
in a name. It uses each token’s surname share,
and ranks tokens in three tiers:
- known names that are overwhelmingly surnames (), the more common first;
- tokens in neither list;
- all other names, by .
Remaining ties go to the later position. The first tier keeps
SMITH ahead of an initial or an unlisted token:
SMITH has a few thousand given-name uses in the 2020 lists,
so its share is just under 1, while an unlisted token’s share is exactly
1.
cd <- get_census_data( c("TAYLOR", "JORDAN") )
# position of the surname: JORDAN is first, TAYLOR the surname
determine_surname( cd )
#> [1] 1Rules by number of tokens
One token
A lone token is treated as the surname.
show( c("SMITH", "MADONNA") )| name | first_name | middle_name | last_name |
|---|---|---|---|
| SMITH | SMITH | ||
| MADONNA | MADONNA |
Two tokens
Most two-word names are written first name first, so the written order is the starting point. The tokens are swapped only when the census makes it much more likely that the name is written surname first.
Each token gets a smoothed surname share,
so a token with few records moves toward 0.5 and thin evidence cannot decide the order on its own. A token in neither census list gets s = 0.85 (an unlisted word is more often a rare surname than a rare given name), and a lone letter gets s = 0.05. The odds that the name is written surname first are
and the tokens are swapped when these odds exceed 30. An unlisted
first token of one or two letters is initials (HM CHERRY,
DC ALLEN).
x <- c( "JOHN SMITH", "SMITH JOHN",
"JORDAN TAYLOR", "TAYLOR JORDAN",
"LESLIE JAMES", "HARRIS MORRISON",
"RICHARD RUVIN", "R BLINCOE" )
show( x )| name | first_name | middle_name | last_name |
|---|---|---|---|
| JOHN SMITH | JOHN | SMITH | |
| SMITH JOHN | JOHN | SMITH | |
| JORDAN TAYLOR | JORDAN | TAYLOR | |
| TAYLOR JORDAN | TAYLOR | JORDAN | |
| LESLIE JAMES | LESLIE | JAMES | |
| HARRIS MORRISON | HARRIS | MORRISON | |
| RICHARD RUVIN | RICHARD | RUVIN | |
| R BLINCOE | R | BLINCOE |
Before version 0.2.0 the token with the higher surname share was the
surname, wherever it stood. That turned HARRIS MORRISON
into MORRISON HARRIS and, because RUVIN has a
few first-name records and no surname records in the census lists,
RICHARD RUVIN into first name RUVIN.
The settings (a, the unlisted share and the odds) were tuned on
758,388 two-word Form 990 Part VII names, each labelled by the
convention of the other names on the same return
(LAST, FIRST, FIRST M LAST and the like): see
data-raw/name_order_eval.R. On those labels the order
errors fell from 12,463 to 2,687. Names written first name first keep
their order 99.8% of the time, and 89% of names written surname first
are swapped. The rest of the surname-first names, such as
WALTER DALE, cannot be told apart from the census counts
alone.
A title that is also a surname (SHERIFF,
BISHOP, BROTHER) as the first of two tokens is
treated as a title when the other token is not mostly a given name.
BISHOP JOHN is left alone, because it may be
JOHN BISHOP written surname first.
x <- c( "HM CHERRY", "NICKHATH SHERIFF",
"HOWARD SITRON", "SHERIFF MASRY",
"BISHOP JOHN" )
show( x )| name | first_name | middle_name | last_name |
|---|---|---|---|
| HM CHERRY | HM | CHERRY | |
| NICKHATH SHERIFF | NICKHATH | SHERIFF | |
| HOWARD SITRON | HOWARD | SITRON | |
| SHERIFF MASRY | MASRY | ||
| BISHOP JOHN | JOHN | BISHOP |
Three tokens with two initials
The full token is the surname and the initials are the first and
middle initials, in order: A J SMITH and
SMITH A J both give A J SMITH.
Three tokens with one initial
A single-letter token is a middle initial (or a first initial). The
rules assume two orders, FIRST M LAST and
LAST FIRST M:
- a trailing initial means the name was written surname first:
SMITH JOHN AbecomesJOHN A SMITH; - an initial in the middle is reordered only when the two full words
pass the two-word written-order test above (
SMITH J ALANbecomesJ ALAN SMITH); - otherwise the order is kept.
show( c("JOHN A SMITH", "SMITH JOHN A", "SMITH J ALAN", "J ALAN SMITH") )| name | first_name | middle_name | last_name |
|---|---|---|---|
| JOHN A SMITH | JOHN | A | SMITH |
| SMITH JOHN A | JOHN | A | SMITH |
| SMITH J ALAN | J | ALAN | SMITH |
| J ALAN SMITH | J | ALAN | SMITH |
The trailing-initial rule cannot tell JOHN SMITH A
(given name first, stray initial at the end) from
SMITH JOHN A, and reads both as surname first.
Three full tokens
The first and last words get the two-word written-order test above.
The name is read surname first (SMITH JOHN ALAN becomes
JOHN ALAN SMITH) only when the first word is much more
likely a surname and the last a given name; otherwise the written order
is kept: first, middle, last. DONG JOON YI and
TOKS MALIK ASHIRU keep their order.
Up to version 0.2.1 the rule reordered any name whose first word read
as a surname and whose second did not, and counted every word missing
from the census as a surname. Labelled by the convention of the other
names on the same return, 28,811 three-word Part VII names were
reordered wrongly 1,210 times by that rule and 53 times by the
written-order test (data-raw/name_order_eval3.R).
x <- c( "JOHN ALAN SMITH", "SMITH JOHN ALAN",
"DONG JOON YI", "TOKS MALIK ASHIRU" )
show( x )| name | first_name | middle_name | last_name |
|---|---|---|---|
| JOHN ALAN SMITH | JOHN | ALAN | SMITH |
| SMITH JOHN ALAN | JOHN | ALAN | SMITH |
| DONG JOON YI | DONG | JOON | YI |
| TOKS MALIK ASHIRU | TOKS | MALIK | ASHIRU |
Four or more tokens
The first token is the first name and
determine_surname() picks the surname; a single letter is
chosen only when nothing else can be. Everything else is the middle
name. A word, two or more initials and a word
(GLYNN C W SCOTT) is treated as a two-word name with middle
initials. If the name opens with two surnames followed by a given name
(SMITH JONES MARY ANN), the two surnames are joined into
one.
show( c("JOHN PAUL GEORGE RINGO", "SMITH JONES MARY ANN") )| name | first_name | middle_name | last_name |
|---|---|---|---|
| JOHN PAUL GEORGE RINGO | JOHN | PAUL GEORGE | RINGO |
| SMITH JONES MARY ANN | MARY | ANN | SMITH-JONES |
Compound surnames
Compound surnames are kept together by joining their parts with a
dash, so they stay one token through the rest of the parse. The census
looks names up with the dashes removed (VON-KAMECKE as
VONKAMECKE).
Surname particles
prep_name() and fix_locative_surnames()
join a particle to the word after it. The particles are LA,
VON, VAN, VANDER,
DEL, DE, DI, DEN,
DER and O, plus ST inside a name
(Saint) and LO GRANDE. A second set joins only after the
first word and before a word that is not a title: VANDEN,
VANDE, SAN, SANTA,
LOS, LAS, DELLA,
DALLA, DELA, DOS,
DAS, DA, DU, TEN and
TER (PATRICIA SAN PEDRO,
ESTELLA DE LOS RIOS, LEANA DA SILVA). Some of
these are also given names, so they are not joined at the start of a
name.
A split MC surname inside a name is joined without a
dash, the way the census and most records spell it:
STEVE MC CORMICK gives MCCORMICK. A leading
MC is read as initials (MC OLSON), and a
trailing one as a credential (Navy Medical Corps).
Particles chain, so DE LA ROSA and
VAN DER BERG become one token.
x <- c( "Jane Van Dyke", "Carlos De La Rosa", "Dylan Van" )
data.frame( raw = x, joined = fix_locative_surnames(x) ) |> knitr::kable()| raw | joined |
|---|---|
| Jane Van Dyke | Jane Van-Dyke |
| Carlos De La Rosa | Carlos De-La-Rosa |
| Dylan Van | Dylan Van |
x <- c( "THOMAS H VON KAMECKE", "SEAN ST CLAIR",
"JULIA DI BUSSOLO", "JUAN CARLOS DE LA ROSA",
"MARY VAN DER BERG", "PATRICIA SAN PEDRO",
"ESTELLA DE LOS RIOS" )
show( x )| name | first_name | middle_name | last_name |
|---|---|---|---|
| THOMAS H VON KAMECKE | THOMAS | H | VON-KAMECKE |
| SEAN ST CLAIR | SEAN | ST-CLAIR | |
| JULIA DI BUSSOLO | JULIA | DI-BUSSOLO | |
| JUAN CARLOS DE LA ROSA | JUAN | CARLOS | DE-LA-ROSA |
| MARY VAN DER BERG | MARY | VAN-DER-BERG | |
| PATRICIA SAN PEDRO | PATRICIA | SAN-PEDRO | |
| ESTELLA DE LOS RIOS | ESTELLA | DE-LOS-RIOS |
A particle at the end of a name (Dylan Van) has nothing
to join and is left alone. ST at the start of a name is not
joined, because there it is usually a title.
Two surnames: middle tokens that read as surnames
After the first, middle and last names are assigned, a middle name of
three or more letters is checked again. A middle word joins the last
name only when at least 90% of its census records are surnames, or it is
not in the census. An initial never joins. So
MARIA GARCIA LOPEZ gives GARCIA-LOPEZ
(GARCIA is 99.8% surname), but JOHN LEE SMITH
keeps LEE as the middle name (LEE is 81%
surname; up to 0.2.1 this gave LEE-SMITH):
- one middle token that is a strong surname joins the last name;
- with several middle tokens, an initial followed by a full token keeps the initial as the middle name and joins the rest to the surname;
- otherwise, everything from the first surname-like middle token on joins the surname, and the tokens before it stay as the middle name.
When the surname parts are next to each other in the original string,
they are joined in the order they were written.
MARY ANN SMITH JONES gives SMITH-JONES, even
though SMITH was picked as the main surname. When they are
not next to each other, the middle part goes first.
x <- c( "MARIA GARCIA LOPEZ", "JOHN LEE SMITH",
"ELIZABETH ANNE WALKER SMITH",
"JOHN Q PUBLIC SMITH", "MARY ANN SMITH JONES",
"JEAN A DU PONT" )
show( x )| name | first_name | middle_name | last_name |
|---|---|---|---|
| MARIA GARCIA LOPEZ | MARIA | GARCIA-LOPEZ | |
| JOHN LEE SMITH | JOHN | LEE | SMITH |
| ELIZABETH ANNE WALKER SMITH | ELIZABETH | ANNE | WALKER-SMITH |
| JOHN Q PUBLIC SMITH | JOHN | Q | PUBLIC-SMITH |
| MARY ANN SMITH JONES | MARY | ANN | SMITH-JONES |
| JEAN A DU PONT | JEAN | A | DU-PONT |
One exception: MAY is a common middle name and a
surname. If it ends up at the front of a compound surname, it is moved
back to the middle name.
show( c("SARAH MAY WILSON", "MARY MAY") )| name | first_name | middle_name | last_name |
|---|---|---|---|
| SARAH MAY WILSON | SARAH | MAY | WILSON |
| MARY MAY | MARY | MAY |
Titles that turned out to be names
When a token is both a title and a name (EARL,
MAJOR), cleaning may strip it and leave no first name. The
parser then puts it back, using its position in the original string: a
leading token is the first name and a trailing one is the surname. See
vignette("name-cleaning").
Limits
- The rules know only how common each token is, not which order a
source uses. If you know the source writes
LAST FIRST, reorder the tokens before parsing. - Tokens absent from the census rank above names that are mostly given
names, so an unlisted given name (
SEOKJIN) next to a common given name can end up as the surname (SEOKJIN JAMES-> surnameSEOKJIN). In names of three or more words, strong surnames rank above unlisted tokens (TSHEPO CHOkeepsCHO), but a name with a large given-name share does not: inLUDWIG VAN BEETHOVENthe unlistedVAN-BEETHOVENis the surname, as it should be, becauseLUDWIGis also a given name. - A name that is both a common given name and a common surname
(
JAMES,LESLIE,TAYLOR,JORDAN) is decided by a small margin. Treat such parses as uncertain. - A middle word that is mostly a surname (
ANNE WALKER, 96%) is joined to the last name. That is right for Spanish and Portuguese double surnames and for maiden names kept as a middle name, but not for a given middle name that is a strong surname. Middle names that are often given names (LEE,RAY,GRANT) stay middle names, so a real double surname made of them is split. - A given name missing from the census before a listed name can still
be read as a surname written first (
CHIYA AYDIN AYHAN,MASSUMEH FARHAD).