Approximate String Matching, Fuzzy Text Search, and String Distance Functions

Implements an approximate string matching version of R's native 'match' function. Also offers fuzzy text search based on various string distance measures. Can calculate various string distances based on edits (Damerau-Levenshtein, Hamming, Levenshtein, optimal sting alignment), qgrams (q- gram, cosine, jaccard distance) or heuristic metrics (Jaro, Jaro-Winkler). An implementation of soundex is provided as well. Distances can be computed between character vectors while taking proper care of encoding or between integer vectors representing generic sequences. This package is built for speed and runs in parallel by using 'openMP'. An API for C or C++ is exposed as well. Reference: MPJ van der Loo (2014) .


Mentioned in Awesome Official Statistics

stringdist

  • Approximate matching and string distance calculations for R.
  • All distance and matching operations are system- and encoding-independent.
  • Built for speed, using openMP for parallel computing.

The package offers the following main functions:

  • stringdist computes pairwise distances between two input character vectors (shorter one is recycled)
  • stringdistmatrix computes the distance matrix for one or two vectors
  • stringsim computes a string similarity between 0 and 1, based on stringdist
  • amatch is a fuzzy matching equivalent of R's native match function
  • ain is a fuzzy matching equivalent of R's native %in% operator
  • seq_dist, seq_distmatrix, seq_amatch and seq_ain for distances between, and matching of integer sequences.

These functions are built upon C-code that re-implements some common (weighted) string distance functions. Distance functions include:

  • Hamming distance;
  • Levenshtein distance (weighted)
  • Restricted Damerau-Levenshtein distance (weighted, a.k.a. Optimal String Alignment)
  • Full Damerau-Levenshtein distance
  • Longest Common Substring distance
  • Q-gram distance
  • cosine distance for q-gram count vectors (= 1-cosine similarity)
  • Jaccard distance for q-gram count vectors (= 1-Jaccard similarity)
  • Jaro, and Jaro-Winkler distance
  • Soundex-based string distance

Also, there are some utility functions:

  • qgrams() tabulates the qgrams in one or more character vectors.
  • seq_qrams() tabulates the qgrams (somtimes called ngrams) in one or more integer vectors.
  • phonetic() computes phonetic codes of strings (currently only soundex)
  • printable_ascii() is a utility function that detects non-printable ascii or non-ascii characters.

C API

Some of stringdist's underlying C functions can be called directly from C code in other packages. The description of the API can be found by either typing ?stringdist_api in the R console or open the vignette directly as follows:

vignette("stringdist_C-Cpp_api", package="stringdist")

Examples of packages that link to stringdist can be found here and here.

Resources

  • A paper on stringdist has been published in the R-journal
  • Slides of a talk given at te useR!2014 conference.

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("stringdist")

0.9.17 by Mark van der Loo, 9 months ago


https://github.com/markvanderloo/stringdist


Report a bug at https://github.com/markvanderloo/stringdist/issues


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


Authors: Mark van der Loo [aut, cre] (ORCID: , Jan van der Laan [ctb] , R Core Team [ctb] , Nick Logan [ctb] , Chris Muir [ctb] , Johannes Gruber [ctb] , Brian Ripley [ctb]


Documentation:   PDF Manual  


GPL-3 license


Imports parallel

Suggests tinytest


Imported by APCalign, AbSolution, AntibodyForests, ColOpenData, Conigrave, ELAplus, FeNEU, GTAPViz, GetLattesData, JANE, KOR.addrlink, LexisNexisTools, MEDseq, Nematode, OrgHeatmap, PFW, PGRdup, SemNetCleaner, SentimentAnalysis, ThesiStats, agriDQ, available, bdc, bdlp, bibliometrix, biblioverlap, bidux, bioseq, campfin, caretSDM, ciecl, clickR, clustringr, cols4all, concatipede, countries, ctrdata, daqapo, deductive, discoverableresearch, dupree, exams.forge, fastLink, fctutils, fcuk, fedmatch, firmmatchr, flora, fossilbrush, fuzzyjoin, fuzzylink, fuzzystring, genBaRcode, gerda, hood2net, hoopR, immunarch, irelink, itol.toolkit, levitate, lexsync, lingtypology, longreadvqs, messy.cats, mmstat4, nascaR.data, occupationMeasurement, ogrdbstats, ontophylo, orisma, palaeoverse, pensar, phsopendata, piglet, placematchr, poldis, qdap, qkiosk, r2dii.match, rassta, rdiversity, readapra, reclin2, refinr, retraction, revtools, rfair, searchAnalyzeR, shoppingwords, simOutrank, spell.replacer, synthesisr, taxlist, theorytools, tidyCDISC, tidystringdist, ulex, utilsIPEA, vDiveR, wcvpmatch, wehoop, wizaRdry.

Depended on by AurieLSHGaussian, VDJgermlines, blink, diathor.

Suggested by BioMonTools, LSTbook, Nestimate, WorldFlora, bidser, climatehealth, contentanalysis, countryatlas, dataquieR, embed, featForge, googleLanguageR, inkaR, joinery, lavaanExtra, mongolstats, peruflorads43, rlist, rolescry, screenllm, sjmisc, tna, vectra, zoomerjoin.


See at CRAN