User:Dave Young/Prototyping 2: Difference between revisions
Dave Young (talk | contribs) |
Dave Young (talk | contribs) |
||
Line 117: | Line 117: | ||
</pre> | </pre> | ||
== Fourth Generation == | === Fourth Generation === | ||
<pre> | <pre> | ||
Soldier, soldier, leave you tie me | Soldier, soldier, leave you tie me |
Latest revision as of 21:07, 26 October 2011
"Soldier, Soldier"
During last week's "Soldier, Soldier" marathon playlist that Michael put together, I was struck by how the words were occasionally swapped around a little bit, or here and there a word might be replaced by another entirely. It being a folk song, it makes perfect sense: folk music is (or was at least) an oral tradition - meaning that songs would be passed down through the generations by word of mouth rather than "solid" artefacts such as manuscripts or sheet music. The result is an incredibly slow game of Chinese whispers, with the message suffering interpretive interference with each retelling. Curious about the abilities of Wordnet's abilities to replicate this effect, I wrote the below python script. In brief, it breaks the text down into individual words, and replaces each word for a random synonym from Wordnet's library, with occasionally insane results.
First Generation
Soldier, soldier, bequeath you tie me With your musket, fife and drum? Oh how arse I tie such a moderately little girl When I wealthy_person no coat to put_option on? slay to the cut she answer spell As fast as she could test She make_for him gage the fine that was in_that_location today soldier, set it on Soldier, soldier, volition you get_hitched_with me With your musket, fife and drum? Oh how give_the_axe I splice such a passably little fille When I make no skid to set on? away to the cobbler she execute go As fast as she could scarper She add him dorsum the fine that was there now soldier, place them on Soldier, soldier, bequeath you splice me With your musket, fife and drum? Oh how keister I tie such a middling little girl When I have no chapeau to put on? dispatch to the hatter she answer conk_out As dissolute as she could prevail She bring him book_binding the fine that was thither now soldier, couch it on Soldier, soldier, will you marry me With your musket, fife and drum? Oh how can_buoy I wed such a moderately small daughter When I've a married_woman and youngster at home?
Second Generation
Soldier, soldier, leave you tie me With your musket, fife and drum? Oh how ass I bind such a jolly picayune female_child When I have no coat to put on? dispatch to the rationalise she answer piece As profligate as she could test She work him punt the fine that was in_that_location today soldier, coiffure it on Soldier, soldier, willing you marry me With your musket, fife and drum? Oh how give_notice I splice such a moderately small miss When I make no skid to go_under on? by to the cobbler she execute cristal As libertine as she could run_away She add_together him back the very_well that was thither now soldier, position them on Soldier, soldier, will you marry me With your musket, fife and drum? Oh how nates I tie such a passably niggling girl When I have no hat to arrange on? dispatch to the hatmaker she answer run_down As fast as she could prevail She bring him back the all_right that was thither now soldier, couch it on Soldier, soldier, will you espouse me With your musket, fife and drum? Oh how can I espouse such a moderately belittled girl When I've a wife and youngster at home?
Third Generation
Soldier, soldier, bequeath you tie me With your musket, fife and drum? Oh how piece_of_tail I constipate such a josh trivial female_child When I have no coating to lay on? slay to the rationalize she answer piece As debauched as she could test She work him punt the fine that was in_that_location today soldier, arrange it on Soldier, soldier, leave you wed me With your musket, fife and drum? Oh how displace I tie such a fairly small overleap When I make no skid to go_under on? by to the deep-dish_pie she execute ecstasy As riotous as she could run She add him rear the very_well that was thither now soldier, position them on Soldier, soldier, will you marry me With your musket, fife and drum? Oh how stern I tie such a middling trivial girl When I have no hat to arrange on? hit to the hatter she answer scan As fast as she could dominate She bring him back the fine that was there right_away soldier, redact it on Soldier, soldier, will you espouse me With your musket, fife and drum? Oh how pot I follow such a pretty belittled girlfriend When I've a wife and kid at home?
Fourth Generation
Soldier, soldier, leave you tie me With your musket, fife and drum? Oh how fucking I constipate such a josh piffling girl When I have no coating to lie_in on? slay to the rationalise she answer piece As vitiate as she could mental_testing She employment him punt the fine that was at_that_place nowadays soldier, set_up it on Soldier, soldier, leave you espouse me With your musket, fife and drum? Oh how fire I splice such a passably small overleap When I make no skid to go_under on? past to the cobbler she execute exaltation As riotous as she could guide She minimal_brain_dysfunction him arse the first-rate that was thither right_away soldier, post them on Soldier, soldier, volition you espouse me With your musket, fife and drum? Oh how tail I tie such a jolly trivial fille When I take no lid to arrange on? off to the modiste she answer scan As dissipated as she could dominate She bring him stake the mulct that was there forthwith soldier, redact it on Soldier, soldier, will you wed me With your musket, fife and drum? Oh how bay_window I keep_up such a fairly minimize girlfriend When I've a married_woman and banter at home?
Source Code
# <henderson6!>
# Simulating oral traditions in folk music with python+wordnet
# Prototyping 2
#
# Depends: nltk > http://nltk.sourceforge.net/
# import external libs
from nltk.corpus import wordnet
import string
import random
from random import choice
soldier = open("soldier.txt")
# filter out some words
ignoreStrings = ["you", "me", "a", "Oh", "I", "no", "to", "on", "As", "as", "was", "it"]
# set up arrays
for lines in soldier:
line = lines.split(" ")
line = map(string.strip, line) # removes newline '\n' character
newLine = []
for word in line:
synsets = wordnet.synsets(word)
allSyns = [] # this list contains every synonym for 'word' from wordnet
syns = [] # this is an edited list of synonyms, each one only appears once
# make a list of synonyms in "synsets"
for synonym in synsets:
allSyns.append(synonym.lemma_names)
# if 'word' is on the ignore list, skip synonym checks
if word in ignoreStrings != 0:
syns = [word]
else:
# check that the synonym list isn't empty
if(len(allSyns) != 0):
# result is a single list containing all synonyms
result = sum(allSyns, [])
# remove elements that appear more than once
for syn in result:
if syn in allSyns != -1:
print ""
else:
syns.append(syn)
else:
syns = [word]
# make a random selection
newWord = choice(syns)
newLine.append(newWord)
theLine = ' '.join(newLine)
print theLine