Insert
Sample

The Space of Perfect Rhyme and Perfect Similarity

Perfect rhyme is the most well known kind of perfect similarity. but there are many other forms. Let’s explore how frequent they really are!
◼
Perfect Rhyme: (cat, sat) (sit, fit) (hello, jello, fellow)
◼
Perfect Assonance: (bat, tab, tack) (meet, seen, week) (go, known, hope)
◼
Perfect Consonance: (black, bleek, bloke, blake) (cut, cat, kit, kate, kite)
Initialization
◼
Before we begin, let’s grab the subset of words from WordData for which there are Phonetic Transcriptions, we will need these for our sound similarity condition tests.
In[7]:=
$wordsWithPhoneticForm=Select[WordData[],!MissingQ[WordData[#,"PhoneticForm"]]&];(*Thisleavesuswith29,795wordsfortheexploration*)
◼
Here we generate a list of all unique word pairs from our dictionary - this excludes identity comparisons.
In[8]:=
allPairs=Join@@Monitor[Table[{$wordsWithPhoneticForm[[i]],$wordsWithPhoneticForm[[j]]},{i,1,10000-1},{j,i+1,10000}],{i,j}]
In[45]:=
vowels="a","æ","ɛ","ʌ","ɔ","ə","e","o","ʊ","i","u","ɪ","ɝ","ɒ";​​consonants="ŋ","ɡ","ʃ","ʒ","b","d","ð","f","h","j","k","l","m","n","p","r","s","t","v","w","z","θ";

Perfect Rhyme - User Input

Two words are considered to be a perfect rhyme if all their vowels and all following consonants are identical. This is the most strict interpretation of perfect rhyme.
◼
This function will check to see if two words compose a perfect rhyme by our definition (minus stress, which is not available in Wolfram atm):
In[9]:=
checkForPerfectRhyme[word1_,word2_]:=Equal[StringCases[WordData[word1,"PhoneticForm"],RegularExpression["[aæɛʌɔəeoʊiuɪɝɒ]"]~~___~~EndOfString],StringCases[WordData[word2,"PhoneticForm"],RegularExpression["[aæɛʌɔəeoʊiuɪɝɒ]"]~~___~~EndOfString]]
◼
  • Running the next line of code will prompt you to enter two words for perfect rhyme comparison.
  • In[10]:=
    inputPair=Table[InputString["Choose a word:"],2]
    Out[10]=
    {stop,drop}
    ◼
  • Now we can check if these words constitute a perfect rhyme by our definition
  • In[12]:=
    checkForPerfectRhyme[inputPair[[1]],inputPair[[2]]]
    Out[12]=
    True

    Perfect Rhyme - Exhaustive Dictionary Search

    Perfect rhyme is the most well known kind of perfect similarity, but how many perfect rhymes are there in English according to our definition?
    ◼
    For the time being, we will use a random sample of the exhaustive search for expediency
    In[93]:=
    allPairsSample=RandomSample[allPairs,100000];
    In[15]:=
    ​
    ◼
    Use the checkForPerfectRhyme to see if two words compose a perfect rhyme by our definition (minus stress, which is not available in Wolfram atm): This compairedPairs variable will store T/F values for each pair, indicating perfect rhyme or not.
    In[68]:=
    testedPerfectPairs=AbsoluteTiming[Monitor[Table[checkForPerfectRhyme@@allPairsSample[[i]],{i,Length[allPairsSample]},{1}],i]];​​
    In[140]:=
    (*comparedPairs3=Monitor[Table[checkForPerfectRhyme[arr2[[i]][[1]],arr2[[i]][[2]]],{i,Length[arr2]},{1}],i]*)
    In[63]:=
    ​​Count[comparedPairs2,True,2]
    Out[63]=
    0
    Ok, but how many word pairings are possible?
    ◼
  • Lets visualize that amount of word pairings that are perfect rhymes.
  • In[105]:=
    PieChart3D[{0,100000}]
    Out[105]=
    ◼
    It turns out our sample wasn’t big enough to find any perfect rhyme, not astonishing since our sample is 100,000 of the 900,000,000 possible pairs, and our definition is very strict.

    Perfect Assonance - Exhaustive Dictionary Search

    ◼
  • Words pairs are considered to have perfect assonance if all the their vowels are the same.
  • ◼
  • getVowels is a function from a project by Paruyr Danielian at Wolfram camp, which finds the string of vowels in a word. We will use this to examine the space of perfect assonance (perfect vowel similarity)
  • In[94]:=
    getVowels[word_]:=Replace​​ WordData[word,"PhoneticForm"],​​ ​​ s_?StringQStringReplace[s,(Alternatives@@consonants)|"ˌ"|"ˈ"""],​​ any_Missing["NotAvailable"]​​ ​​​​
    ◼
  • Ok, here we are getting all the vowel patterns for each pair of words.
  • ◼
  • allPairsVowelsSample = Map[getVowels, allPairsSample, {2}];
  • Out[95]=
    ɛəæɪ,ɪɝɪ,{ɔə,əɒə},ɛɝ,ɪɛəeɪ,ɒəeɪə,ɪɒ,əɛə,oʊi,aɪ,ɛoʊ,ɪəeɪ,ɪɛ,ɒɪɝə,ɒ,əi,ɪəɪ,əuɪ,oʊɔəeɪɝ,əɔɪ,ɪəɔi,ɛə,ɛəɛiɛi,æi,ɛəəi,ɔɪ,ɪɪəi,əʌə,oʊɪ,ɪæ,əaɪə,əʊ,ɒəaʊ,æəoʊi,ɒəaɪ,æɔ,ɛoʊɪ,eɪə,əoʊiə,əɛɝ,ui,æɪiə,ɛəaɪɪ,ɪɪ,ɔɪ,əɒɪ,ʌɪ,əɛ,eɪoʊ,
    ⋯99951⋯
    ,ɛ,æi,ɪeɪ,ɛɔɝ,ɪɪiɝ,eɪ,ɒoʊɒə,ɛoʊɝ,ɛu,ɝəaɪ,uɝi,uiə,æi,ɪɪ,ʌɝi,ʊiɪ,ɪ,ɛəɛ,ɪɝ,ɔɪ,æəeɪə,ɒi,ɪɒəi,ɛaʊ,ɔɛəi,æə,ɔoʊeɪɝ,ɛə,əɛɪ,oʊəaɪ,æeɪ,ʌaʊ,əaʊ,ɪi,{æɔə,æə},əɛəə,əeɪə,aɪɝ,ɒəɛə,{ɔəə,æi},ɪ,ɪɒ,əɛəɪ,ʌ,ɛiə,iɛ
    large output
    show less
    show more
    show all
    set size limit...
    ◼
  • Here we check each word pair and output a list of lists, with true values indicating a match has been found
  • In[74]:=
    checkForPerfectAssonance[a_,b_]:=Equal[a,b]
    In[101]:=
    testedPerfectAssonance=AbsoluteTiming[Monitor[Table[checkForPerfectAssonance@@allPairsVowelsSample[[i]],{i,Length[allPairsVowelsSample]},{1}],i]]
    Out[101]=
    {0.325129,{{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},
    ⋯99916⋯
    ,{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False},{False}}}
    large output
    show less
    show more
    show all
    set size limit...
    ◼
  • Let’s visualize the ratio of words pairs in this set that have perfect assonance
  • In[107]:=
    PieChart3D[{Count[testedPerfectAssonance,True,3],100000-Count[testedPerfectAssonance,True,3]}]​​
    Out[107]=
    ​
    ​
    ​
    ◼
    306 of the 100,000 tested pairs had perfect assonance!
    In[117]:=
    Count[testedPerfectAssonance,True,3]
    Out[117]=
    306

    Perfect Consonance - Exhaustive Dictionary Search

    Wordspairsareconsideredtohaveperfectconsonanceifallthetheirconsonantsarethesame.
    In[118]:=
    getConsonantsisafunctionfromaprojectbyParuyrDanielianatWolframcamp,whichfindsthestringofconsonantsinaword.Wewillusethistoexaminethespaceofperfectconsonance(perfectconsonantsimilarity)
    ◼
  • Here we check for consonance matches
  • ◼
    Wow, only 23 of 100,000 pairs had perfect consonance!

    What does this mean?

    These kinds of patterns are not common, although they stand out in our minds. Of course if we relax the criteria these number will grow quite a bit.

    Unanswered Questions

    We still need to finish running all the data in order to understand what the actual percentages are. Also we need a much more extensive IPA dictionary in order to have any understanding of the real space of perfect similarity. This dictionary has only ~30k words, which is not representative of the English Lexicon. Many others such as, CMU, CEL EX, etc... have at least 100k, we plan to import these into Mathematica to explore more fully.
    ​​
    ​In the future we will explore the space of similarity using varying degrees of similarity constraints.

    Further Explorations
    Slant Rhyme (imperfect rhyme)
    Nonce Words
    Poetry / Rap / Battle Rap
    Phonological Similaity
    Authorship information
    Jordan Ackerman
    June 22 2017
    jordan.aackerman@gmail.com