StringTools - Maple Programming Help

Home : Support : Online Help : Programming : Names and Strings : StringTools Package : String Homology Routines : StringTools/SimilarityCoefficient

StringTools

 SimilarityCoefficient
 computes the similarity coefficient of two strings

 Calling Sequence SimilarityCoefficient( s, t ) SimilarityCoefficient( s, t, n )

Parameters

 s - Maple string t - Maple string n - (optional) positive integer

Description

 • The SimilarityCoefficient(s, t) command computes the similarity coefficient of two strings s and t, defined as follows.
 Let N(S) denote the set of trigrams of any string S. Then $\frac{\mathrm{nops}\left(N\left(s\right)\cup N\left(t\right)\right)}{\mathrm{nops}\left(N\left(s\right)\cap N\left(t\right)\right)}$ is the similarity coefficient of s and t, with the convention that strings having no trigrams in common have similarity coefficient equal to infinity.
 • An optional argument n may be specified causing the similarity coefficient to be computed for n-gram similarity instead of the default trigram similarity.
 • In typical applications, n is taken to be either $2$ or $3$ (the default). Note that Maple computes this measure as an exact rational quantity, rather than a floating-point approximation. You can obtain a floating-point result by applying evalf to the result.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{SimilarityCoefficient}\left("Canada","Canary"\right)$
 ${3}$ (1)
 > $\mathrm{SimilarityCoefficient}\left("Kline","Cline"\right)$
 ${2}$ (2)
 > $\mathrm{SimilarityCoefficient}\left("mathematics","mathematische"\right)$
 ${2}$ (3)
 > $\mathrm{SimilarityCoefficient}\left("Constance","Connor",1\right)$
 ${3}$ (4)
 > $\mathrm{SimilarityCoefficient}\left("Constance","Connor",2\right)$
 $\frac{{11}}{{2}}$ (5)
 > $\mathrm{SimilarityCoefficient}\left("Constance","Connor",3\right)$
 ${10}$ (6)
 > $\mathrm{SimilarityCoefficient}\left("Constance","Connor",4\right)$
 ${\mathrm{\infty }}$ (7)
 > $\mathrm{SimilarityCoefficient}\left("Constance","Connor",5\right)$
 ${\mathrm{\infty }}$ (8)