Package: phonk
phonk: some helpful phonetics and phonology functionsPronounced [fʌŋk], [fɑŋk], [fɔŋk], or even [foʊŋk].InstallationRun the following:pip intall phonkUsageRhymeCompSo far, the only module isrhymescore, which contains theRhymeCompclass. This is a tool for finding and investigating (poetic) rhymes. Import theRhymeCompclass directly.fromphonk.rhymescoreimportRhymeCompRhymeComp('lives','read').get_score()Theget_score()method returns a non-negative integer.0indicates the rhymes are identical. Any positive number is the number of featural changes between the two rhymes. (See below for exact calculation method.)To see verbose output (that explains the exact featural differences), use theprint_details()method. This method takes an integer argument (default isverbose=1); the higher the number, the more detail shown.RhymeComp('lives','read').print_details()The above will output the following:'lives' vs. 'read'       SCORE: 10
Segment Comparisons
---
IH1     EH1     1
V       None    6
Z       D       3

Feature Comparisons
---
       IH   EH
high  1.0  0.0
                   Z    D
continuant       1.0  0.0
delayed release  1.0  0.0
strident         1.0  0.0

Possible Pronunciation Comparison:
---
('IH1', 'V', 'Z')       ('EH1', None, 'D')      10
('IH1', 'V', 'Z')       ('IY1', None, 'D')      10
('AY1', 'V', 'Z')       ('EH1', None, 'D')      12
('AY1', 'V', 'Z')       ('IY1', None, 'D')      14The function has pulled each word from the CMU pronouncing dictionary. Because each word has multiple listed pronunciations, and the rhymes are of different length, the function compares all possible alignments of all possible pronunciations. The best alignment of each pronunciation is printed at the end. The Segment Comparison shows that the lower score occurs whenZis compared withD. TheVoflivesis compared with an empty position. The default score for such a comparison is6; this can be changed by setting a value toe_compwhen creating the object.The details of each segment-to-segment comparison are shown in the Feature Comparison tables. The feature set is based onHayes 2012. This is a relatively standard set of features; definitions for which can be found in chapter 4 of the aforementioned textbook. To access these features directly, call thediffering_features()method, which returns them in a list.print(RhymeComp('lives','read').differing_features())>>>['high','continuant','delayed release','strident']Under the hoodGetting pronunciationsThe function will load and search theCMU pronouncing dictionaryviacmudictfor pronunciations of the given words. As the CMU might not be accurate, the function can also accept an ARPAbet list representation directly.If there are multiple pronunciations found, the lowest-scoring pronunciation is used for the base calculation. Alternate pronunciations can be viewed via theprint_details(verbose=3)method, or thepossible_pronsattribute directly.Defining 'rhyme'By default, the rhyme comparison looks at the lastVC*#sequence of the two words (i.e. the linguistic rhyme of the final syllable). If you want to compare multiple syllables, setsyllables=nupon object creation. If a given word is shorter thannsyllables, the comparison stops at the length of the shortest word. Currently, stress information is ignored for rhyme calculation.Aligning rhymesIf two rhymes are of different length, they must be aligned. The shorter of the two rhymes is padded with an empty object (None) at every possible position, and each of these sequences is compared with the longer rhyme. The lowest-scoring comparison is used for the eventual result. Any comparison of a segment to an empty position is given an arbitrary score of6. This can be changed by setting a different value toe_compupon object creation.Scoring rhymesThe score of the rhyme comparison is the sum of all featural differences between the two segments, in addition to thee_compvalue for every empty comparison done. In essence, a fairly standardfaithfulness calculationis done between the two strings. In thelivesvsreadexample above, the score breakdown is as follows:Segment Comparisons
---
IH1     EH1     1
V       None    6
Z       D       3Since the rhyme forreadwas shorter, it was padded withNone. The placement of this padding is such that the score is minimized; comparingZwithDandVwithNoneresults in a lower score than if e.g.Vis compared withDandZwithNone.Once there are two given sequences to compare, score lookup is relatively fast. Thediffs.csvtable includes all ARBAbet symbols as rows and columns with the number of featural differences between them as the values. This table is loaded as apandasdataframe and called for every segmental comparison.Only the first instance call ofRhymeComploads the relevant tables into memory, making subsequent calculations relatively fast. (h/tAnupam Basu)AcknowledgementsTK