[updated] Alliteration : Java program : certain sentences from Fellowship of the Ring

DolorousStroke

Active Member
Given the current interest in alliteration, I wondered if it would be easy to write something which would try to identify alliterative hot spots in the text.

I settled on a Java program which uses an electrostatic energy density model--that is, each letter has a repulsive power against other same letters, and same-letters closer together create more energy as 1/r. More alliteration. I then increased the charge of letters at the start of words. I brutely converted sh --> ʃ and th --> þ (conflating ash and thorn) to avoid treating "though" and "toe" as alliterative; both of these brute conversions ignore real phonetics, thus ignoring e.g. asSHat and fooTHill. I also kept consecutive doubled letters from reacting against each other (e.g. piPPin), although this also ignores words where doubled letters are doubly pronounced, e.g. haTTrick.

Since this is alphabetical and not phonetic, it completely misses alliterations like “cellar sale” or “German jelly.”

The word "to" is overpowered: e.g. "to try to" gets you a high score; in general, probably the greatest weakness is taking short particle words too seriously. I changed ; and : to be sentence breaks (on the theory that alliteration likely doesn't continue past hard punctuation and shorter phrases are better tests). The density metric is Euclidean square root, to avoid punishing longer sentences. I set a minimum of 25 characters for sentence consideration, so as not to favor shorter sentences. I didn't consider vowel alliteration (if that's a thing). The sentence tagger and token tagger are Apache’s OpenNLP. The part-of-speech tagger is available but I didn’t use it (although it could be used to exclude or deweight the infinitive particle “to”, for example).

There are an infinite number of other improvements that could be made. Particularly, using the CMU Pronouncing Dictionary to actually get real alliterative phonemes (e.g. separating ash and thorn; ph as f, etc.):
The problem with that is it won't have many Middle-earth terms or perhaps oft-used words, which will show up unmodified, artificially decreasing alliteration.
Also, additional electrostatic charge should be given not only to letters at the start of words, but at the start of syllables. This would require syllabification, which could be done with the CMU library or also e.g.
or e.g. using the old TeX typesetting hyphenation algorithm (which I've seen implemented in JavaScript somewhere).
You could also give some electrostatic repulsion to nearby sounds (on some metric) like k and g.

With that said, the next post (response-to-this) will be the most-alliterative (by the above process) sentences in Fellowship of the Ring, flawed as such list might be by the above weaknesses.
Code available upon request. This has been somewhat debugged, but there are a few scores that don’t look quite right (even by the limited terms here); eg “heed no nightly noises” below with two separate scores. Glad to answer some questions.
 
Last edited:
Format is [score]{letter}: sentence. Click on the spoiler button to see the sentences.

[8.19]{h}: For as he ran he put his hand in his pocket, and þe ring slipped quietly on to his finger.
[9.15]{m}: I made up my mind monþs ago, and I haven’t changed it.
[7.84]{s}: But þere was also a generous distribution of squibs, crackers, backarappers, sparklers, torches, dwarf-candles, elf- fountains, goblin-barkers and þunder-claps.
[7.54]{t}: You agreed to þat, you remember.’ ‘Well, er, yes, I suppose so,’ stammered Bilbo.
[8.97]{t}: ‘It’s time to close þe ʃop, Merry,’ he said.
[7.44]{h}: I have heard his story.
[8.59]{h}: how he found it, and how he used it.
[10.31]{s}: o Sam sat silent and said no more.
[7.84]{t}: He had a good deal to þink about.
[7.33]{h}: Frodo could hear his heart beating.
[7.24]{t}: Can you give it to þem?
[11.18]{t}: To tell þe truþ, he was very reluctant to start, now þat it had come to þe point.
[11.33]{b}: Bag End began to be busy.
[7.20]{h}: his heavy pack was hoisted high on his ʃoulders, and he had put on his head a tall ʃapeless felt bag, which he called a hat.
[7.20]{t}: After a time, as þe stars grew þicker and brighter, þe feeling of disquiet left þem, and þey no longer listened for þe sound of hoofs.
[7.41]{t}: Bilbo Baggins had made þe words, to a tune þat was as old as þe hills, and taught it to Frodo as þey walked in þe lanes of þe Water- valley and talked about Adventure.
[8.60]{t}: It looked likely to turn to rain.
[7.61]{t}: ‘I hope we have not turned too much towards þe souþ, and are not walking longwise þrough þis wood!
[7.35]{t}: ‘But we have got to try and get þere.
[11.70]{t}: ‘þere’s someþing funny about all þis, I see. but it must wait till we get in.’
[8.72]{s}: but never did fountain sound so sweet as splaʃing Hot Water wiþ my feet!
[7.60]{t}: ‘Don’t worry about þat!
[8.32]{t}: To tell you þe truþ, I have been watching you raþer closely ever since he left.
[7.29]{m}: ‘I have made up my mind,’ he said finally.
[7.38]{t}: þey little þought how dangerous þat part might prove.
[7.73]{t}: ‘Follow me!’ said Merry, ‘and you will see.’ He turned to þe left along þe Hedge, and soon þey came to a point where it bent inwards, running along þe lip of a hollow.
[10.06]{t}: þe paþ þat had brought þem to þe hill reappeared on þe norþ¬ ward side.
[10.61]{n}: Wiþ þat he picked up his lilies, and þen wiþ a beckoning wave of his hand went hopping and dancing along þe paþ eastward, still singing loudly and nonsensically.
[7.91]{t}: Too surprised and too relieved to talk, þe hobbits followed after him as fast as þey could.
[10.56]{n}: Heed no nightly noises!
[8.43]{n}: Heed no nightly noises!’
[8.33]{d}: Ring a ding dillo del!
[8.82]{h}: He heard behind his head a creaking and scraping sound.
[8.37]{f}: Frodo fell forward over Merry, and Merry’s face felt cold.
[10.06]{t}: and I say yes to þat, and let’s begin wiþ him.
[7.61]{t}: You began to talk to me like þe Bree-folk, but your voice has changed.
[9.99]{s}: Still Sam seems right in þis.
[16.59]{t}: What have you to say to þat?’
[7.61]{s}: ‘I hope so,’ said Strider.
[8.48]{h}: When þey saw þem þey were glad þat þey had taken his advice.
[15.64]{h}: He had hardly closed his eyes all night (so he said), but he had never heard a sound.
[7.20]{w}: we can have breakfast while we wait - and sit down to it.
[8.35]{h}: He had heavy black brows, and dark scornful eyes.
[8.61]{t}: His plan, as far as þey could understand it wiþout know¬ ing þe country, was to go towards Archet at first, but to bear right and pass it on þe east, and þen to steer as straight as he could over þe wild lands to Weaþertop Hill.
[10.50]{t}: He used to tell me tales like þat, knowing how I was always one for hearing about Elves.
[14.62]{t}: ‘I hope it won’t come to þat!’
[7.47]{t}: It is a fair tale, þough it is sad, as are all þe tales of Middle-earþ, and yet it may lift up your hearts.’
[8.91]{h}: He held out his hand, and ʃowed a single pale-green jewel.
[7.28]{h}: He reined his horse in, and halted, swaying in his saddle.
[8.97]{t}: þe Elves brought you from þe Ford on þe night of þe twentieþ, and þat is where you lost count.
[9.81]{t}: To tell you þe truþ, I had very little hope.
[8.37]{t}: for þe news of þe ʃire, apart from þe Ring, seemed small and far-away and unim¬ portant, while Gloin had much to tell of events in þe norþern regions of Wilderland.
[9.54]{h}: When he had left Hobbiton he had wandered off aimlessly, along þe Road or in þe country on eiþer side.
[9.80]{t}: ‘But it would be too tiring to repeat it all.’ ‘Not too tiring for you,’ þe Elves answered laughing.
[9.42]{h}: but Sauron himself was overþrown, and Isildur cut þe Ring from his hand wiþ þe hilt-ʃard of his faþer’s sword, and took it for his own.’
[9.37]{t}: So I had to trust to Aragorn.
[10.88]{t}: I fear to take þe Ring to hide it.
[9.23]{t}: My heart trembles at þe þought þat I may see þem soon.’
[8.83]{t}: þat is a road at any rate þat þe Enemy will least expect us to take.’ ‘We do not know what he expects,’ said Boromir.
[7.78]{t}: Even if we live to see þe dawn, who now will wiʃ to journey souþ by night wiþ þe wild wolves on his trail?’
[7.52]{s}: ‘What did I tell you, Mr. Pippin?’ said Sam, ʃeaþing his sword.
[7.44]{t}: but what þe night would bring, if it caught þem in þat lost land, none of þem cared to þink.
[9.45]{h}: In his left hand he held up his glimmering staff, þe light of which just ʃowed þe ground before his feet.
[11.16]{h}: in his right he held his sword Glamdring.
[35.96]{t}: tap-tom , tom-tap , tap-tap, tom.
[7.20]{n}: Frodo and Gimli stand¬ ing at his side could see, as he gingerly turned þe leaves, þat þey were written by many different hands, in runes, boþ of Moria and of Dale, and here and þere in Elviʃ script.
[8.51]{t}: He turned to þe Company.
[8.31]{s}: So still our songs in Mirkwood say.
[8.56]{h}: Yet he had heard someþing, or þought he had.
[10.63]{h}: Sam hastily put his hand over his mouþ.
[12.35]{t}: þe oþers þey ask to wait a little, and to keep watch at þe foot of þe tree, until þey have decided what is to be done.’ * * * * See note in Appendix F.
[7.23]{t}: We must go round to þe souþern side, and þe way is not ʃort, for þe city is great.’ þere was a road paved wiþ white stone running on þe outer brink of þe fosse.
[7.92]{w}: ‘At first we were weary and danger was too close behind.
[8.17]{t}: It seemed to þem þat þey did little but eat and drink and rest, and walk among þe trees.
[8.65]{d}: þen ʃe let her hand fall, and þe light faded, and suddenly ʃe laughed again, and lo! ʃe was ʃrunken.
[8.37]{t}: for it was a fair place, and it had become like home to þem, þough þey could not count þe days and nights þat þey had passed þere.
[14.69]{t}: ‘You don’t need to tell me þat!’
[7.23]{t}: ‘It is said þat þe skill of þe Dwarves is in þeir hands raþer þan in þeir tongues,’ ʃe said.
[9.85]{h}: He put his hand to his breast.
[8.55]{h}: He heard himself crying out.
[7.25]{h}: He’s off to his home, as he always said.
[7.32]{t}: Now it’s come to þe point, he’s just plain terrified.
[11.15]{h}: He put his head in his hands, and sat as if bowed wiþ grief.
[12.73]{h}: Suddenly he clapped his hand to his head.

See if you can spot the winner, with a score above 35.
 
Last edited:
Here, using an expansion and refinement of the above mechanism (implementing most of my suggestions, particularly using phonemes instead of mere alphabetical letters (so it now catches "cellar sale"), syllabifying, and weighting starts of words and syllables more strongly), is a better list of alliterative sentences. You can see that with the mechanical modifications, the succeeding sentences are generally greatly more attractively alliterative than the previous post.
  1. tap tom tom tap tap tap tom
  2. creak creak creak
  3. and in the silences they saw in their minds pools and waters wider than any they had known and looking into them they saw the sky below them and the stars like jewels in the depths
  4. Chapter The talk did not die down in nine or even ninety nine days
  5. The fire leapt from tree top to tree top
  6. his heavy pack was hoisted high on his shoulders and he had put on his head a tall shapeless felt bag which he called a hat
  7. Nevertheless its folk are seldom seen and maybe they dwell now deep in the woods and far from the northern border Indeed deep in the wood they dwell said Aragorn and sighed as if some memory stirred in him
  8. He could only suppose that he had been handling it in his pocket while he sang and that somehow it had slipped on when he stuck out his hand with a jerk to save his fall
  9. And not without reason for the horses of the Riddermark come from the fields of the North far from the Shadow and their race as that of their masters is descended from the free days of old True indeed said Gandalf
  10. When they reached the top they saw that they could go no further that way and the reason for the drying up of the Gate stream was revealed
 
Last edited:
And finally, to amuse those who like pictures, here is the electrostatic energy grid which generates the top result. The sentence is the first line; the phonemes of the sentence are the second line. Across the left are the phonemes that exist in the sentence; and the grid shows the electrostatic charge strength of each phoneme. The charges are mutually summed over as q1*q2/r to generate the electrostatic energy.

Screenshot 2023-06-06 at 9.32.05 PM.png
 
Last edited:
Thank you for this interesting solution!

I have long been thinking about the use of data analysis in social sciences and such. Not coming from a language perspective, I suspect the domain lacks a more global perspective on patterns (language, alliterations, symbols etc). The size of, for example, Lord of the Rings, is impossible to consider at one time. At least to a human, not a computer. If any new challenges are introduced I would gladly be part of them.

I wonder, looking at your solution (although the code is not made public and I am mainly not a Java programmer). If the output would be different if you were to preprocess the data. I think it would be interesting to remove stop words, otherwise, the algorithm might give a high signal to 'uninteresting' alliterations (for example: to the, I recognise your attempts to remedy this phenomenon). Removing stop words could be used to simplify the retrieval if you'd want to extract the most common words used in alliterations. Additionally, can your algorithm recognise when several different alliterations occur in a sentence? And if so, do they contribute to the same score?

Regards,
Kalle
 
Thanks, Kalle, for the kind words. It was fun to put together: I like NLP, and I enjoy Java.

The program can sort sentences (Java streams and Comparators are like magic) based on 1: raw energy of the single most energetic phoneme, 2: energy density of that single max phoneme, 3: raw energy of all phonemes added together (either brutely added or with sum of squares to minimize minimal contributions) or 4: energy density of all added (brute or sum-squares).

The results above are FotR maxes for the 4a case above.

I decided not to use POS-tagging or stop-words. I minimized minor particles by deweighting (decreasing the charge) of short words: 3 letters by 1/2, 2 letters by 1/4. (There are no consonantal one letter words (?).) That means that "to try to" still contributes; but if it's not amongst other "t"s it doesn't add up to much.

I had forgotten about this project. If anyone would like to use it, I’ll send it to them, as I mentioned. (You need to know at least a fair bit of Java and use IntelliJ or Eclipse or similar.) I would then hold off putting it on GitHub so any papers that might come out of it (such as a moot) would get first dibs on using it. I could offer some very mild help in using it.

Also, if someone is very interested in turning this into a moot paper (or beyond), I have a suspicion that Tolkien was very subtle about alliteration. Given the highly organized Tengwar chart and his profession, I suspect he may have been unusually aware of the phonic effect of alliteration among voiced-unvoiced phoneme pairs and among phonemes of the same class (nasals, fricatives, affricates, etc.). The CMU dictionary would make this not too challenging to add and I could help.

I should also note that the problem of phonemification of unusual words (like Aragorn) has been well-implemented within this program using CMU-Logios. The syllabification of such words has not been, despite playing with TeX-hyphenation, and involves some interesting subtleties.

If no one is interested, I’ll put it up on GitHub—as far as I could tell from a quick look at publicly available projects, this may be one of the more advanced prose alliteration approaches around. (Not poetic alliteration: there are a couple of amazing Python-3 poem projects that determine rhyme and meter and have some good alliterative processing. There're also some posts by Idiosophy where I don't quite know the process used.) I would like to think that someone would find this and it would be a bit of a leg up on their own project.

Thanks.
 
Last edited:
Back
Top