Encodes names and words as phonetic codes, so that names which sound alike but are spelled differently can be matched. Implements the Metaphone algorithm of Philips (1990, Computer Language, 7(12), 38-43) and the Double Metaphone algorithm of Philips (2000) < https://web.archive.org/web/20250702064845/https://drdobbs.com/the-double-metaphone-search-algorithm/184401251>, which gives a primary and an alternate code for names of many language origins. Unlike most implementations, including 'PGRdup', the codes are not cut to four characters, which keeps long and multi-part names apart. Provides metaphone(), double_metaphone() and sounds_like() for record linkage, deduplication and name search, and includes a data set of common United States surnames.
Full-length Metaphone and Double Metaphone phonetic codes for R.
People spell the same name in different ways. Meyer, Meier, Mayer and Maier are one surname. Catherine and Katherine are one first name. Exact comparison misses these, which makes deduplication, record linkage and name search unreliable. Phonetic algorithms turn each name into a code for its sound, so that names which sound alike can be matched.
fullmetaphone implements the two algorithms of Lawrence Philips.
Most implementations, including PGRdup::DoubleMetaphone(), cut the
codes to four characters. That is often too short. Here codes keep up to
32 characters by default, which is the complete code for practically
every real name, so long and multi-part names keep their identity. The
length is set with the max_length argument.
library(fullmetaphone)
people <- c("Christopher Anderson", "Christina Andrews")
double_metaphone(people, max_length = 4)
#> primary secondary
#> 1 KRST KRST
#> 2 KRST KRST
double_metaphone(people)
#> primary secondary
#> 1 KRSTFRNTRSN KRSTFRNTRSN
#> 2 KRSTNNTRS KRSTNNTRS
In a test with almost 5000 synthetic full names, four-character codes left fewer than 900 distinct codes. Full-length codes left more than 4200.
From GitHub, until the package is on CRAN.
# install.packages("remotes")
remotes::install_github("anilyayavar/dblmetaphone", build_vignettes = TRUE)
| Function | What it gives |
|---|---|
metaphone(x) |
One Metaphone code per name. |
double_metaphone(x) |
A data frame with a primary and a secondary Double Metaphone code per name. |
sounds_like(x, y) |
TRUE where two names share a code. |
us_surnames |
The 5000 most common surnames in the 2010 US Census, for examples and testing. |
sounds_like("Smith", c("Schmidt", "Smyth", "Jones"))
#> [1] TRUE TRUE FALSE
# Search a register by sound
us_surnames[sounds_like("Schneider", us_surnames$surname), ]
#> surname rank count
#> 165 Snyder 165 160262
#> 312 Schneider 312 101290
#> 1088 Snider 1088 32148
#> 3906 Sander 3906 9090
#> 4077 Santoro 4076 8713
All functions share these arguments.
| Argument | Default | Meaning |
|---|---|---|
max_length |
32 |
Largest number of characters kept in each code. 32 keeps the complete code for practically every real name. Use Inf for no limit, or 4 for the traditional short codes. |
by_word |
FALSE |
If TRUE, encode each word of a name separately and join the codes with spaces. |
method |
"double" |
sounds_like() only. Compare Double Metaphone codes ("double") or Metaphone codes ("metaphone"). |
double_metaphone("Christopher Anderson", max_length = 6)
#> primary secondary
#> 1 KRSTFR KRSTFR
double_metaphone("Christopher Anderson", by_word = TRUE)
#> primary secondary
#> 1 KRSTFR ANTRSN KRSTFR ANTRSN
Missing values stay missing, accented Latin letters are read as plain letters, and punctuation is ignored.
The vignette, vignette("fullmetaphone"), explains the algorithms and
works through deduplication, record linkage and name search, including
the limits of phonetic matching.
PGRdup::DoubleMetaphone() for 4995 names. The other five differ
because of two small errors in the C code that 'PGRdup' uses, in the
rules for "GN" (as in Wagner) and "SC" (as in Frascella). This package
follows the published algorithm there.citation("PGRdup") to cite it.us_surnames data come from the
United States Census Bureau
and are in the public domain.See inst/COPYRIGHTS for details.
GPL-3.
Philips, L. (1990). Hanging on the metaphone. Computer Language, 7(12), 38-43.
Philips, L. (2000). The double metaphone search algorithm. C/C++ Users Journal, 18(6), 38-43. Archived copy.