Function Repository Resource:

WordGraph

Source Notebook

Create a word graph

Contributed by: Peter Burbery

ResourceFunction["WordGraph"][dictionary, start, nestlevel]

creates a word graph by nesting nestlevel times to find words that have a Hamming distance of 1 from the string or word start based on the data in dictionary.

ResourceFunction["WordGraph"][dictionary,start,nestlevel,distancefunction,threshold]

creates a word graph by finding words that have a distance of threshold based on the string distance function distancefunction.

Details

String distance functions include HammingDistance, DamerauLevenshteinDistance and EditDistance

Examples

Basic Examples (2) 

Create a word graph starting from "tears" with WordList by going five levels deep:

In[1]:=
ResourceFunction["WordGraph"][WordList[], "tears", 5]
Out[1]=

Now go two levels deep and use words that differ by two according to the DamerauLevenshteinDistance:

In[2]:=
ResourceFunction["WordGraph"][
 WordList[], "tears", 2, DamerauLevenshteinDistance, 1]
Out[2]=

Neat Examples (1) 

Compare the sizes of graphs based on different distance rules:

In[3]:=
AssociationMap[
 distancefunction |-> ResourceFunction["WordGraph"][WordList[], "tears", 2, distancefunction, 1], {EditDistance, HammingDistance, DamerauLevenshteinDistance}]
Out[3]=

Publisher

Peter Burbery

Version History

  • 1.0.0 – 20 July 2022

Related Resources

License Information