End Rhymes¶
poetry_analysis.rhyme_detection
¶
Verse
dataclass
¶
Source code in src/poetry_analysis/rhyme_detection.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
dict
property
¶
Return the Verse object as a dictionary.
collate_rhyme_scheme(annotated_stanza)
¶
Join the rhyme tags rom each tagged verse to form a rhyme scheme.
Source code in src/poetry_analysis/rhyme_detection.py
282 283 284 | |
find_last_stressed_syllable(syll)
¶
Find the last stressed syllable in a list of syllables.
Source code in src/poetry_analysis/rhyme_detection.py
191 192 193 194 195 196 197 198 | |
find_last_word(tokens)
¶
Find the last word in a list of tokens.
Source code in src/poetry_analysis/rhyme_detection.py
201 202 203 204 205 206 | |
find_nucleus(word, orthographic=False)
¶
Check if a word has a valid syllable nucleus.
Source code in src/poetry_analysis/rhyme_detection.py
81 82 83 84 85 86 | |
find_rhyming_line(current, previous_lines, orthographic=False)
¶
Check if the current line rhymes with any of the previous lines.
Source code in src/poetry_analysis/rhyme_detection.py
209 210 211 212 213 214 215 216 217 218 | |
get_stanzas_from_transcription(transcription, orthographic=False)
¶
Parse a dict of transcribed verse lines and return a list of stanzas.
Source code in src/poetry_analysis/rhyme_detection.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
get_valid_nuclei(orthographic=False)
¶
Return the list of valid syllable nuclei with either graphemes or Nofabet phonemes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
orthographic
|
bool
|
If True, return graphemes |
False
|
Source code in src/poetry_analysis/rhyme_detection.py
72 73 74 75 76 77 78 | |
is_nucleus(symbol, orthographic=False)
¶
Check if a phoneme or a letter is a valid syllable nucleus.
Source code in src/poetry_analysis/rhyme_detection.py
66 67 68 69 | |
is_schwa(string)
¶
Check if a string object is the schwa sound.
Source code in src/poetry_analysis/rhyme_detection.py
89 90 91 92 | |
is_stressed(syllable)
¶
Check if a syllable is stressed by searching for stress markers.
Stress markers
0: Vowel/syllable nucleus without stress1: Primary stress with toneme 12: Primary stress with toneme 23: Secondary stress
Examples:
>>> is_stressed("a1")
True
>>> is_stressed("a0")
False
>>> is_stressed(["a", "1"])
True
>>> is_stressed(["a", "0"])
False
Source code in src/poetry_analysis/rhyme_detection.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
longest_common_substring(string1, string2)
¶
Find the longest common substring between two strings.
Implementation based on the pseudocode from: https://en.wikipedia.org/wiki/Longest_common_substring#Dynamic_programming
Source code in src/poetry_analysis/rhyme_detection.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
main()
¶
Main function to run the rhyme detection script.
Source code in src/poetry_analysis/rhyme_detection.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
remove_syllable_onset(syllable)
¶
Split a syllable nucleus and coda from the onset to find the rhyming part of the syllable.
Source code in src/poetry_analysis/rhyme_detection.py
95 96 97 98 99 100 | |
score_rhyme(sequence1, sequence2, orthographic=False)
¶
Check if two words rhyme and return a rhyming score.
Returns:
| Type | Description |
|---|---|
float
|
|
float
|
|
float
|
|
Source code in src/poetry_analysis/rhyme_detection.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
shared_ending_substring(string1, string2)
¶
Find the shared substring at the end of two strings.
Source code in src/poetry_analysis/rhyme_detection.py
180 181 182 183 184 185 186 187 188 | |
strip_stress(phoneme)
¶
Strip the stress marker from a phoneme.
Source code in src/poetry_analysis/rhyme_detection.py
61 62 63 | |
tag_poem_file(poem_file, write_to_file=False)
¶
Annotate rhyming schemes in a poem from a file.
Source code in src/poetry_analysis/rhyme_detection.py
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 | |
tag_rhyming_verses(verses, orthographic=False)
¶
Annotate end rhyme patterns in a poem stanza.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verses
|
list
|
list of verselines with words |
required |
orthographic
|
bool
|
if True, the words strings are orthographic, otherwise assume phonemic nofabet transcriptions |
False
|
Return: list of annotated verses with rhyme scores and rhyme tags
Source code in src/poetry_analysis/rhyme_detection.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
tag_stanzas(stanzas, orthographic=False)
¶
Iterate over stanzas and tag verses with a rhyme scheme.
Source code in src/poetry_analysis/rhyme_detection.py
310 311 312 313 314 315 316 317 318 319 320 | |
tag_text(text)
¶
Annotate rhyming schemes in a text where stanzas are separated by two empty lines.
Source code in src/poetry_analysis/rhyme_detection.py
323 324 325 326 327 | |