Full-Length Metaphone and Double Metaphone Phonetic Codes

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.


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.

  • Metaphone (1990) gives one code per name, following the rules of English spelling.
  • Double Metaphone (2000) handles names of many language origins and gives a second code where a name has two common pronunciations, so that Smith matches Schmidt and Wasserman matches Vasserman.

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

  • Cut to four characters, the Double Metaphone codes agree with all 1221 reference names in the test suite of Apache Commons Codec.
  • The Metaphone codes agree with the Apache Commons Codec test cases.
  • On 5000 synthetic names, the four-character codes agree with 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.

Credits

  • Lawrence Philips designed Metaphone and Double Metaphone and published the original code.
  • The Double Metaphone rules follow the C implementation by Maurice Aubrey in the Perl module Text::DoubleMetaphone, with fixes by Kevin Atkinson.
  • The PGRdup package by J. Aravind, J. Radhamani, Kalyani Srinivasan, B. Ananda Subhash and co-authors first brought Double Metaphone to R and inspired this package. Run citation("PGRdup") to cite it.
  • The Metaphone rules and the test data come from Apache Commons Codec.
  • The us_surnames data come from the United States Census Bureau and are in the public domain.
  • The first version of this package was written by Atharv Tyagi under the guidance of Anil Kumar Goyal, who maintain it together.

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.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("fullmetaphone")

0.1.0 by Anil Kumar Goyal, 4 hours ago


https://github.com/anilyayavar/dblmetaphone


Report a bug at https://github.com/anilyayavar/dblmetaphone/issues


Browse source code at https://github.com/cran/fullmetaphone


Authors: Anil Kumar Goyal [aut, cre, cph] , Atharv Tyagi [aut, cph] , Lawrence Philips [ctb] (Designer of the Metaphone and Double Metaphone algorithms and author of their original code) , Maurice Aubrey [ctb] (Author of the C implementation of Double Metaphone whose rules are followed here) , Kevin Atkinson [ctb] (Bug fixes to that C implementation) , The Apache Software Foundation [cph] (Apache Commons Codec , the basis of metaphone() and of the test data)


Documentation:   PDF Manual  


GPL-3 license


Suggests dplyr, knitr, rmarkdown, testthat


See at CRAN