fullmetaphone

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.

Installation

From GitHub, until the package is on CRAN.

# install.packages("remotes")
remotes::install_github("anilyayavar/dblmetaphone", build_vignettes = TRUE)

Usage

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.

Validation

Credits

See inst/COPYRIGHTS for details.

Licence

GPL-3.

References

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.