Learn R Programming

phonics (version 1.4.0)

metaphone: Generate phonetic versions of strings with Metaphone

Description

The function metaphone phonetically encodes the given string using the metaphone algorithm.

Usage

metaphone(word, maxCodeLen = 10L, clean = TRUE)

Value

a character vector containing the metaphones of word, or an NA if the word value is NA

Arguments

word

string or vector of strings to encode

maxCodeLen

maximum length of the resulting encodings, in characters

clean

if TRUE, return NA for unknown alphabetical characters

Details

Metaphone has accumulated incompatible implementation variants. This function follows the traditional rules from Philips' 1990 algorithm; it is therefore not expected to reproduce PHP or Apache Commons Codec for every input.

The variable maxCodeLen is the limit on how long the returned metaphone should be.

The metaphone algorithm is only defined for inputs over the standard English alphabet, i.e., "A-Z.". Non-alphabetical characters are removed from the string in a locale-dependent fashion. This strips spaces, hyphens, and numbers. Other letters, such as "Ü," may be permissible in the current locale but are unknown to metaphone. For inputs outside of its known range, the output is undefined and NA is returned and a warning this thrown. If clean is FALSE, metaphone attempts to process the strings. The default is TRUE.

References

James P. Howard, II, "Phonetic Spelling Algorithm Implementations for R," Journal of Statistical Software, vol. 95, no. 8, (2020), p. 1--21, <10.18637/jss.v095.i08>.

Lawrence Philips, "Hanging on the Metaphone," Computer Language, vol. 7, no. 12 (1990), p. 38--44.

See Also

Other phonics: caverphone(), cologne(), lein(), mra_encode(), nysiis(), onca(), phonex(), phonics(), rogerroot(), soundex(), statcan()

Examples

Run this code
metaphone("wheel")
metaphone(c("school", "benji"))

Run the code above in your browser using DataLab