Package: rhymetagger
RhymeTaggerA simple collocation-drivenrecognition of rhymes. Contains pre-trained models forCzech, Dutch, English, French, German, Russian,andSpanishpoetry.Details in P. Plecháč (2018).A Collocation-Driven Method of Discovering Rhymes (in Czech, English, and French Poetry). In Taming the Corpus: From Inflection and Lexis to Interpretation. Cham: Springer, 79-95.!Requires eSpeak to be installedInstallationpip install rhymetaggerorpip3 install rhymetaggerUsageTo annotate poems with one of the pre-trained models:fromrhymetaggerimportRhymeTaggerpoem=["Tell me not, in mournful numbers,","Life is but an empty dream!","For the soul is dead that slumbers,","And things are not what they seem.","Life is real! Life is earnest!","And the grave is not its goal;","Dust thou art, to dust returnest,","Was not spoken of the soul.","Not enjoyment, and not sorrow,","Is our destined end or way;","But to act, that each tomorrow","Find us farther than today.",]rt=RhymeTagger()rt.load_model(model='en')rhymes=rt.tag(poem,output_format=3)print(rhymes)>>[1,2,1,2,3,4,3,4,5,6,5,6]poem=["Über allen Gipfeln","Ist Ruh’,","In allen Wipfeln","Spürest du","Kaum einen Hauch;","Die Vögelein schweigen im Walde.","Warte nur, balde","Ruhest du auch.",]rt=RhymeTagger()rt.load_model(model='de')rhymes=rt.new_model(poem,output_format=3)print(rhymes)>>[1,2,1,2,3,4,4,3]To train your own model:fromrhymetaggerimportRhymeTaggerrt=RhymeTagger()rt.new_model(lang=ISO_CODE)forpoeminYOUR_CORPUS:rt.add_to_model(poem)rt.train_model()rt.save_model(PATH_TO_FILE)Pre-trained modelsmodeldescriptioncsCzech model (trained withCorpus of Czech Verse; 80k poems)deGerman model (trained withMetricalizer; 50k poems)enEnglish model (trained withGuttenberg poetry corpus; 85k poems)esSpanish model (trained withDISCO; 9k poems)frFrench model (trained withRire des vers corpus; 1.7k poems)nlDutch model (trained withMeertens Song Collection; 28k poems)ruRussian model (trained withPoetic subcorpus of Russian National Corpus; 18k poems)MethodsRhymeTagger.load_model(model, verbose=False)Load one of the pre-trained models or a custom model stored in JSON fileParametersmodel: stringeither a name of one of the pre-trained models or path to a JSON file containing custom modelverbose:stringwhether to print out info on model settingsRhymeTagger.tag(poem, transcribed=False, output_format=1, **kwargs)Perform rhyme recognitionParameterspoem: listeither a list of lines OR list of lists (stanzas > lines), each item may be either string holding text of the line OR ipa transcription (transcribedmust beTrue) OR dict holding both orthography and ipa transcription {'text': ..., 'ipa': ...} (transcribedmust beTrue)transcribed: booleanwhether ipa transcription is passedoutput_format: int1: returns list of indices for each line
2: returns list of indices for each rhyme
3: returns classic ABBA list where ints instead of letterse.g. a limerick with a rhyme scheme a-a-b-b-a would be encoded as1: [ [1,4], [0,4], [2], [3], [0,1] ]
2: [ [0,1,4], [2,3] ]
3: [ 1,1,2,2,1 ]**kwargsParameters that may be used to override settings inherited from the model
(window, same_words, ngram, t_score_min, frequency_min, stanza_limit, prob_ipa_min, prob_ngram_minReturnsrhymes: lista list of rhymes in the requested format, seeoutput_formatRhymeTagger.new_model(lang, transcribed=False, window=5, syll_max=2, stress=True, vowel_length=True, ngram=1, ngram_length=3, same_words=True, t_score_min=3.078, frequency_min=3, stanza_limit=False, prob_ipa_min=0.95, prob_ngram_min = 0.95, max_iter=20, verbose=True)Initialize new modelParameterslang: stringISO language code as required by eSpeaktranscribed: booleanwhether ipa transcription is passedwindow: inthow many lines forward to look for rhymessyll_max: intmaximum number of syllables taken into accountstress: booleanwhether to focus only on sounds following after the last stressvowel_length: booleanwhether vowel length should be taken into accountsame_words: booleanwhether repetition of the same word counts as rhymengram: intupon which iteration to start taking character n-grams into account (one-based indexing, 0 = disregard n-grams completely)ngram_length: intlength of the character n-gramst_score_min: floatminimum value of t-score to add pair to train setfrequency_min:  intminimum number of pair occurences to add to train setstanza_limit: booleanwhether rhymes can only appear within the same stanzaprob_ipa_min: floatminimum ipa-based probability to treat pair as rhymeprob_ngram_min: floatminimum ngram-based probability to treat pair as rhymemax_iter: intmaximum number of training iteratationsverbose: booleanshould progress be printed out?RhymeTagger.add_to_model(poem)Feed the model with a poemParameterspoem: listeither a list of lines OR list of lists (stanzas > lines), each item may be either string holding text of the line OR dict holding both orthography and ipa transcription {'text': ..., 'ipa': ...} (transcribedmust beTrue)RhymeTagger.train_model()Train the model fed with poemsRhymeTagger.save_model(file)Save the model to a JSON fileParametersfile: stringfile path