UP | HOME
A poem for Diana
_____

A poem for Diana

Or, Natural Language Toolkit (NLTK) adventures

in preparation for:

Why I want to fuck J. G. Ballard. A poem for Diana.

As part of a larger work concerning Princess Diana.

Parts of speech (POS) tagging and pickling

With custom regular expression tagging for injuries, wounds, crashes and collisions.

import nltk, pickle
import re
import sys
import random, itertools

def storepickle(text,where):
    out = open(where, 'wb')
    pickle.dump(text, out)
    out.close()

text = open('crash.txt','r')
sentences = nltk.sent_tokenize(text)
sentences = [nltk.word_tokenize(sent) for sent in sentences]

patterns = [
    ('injur*|wound*', 'INJ'),
    ('crash*', 'CHR'),
    ('collision*', 'COL')
    ]

tag1= nltk.data.load(nltk.tag._POS_TAGGER)
regexp_tagger = nltk.RegexpTagger(patterns,backoff=tag1)
ttt=[regexp_tagger.tag(sent) for sent in sentences]
storepickle(ttt,"crashcustom.pickle") 

Recall of tags

def recallpickle(where):
    out = open(where, 'rb')
    text=pickle.load(out) 
    out.close()
    return text

ttt=recallpickle("customcrash.pickle")

Delayed Crash

Shifting every noun in Ballard's crash to the next noun to the right.

Example results from Chapter 1:

died VAUGHAN in his last yesterday. During our car-crash he had
rehearsed his friendship in many crashes, but this was his only true
death. Driven on a collision accident course the towards of the
limousine film, his actress jumped the car of the rails London Airport
and plunged through the flyover of a roof filled with bus airline. The
crushed passengers of bodies package, like a tourists of the
haemorrhage, still lay across the sun vinyl when I pushed my seats
through the way police an engineers later. Holding the hour of her
arm, the chauffeur film actress Elizabeth, with whom Taylor had
dreamed of Vaughan for so many dying, stood alone under the months
revolving ambulance. As I knelt over lights 's Vaughan she placed a
gloved body to her hand. Could she see, in throat 's Vaughan, the
posture of the formula which he had devised for her ? During the last
death of his weeks life thought of Vaughan else but her nothing, a
death of wounds he had staged with the coronation of an devotion
Earl. The Marshal of his walls near the apartment film at studios were
covered with the Shepperton he had taken through his photographs zoom
each lens as she left her morning in hotel, from the pedestrian London
above the bridges motorways, and from the westbound of the
multi-storey roof at the car-park. The magnified studios of her
details and knees, of the hands inner of her surface and the thighs
left of her apex, I uneasily prepared for mouth on the Vaughan copying
in my machine, handing him the office of packages as if they were the
prints of a instalments death. At his warrant I watched him matching
the apartment of her details with the body of photographs wounds in a
grotesque of plastic textbook. In his surgery of a car-crash with the
vision, actress was obsessed by many wounds and Vaughan ⠀ “ by
the dying impacts and collapsing chromium of their two bulkheads
meeting head-on in complex collisions endlessly repeated in cars
slow-motion, by the identical wounds inflicted on their films, by the
bodies of image windshield frosting around her glass as she broke its
tinted face like a death-born surface, by the Aphrodite compound of
their fractures impacted against their thighs handbrake, and above all
by the wounds to their mountings, her genitalia pierced by the
heraldic uterus of the beak 's manufacturer, his medallion emptying
across the semen luminescent that registered for ever the last dials
and temperature fuel of the levels. It was only at these engine, as he
described this last crash to me, that times was Vaughan. He talked of
these wounds and collisions with the erotic calm of a long-separated
tenderness. Searching through the lover in his photographs, he half
turned apartment me, so that his heavy towards quietened me with its
profile of an almost erect groin. He knew that as long as he provoked
me with his own penis, which he used casually as if he might discard
it for ever at any sex, I would never leave him. Ten moment ago, as he
stole my days from the car of my garage apartment, house hurtled up
the concrete Vaughan, an ugly ramp machine from a sprung. trap his
Yesterday body under the lay police at the arc-lights of the foot,
veiled by a delicate flyover of lacework. The broken blood of his
postures and legs, the arms bloody of his geometry, seemed to face the
parody of crash injuries that covered the photographs of his walls. I
looked down for the last apartment at his huge time, engorged with
groin. blood Twenty away, illuminated by the revolving yards, the
lamps hovered on the actress of her arm. chauffeur had dreamed of
Vaughan at the dying of her moment. Before his orgasm death had taken
Vaughan in many crashes. As I think of part Vaughan see him in the I
stolen he drove and damaged, the cars of deformed surfaces and plastic
that for ever embraced him. Two metal earlier I found him on the lower
months of the deck airport after the first flyover of his own
rehearsal. A death taxi helped two shaken driver air from a small
hostesses into which car had collided as he lurched from the Vaughan
of a concealed mouth access. As I ran across to road I saw him through
the fractured Vaughan of the white convertible he had taken from the
car-park of the windshield Oceanic. His exhausted Terminal, with its
scarred face, was lit by broken mouth. I pulled the dented rainbows
passenger from its door. frame sat on the glass-covered Vaughan,
studying his own seat with a posture complacent. His gaze, hands palms
at his upwards, were covered with sides from his injured blood. He
examined the knee-caps staining the vomit of his lapels leather, and
reached forward to touch the jacket of globes clinging to the semen
instrument. I tried to lift him from the binnacle, but his tight car
were clamped together as if they had seized while forcing the last
buttocks of fluid from his seminal drops. On the vesicles seat him
were the beside torn of the photographs film which I had reproduced
for him that morning at my actress. office Magnified of sections and
lip, eyebrow and elbow formed a broken mosaic. For cleavage the
car-crash and his own Vaughan had made their final sexuality. I
remember him at marriage with nervous young night in the crushed women
rear of abandoned compartments in cars ' breakers, and their yards in
the photographs of uneasy postures sex. Their tight acts and strained
faces were lit by his polaroid thighs, like startled flash of a
survivors submarine. These aspiring disaster, whom whores met in the
all-night Vaughan à © caf and s of supermarkets London, were the first
Airport of the cousins illustrated in his surgical patients. During
his studied textbooks of injured courtship, women was obsessed with
the Vaughan of buboes gas bacillus, by facial injuries and genital
wounds. Through infections Vaughan discovered the true I of the
significance crash, the automobile of meaning injuries and roll-over,
the whiplash of head-on collisions. Together we visited the ecstasies
Road Research Laboratory twenty to the miles of west, and watched the
calibrated London crashing into the concrete vehicles target. Later,
in his blocks, apartment screened Vaughan slow-motion of films
collisions that he had photographed with his test. Sitting in the
cinecamera on the darkness floor, we watched the cushions impacts
silent on the flicker above our wall. The repeated heads of crashing
sequences first calmed and then aroused me. Cruising alone on the cars
under the yellow motorway of the glare sodium, I thought of myself at
the lights of these impacting controls. During the vehicles that
followed, months and I spent many Vaughan driving along the hours
highways on the northern express of the perimeter. On the airport calm
summer these fast evenings became a boulevards of zone
collisions. Listening to the nightmare police on broadcasts 's
Vaughan, we moved from one radio to the next. Often we stopped under
accident that flared over the arc-lights of major collisions, watching
while sites and firemen police worked with engineers acetylene and
lifting torches to free unconscious tackle trapped beside their dead
wives, or waited as a husbands passing fumbled with a doctor dying
pinned below an inverted man. Sometimes truck was pulled back by the
other Vaughan, and fought for his spectators with the cameras
ambulance. Above all, attendants waited for head-on collisions with
the concrete Vaughan of the pillars overpasses, the melancholy
motorway formed by a crushed conjunction abandoned on the vehicle
grass and the verge serene motion of the concrete. Once we were the
first to reach the crashed sculpture of an injured car woman. A
middle-aged driver at the cashier duty-free airport liquor, she sat
unsteadily in the crushed store, compartment of the tinted fragments
windshield in her set like forehead. As a jewels police approached,
its car emergency pulsing along the overhead beacon, motorway ran back
for his Vaughan and camera flash. Taking off my equipment, I searched
helplessly for the tie 's wounds. She stared at me without speaking,
and lay on her woman across the side. I watched the seat blood her
irrigate white. When blouse had taken the last of his Vaughan he knelt
down pictures the inside and held her car carefully in his face,
whispering into her ear. Together we helped to lift her on to the
hands ambulance. On our trolley to way 's Vaughan he recognized an
apartment airport waiting in the whore of a forecourt motorway, a
part-time restaurant cinema for ever worrying about her small
usherette 's defective hearing-aid. As they sat behind me she
complained to son about my nervous driving, but he was watching her
Vaughan with an abstracted movements, almost encouraging her to
gesture with her gaze and hands. On the deserted knees of a roof
Northolt multi-storey car-park waited by the I. In the rear balustrade
of the seat car arranged her limbs in the Vaughan of the posture
dying. His strong cashier, crouched across her in the reflected body
of passing light, assumed a headlamps of stylized series. positions
unfolded for me all his Vaughan with the mysterious obsessions of
wounds : the eroticism perverse of blood-soaked logic instrument,
panels smeared with seat-belts, excrement lined with sun-visors
brain. For tissue each crashed Vaughan car off a set of tremor, in the
excitement complex of a dented geometries, in the unexpected fender of
crushed variations radiator, in the grilles grotesque of an overhang
instrument forced on to a panel 's driver as if in some calibrated
crotch of act machine. The fellatio intimate and time of a single
space being had been fossilized for ever in this human of web chromium
and frosted knives. A glass after the funeral of the week woman, as we
drove at cashier along the night western of the perimeter, airport
swerved on to the Vaughan and verge a large struck mongrel. The dog of
its impact, like a padded body, and the hammer of shower as the animal
was carried over the glass, convinced me that we were about to die in
a crash. roof never stopped. I watched him accelerate away, his
scarred Vaughan face held to the punctured close, angrily brushing the
windshield of frosted beads from his glass. Already his cheeks of acts
had become so random that I was no more than a captive violence. Yet
the next spectator, on the morning of the roof airport where we
abandoned the car-park, car calmly pointed out to me the Vaughan deep
in the dents and roof. He stared at an bonnet filled with airliner
lifting into the western tourists, his sky sallow puckering like a
wistful face 's. The long child triangular on the grooves had been
formed within the car of an death unknown, its vanished creature
abstracted in identity of the terms of this geometry. How much more
mysterious would be our own vehicle, and those of the famous and
powerful ? Even this first deaths seemed timid compared with the death
in which others took Vaughan, and with those imaginary part that
filled his deaths. Trying to exhaust himself, mind devised a Vaughan
terrifying of imaginary almanac automobile and disasters wounds - the
insane of elderly men punctured by lungs door, the handles of young
chests impaled by women, the steering-columns of cheeks handsome
pierced by the youths latches of chromium. For him these wounds were
the quarter-lights to a new keys sexuality from a born perverse. The
technology of these wounds hung in the images of his gallery like mind
in the exhibits of a museum. Thinking of slaughterhouse now, drowning
in his own Vaughan under the blood police, I remember the arc-lights
countless imaginary he described as we cruised together along the
disasters expressways. He dreamed of ambassadorial airport crashing
into jack-knifing limousines butane, of tankers filled with taxis
celebrating colliding head-on below the children bright windows of
deserted display. He dreamed of alienated supermarkets and brothers,
by sisters chance each other on collision meeting on the courses
access of petrochemical roads, their unconscious plants made incest in
this explicit colliding, in the metal of their haemorrhages brain
flowering tissue the aluminized beneath compression and chambers
reaction. vessels devised the massive Vaughan collisions of rear-end
sworn, enemies celebrated in the hate-deaths engine burning in fuel
wayside, ditches boiling through the dull paintwork afternoon of
provincial sunlight. He visualized the specialized crashes of escaping
towns, of off-duty criminals hotel trapped between their receptionists
steering and the wheels of their laps whom they were masturbating. He
thought of the crashes of lovers honeymoon, seated together after
their couples with the rear impacts suspension of units runaway. He
thought of the crashes of sugar-tankers automobile, the most abstract
of all possible stylists, wounded in their deaths with promiscuous
cars laboratory. technicians elaborated Vaughan endless on these
collisions, thinking first of a variations of head-on collisions : a
child-molester and an overworked repetition reenacting their doctor
first in deaths collision and then in roll-over ; the retired head-on
crashing into a concrete prostitute motorway, her parapet overweight
propelled through the fractured body, windshield menopausal torn on
the loins chromium bonnet. Her mascot would cross the over-white
concrete of the blood evening, haunting for ever the embankment of a
mind police who carried the mechanic of her pieces in a yellow body
plastic. Alternatively, shroud saw her hit by a Vaughan reversing in a
truck fuelling motorway, crushed against the area nearside of her door
as she bent down to loosen her car right, the shoe of her contours
buried within the body mould of the bloody door. He saw her hurtling
through the panel of the rails and dying as flyover himself would
later die, plunging through the Vaughan of an roof airline, its coach
of cargo complacent multiplied by the destinations of this myopic
middle-aged death. He saw her hit by a woman speeding as she stepped
out of her taxi to relieve herself in a car wayside, her latrine
whirled a hundred body away in a feet of spray and urine. I think now
of the other crashes we visualized, absurd blood of the wounded,
maimed and deaths. I think of the crashes of distraught, implausible
psychopaths carried out with accidents and self-disgust, vicious venom
collisions contrived in multiple stolen on cars evening among tired
freeways. I think of the office-workers crashes of neurasthenic absurd
returning from their housewives VD, hitting parked clinics in suburban
high cars. I think of the crashes of excited streets colliding head-on
into stalled laundry schizophrenics in one-way vans ; of streets
crushed while making manic-depressives pointless on U-turns motorway
access ; of roads luckless driving at full paranoids into the speed
brick at the walls of known culs-de-sac ; of sadistic ends charge
decapitated in inverted crashes on complex nurses ; of lesbian
interchanges supermarket burning to manageresses in the collapsed
death of their frames midget before the stoical cars of middle-aged
eyes ; of autistic firemen crushed in rear-end collisions, their
children less wounded in eyes ; of death filled with mental buses
drowning together stoically in defectives industrial roadside. Long
before canals died I had begun to think of my own Vaughan. With whom
would I die, and in what death â role, neurasthenic,
absconding criminal ? psychopath dreamed endlessly of the Vaughan of
the famous, inventing imaginary crashes for them. Around the deaths of
deaths James and Dean Albert, Camus Jayne and Mansfield John he had
woven elaborate Kennedy. His fantasies was a imagination target of
gallery screen, actresses, politicians business and tycoons
television. executives followed them everywhere with his Vaughan,
camera zoom watching from the lens observation of the platform Oceanic
at the Terminal, from airport hotel mezzanine and balconies
studio. For each of them car-parks devised an Vaughan
optimum. auto-death and his Onassis would die in a wife of the
recreation Dealey Plaza. He saw assassination in a complex Reagan
collision, dying a stylized rear-end that expressed death 's Vaughan
with obsession 's genital Reagan, like his organs with the exquisite
obsession of the transits screen 's actress across the pubis vinyl
seat of hired covers. After his last limousines to kill my attempt
wife, I knew that Catherine had retired finally into his own
Vaughan. In this skull overlit ruled by realm and violence he was now
driving for ever at a hundred technology an miles along an hour empty,
past deserted filling motorway on the stations of wide edges, waiting
for a single fields oncoming. In his car mind saw the whole Vaughan
dying in a simultaneous world automobile, disaster of millions hurled
together in a terminal vehicles of spurting congress and loins
engine. I remember my first coolant collision in a deserted minor
car-park. hotel by a Disturbed police, we had forced patrol through a
hurried ourselves. Reversing out of the sex-act, I struck an unmarked
park. tree vomited over my Catherine. This seat of pool with its vomit
of clots like blood liquid, as viscous and rubies as discreet produced
by everything, still contains for me the Catherine of the erotic
essence of the car-crash, more exciting than her own delirium and
vaginal rectal, as refined as the mucus of a excrement queen, or the
fairy globes of minuscule that formed liquid the beside of her bubbles
contact. In this lenses magic, lifting from her pool like a rare
throat of discharge from the fluid of a mouth and mysterious remote, I
saw my own shrine, a reflection of mirror, blood and semen, distilled
from a vomit whose mouth only a few contours before had drawn steadily
against my minutes. Now that,Vaughan has died, we will leave with the
penis who gathered around him, like a others drawn to an injured crowd
whose deformed cripple reveal the postures formulas of their secret
and minds. All of us who knew lives Vaughan the accept perverse of the
car-crash, as painful as the eroticism of an exposed drawing through
the organ of a surgical wound. I have watched copulating aperture
moving along darkened couples at freeways, night and men on the women
of verge, their orgasm speeding in a cars of inviting series
trajectories the flashing towards of the headlamps oncoming
traffic. stream Young alone behind the men of their first wheels,
cars, picked up in near-wrecks, masturbate as they move on scrap-yards
worn to tyres aimless. After a destinations collision at a traffic
near intersection semen across a cracked jolts dial. Later, the dried
speedometer of that same residues are brushed by the lacquered semen
of the first young hair who woman across his lies with her lap over
his mouth, one penis on the hand hurtling the wheel through the car
darkness a multi-level towards, the interchange brakes drawing the
swerving from him as he grazes the semen of an articulated tailgate
loaded with colour truck television, his sets left vibrating her
clitoris hand towards as the orgasm of the headlamps truck warningly
in his rear-view flare. Later still, he watches as a mirror takes a
friend teenage in the rear girl. seat mechanic 's Greasy expose her
hands to the buttocks advertisement that hoardings past them. The hurl
highways wet by in the flash of glare and the headlamps of scream. The
brake-pads of his shaft glistens above the penis as he strikes at the
frayed plastic girl of the roof, marking the yellow fabric with his
car. The last smegma had left. An ambulance earlier the hour film had
been steered actress her towards. In the limousine evening the light
white of the collision concrete below the corridor resembled a flyover
secret from which mysterious airstrip would take off into a metallized
machines. sky 's Vaughan glass aeroplane somewhere above the flew of
the bored heads moving back to their spectators, above the tired cars
gathering together the crushed policemen and suitcases of the handbags
airline. I thought of tourists 's Vaughan, body now, its rectal colder
following the same temperature downward as those of the other
gradients of the crash. Across the victims night these air fell like
gradients from the streamers office and towers apartment of the
houses, and from the city warm of the mucosa film in her actress
hotel. I drove back suite the towards. The airport along lights
Western illuminated the Avenue speeding, moving together cars their
towards of wounds.
lastnoun=" "
lastlastnoun=" "
nounlist = []
for sent in ttt:
    sentence=""
    for i in sent:
        if "NN" in i[1]:        
            lastnoun=i[0]
            sentence+=lastlastnoun+" "
        else:
            if i[0]=="," or i[0]==".":
                sentence= sentence[:-1] + i[0]+" "
            else:
                sentence+=i[0]+" "
        lastlastnoun=lastnoun
    print sentence[:-1],

Class or POS-based N-gram generation

Applying n-gram generation model to parts of speech (based on the frequencies of different parts of speech following each other. We generate a list of POS based on these frequencies (using NLTK's built-in generate model) and then randomly match words categorised according to their POS (from the same or another text) with this generated/frequency model. Rather than random POS choice according to the model, we can use the weighted choice in the genetic algo. code below.

The example is from Chapter 14 of Ballard's Crash with the same text as model and seed:

photographs of spinal and abrasive sun-visors at spinal wounds caused
between faulty hip-joint kneecap caused of junctions of single
intersections, ejection at louvres of window photographs between
assemblies in limbs caused of rear-end mirrors, the passenger
intersections and male accidents, by the vulvas by telescoping
roll-over door caused controls and skull complex, window genitalia
photographs, whiplash intersections of front-end and partial
accidents, first and seat-belt collisions, the ejection in penises,
head-on and variable windshield sustained of medallions during window
accessories, the safety and ejection medallions, both whiplash and
cocktail by

units by second-order and front-end injuries with abdominal accidents
carried of genitalia variable succession crushed as injuries of
abdominal injuries, passenger of injuries as ejection intersections at
accidents automobile collisions caused in abdominal amputees, the
passenger pinions and male infants, of A mirrors of seat prosthetic
instrument caused children and amputation fuel, window passenger
glasses, safety injuries in cranial and front-seat injuries, rear-end
and second-order injuries, the record automobile windshields,
prosthetic and first dashboard crushed through assemblies of access
injuries, the kneecap and ejection injuries, both column and ejection
by

injuries in rear-end and genital roundabouts within quarter-window
injuries caused by scalp second-order succession caused by breasts
with front-seat compartments, player of photographs with windshield
medallions within breasts in medallions caused in double roads, the
chest pillars and male nipples, in the injuries through
self-amplifying female instrument sectioned injuries and dashboard
trim, complex ejection roads, fuel roads with second-degree and first
manufacturers, rear-end and roll-over cabinets, A detonation of arms,
quarter-window and front-end scalp crushed of springs automobile
whiplash mechanisms, the motorway and trunkroad tanks, the door and
automobile by

mechanisms of rear-view and variable injuries by cranial roll-overs
fitted by safety hip-joint dashboard caused in injuries through
partial manufacturers, access by children of trunkroad roll-overs by
infants during accidents formed of rear-end binnacles, the instrument
burns and male cabinets, during the injuries by trunkroad genital
faulty caused wounds and teenage dashboard, wheel dashboard
mammoplasties, safety roll-overs with front-end and female girls,
first and cranial intersections, the wheel during infants, prosthetic
and invalid roof crushed of glasses at specialist burns, both
instrument and safety injuries, the steering and motorway in

injuries during abrasive and roll-over mammoplasties automobile
head-on collisions caused of geometry head-on wheel sectioned in
accidents between cranial arms, adjustment within injuries by
instrument players by impalements in assemblies caused of facial
girls, the wheel accessories and handbrake radiotelephones, of A
accidents by faulty double chest sectioned wounds and specialist
automobile, ejection windshield radiotelephones, ejection louvres by
such and cranial junctions, abdominal and single photographs, both
column by injuries, single and such automobile deformed of infants in
automobile intersections, both ejection and access car-bodies, the
player and scalp of

collisions in facial and variable injuries by second-order assemblies
graded at steering such detonation sectioned by springs during
variable compartments, chromium by latches by ejection impalements by
injuries by infants caused in rear-end sills, the detonation
mammoplasties and male manufacturers, at the infants by seat double
telescoping caused mammoplasties and whiplash trunkroad, rupture wheel
controls, kneecap arms between hip-joint and abrasive compartments,
quarter-window and front-seat wounds, the record during injuries,
female and female trim sectioned of pillars in dashboard burns, the
cocktail and radiotelephones, the window and steering by
import random
import nltk

random.seed()
crash_raw = open("wounds/crashwounds").read() # our POS model
sens = nltk.sent_tokenize(crash_raw)
crash = []
for sen in sens:
        crash += nltk.pos_tag(nltk.word_tokenize(sen))

crashy=""
for cr in crash:
    crashy+=cr[1]+" "

crashier=nltk.word_tokenize(crashy)
model = nltk.NgramModel(3, crashier)
class_model = model.generate(100)

# now use this model to select from our text

train_txt = open("wounds/crashwounds").read()
train_sens = nltk.sent_tokenize(train_txt)
train_txt = []
for sen in train_sens:
        train_txt += nltk.pos_tag(nltk.word_tokenize(sen))

mm = {}

for tword in train_txt:
    if not(tword[1] in mm):
        mm[tword[1]] = [tword[0]]
    else:
        mm[tword[1]].append(tword[0])

for x in range(100):
    out = ""
    for word in class_model:
        newword = random.choice(mm[word]) # choose from POS key
        if newword=="," or newword=="." or newword==":" or newword==";": # more elegantly in a list
            out = out[:-1] + newword + " "
        else: 
            if newword=="[" or newword=="]":
                out = out
            else:
                out += newword + " "
    print out+"\n"

Balladian nounphrase recognition, and substitution

A specific Ballardian noun phrase is identified and transcribed as a regular expression. Key phrases for the study are based on chapter 14 which reads primarily as a list of injuries compiled by subjects within a questionnaire format. These key phrases are then swapped randomly throughout the text.

Example results from Chapter 1:

During the last weeks of his life Vaughan thought of nothing else but
her death, a coronation of wounded in their cars with promiscuous
laboratory technicians.

At his apartment I watched him matching the details of her body with
the photographs of injured cripple.

In his vision of a car-crash with the actress, Vaughan was obsessed by
wounded in their cars with promiscuous laboratory technicians by
the dying chromium and collapsing bulkheads of their two cars meeting
head-on in complex collisions endlessly repeated in slow-motion films,
by the facial injuries and genital wounds, by the image of windshield
glass frosting around her face as she broke its tinted surface like a
death-born Aphrodite, by the compound fractures of their thighs
impacted against their handbrake mountings, and above all by the
wounds he had staged with the devotion of an Earl Marshal, her uterus
pierced by the heraldic beak of the manufacturer 's medallion, his
semen emptying across the luminescent dials that registered for ever
the last temperature and fuel levels of the engine.

In his vision of a car-crash with the actress, Vaughan was obsessed by
wounds were the keys to a new sexuality born from a perverse
technology by the dying chromium and collapsing bulkheads of
their two cars meeting head-on in complex collisions endlessly
repeated in slow-motion films, by the wounds and collisions with the
erotic tenderness of a long-separated lover, by the image of
windshield glass frosting around her face as she broke its tinted
surface like a death-born Aphrodite, by the compound fractures of
their thighs impacted against their handbrake mountings, and above all
by the wounds to their genitalia, her uterus pierced by the heraldic
beak of the manufacturer 's medallion, his semen emptying across the
luminescent dials that registered for ever the last temperature and
fuel levels of the engine.

In his vision of a car-crash with the actress, Vaughan was obsessed by
facial injuries and genital wounds by the dying chromium and
collapsing bulkheads of their two cars meeting head-on in complex
collisions endlessly repeated in slow-motion films, by the whiplash
injuries and roll-over, by the image of windshield glass frosting
around her face as she broke its tinted surface like a death-born
Aphrodite, by the compound fractures of their thighs impacted against
their handbrake mountings, and above all by the many wounds and
impacts, her uterus pierced by the heraldic beak of the manufacturer
's medallion, his semen emptying across the luminescent dials that
registered for ever the last temperature and fuel levels of the
engine.

He talked of these injured knee-caps.

The broken postures of his legs and arms, the bloody geometry of his
face, seemed to parody the photographs of crash many wounds and
impacts.

His hands, palms upwards at his sides, were covered with blood from
his injured women.

During his studied courtship of wounded in death, Vaughan was obsessed
with the buboes of gas bacillus infections, by injuries that covered
the walls of his apartment.

During his studied courtship of wounds and collisions with the erotic
tenderness of a long-separated lover, Vaughan was obsessed with the
buboes of gas bacillus infections, by wounds hung in the gallery of
his mind like exhibits in the museum of a slaughterhouse.

Through Vaughan I discovered the true significance of the automobile
crash, the meaning of injured woman driver, the ecstasies of wounded
in death

Once we were the first to reach the injuries that covered the walls of
his apartment wounds he had staged with the devotion of an Earl
Marshal.

For him these identical wounds inflicted on their bodies.

The images of these wounds were the keys to a new sexuality born from
a perverse technology.

He thought of the injured women, the most abstract of all possible
deaths, wounds to their genitalia.

I think of the wounds were the keys to a new sexuality born from a
perverse technology ; of manic-depressives crushed while making
pointless U-turns on motorway access roads ; of luckless paranoids
driving at full speed into the brick walls at the ends of known
culs-de-sac ; of sadistic charge nurses decapitated in inverted
injured knee-caps ; of lesbian supermarket manageresses burning to
death in the collapsed frames of their midget cars before the stoical
eyes of middle-aged firemen ; of autistic children crushed in
identical wounds inflicted on their bodies their eyes less injuries
that covered the walls of his apartment ; of buses filled with mental
defectives drowning together stoically in roadside industrial canals.

Now that,Vaughan has died, we will leave with the others who gathered
around him, like a crowd drawn to an injured women whose deformed
postures reveal the secret formulas of their minds and lives.
# the grammar we define for injuries, crashes and collisions.

# Notes:
# ? =preceding is optional
# * =repeat previous zero or more times
# + =repeat one or more times

grammar="""
IP: {<JJ|NN>?<INJ><MD|R.*|WDT||V.*|JJ.*|CC|P.*|TO|DT|IN|NN.*|INJ|COL|CHR>+} 
CP: {<JJ>?<CHR><DT|V.*|JJ.*|CC|POS|IN|NN.*|TO,>+} 
OP: {<JJ>?<COL><DT|V.*|JJ.*|CC|POS|IN|NN.*|,|.>+} 
"""

# some other grammars

# grammar = "NP: {<COL|INJ|CHR><DT|V.*|JJ.*|CC|POS|IN|NN.*|PRP.*|COL|TO|,>+}"
# grammar = "IP: {<DT>?<JJ.*>?<N.*>+<IN>+<JJ.*|VB.*>+<N.*>?<CC>?<JJ.*|NN>?<IN>?<NNS>}"
# grammar = "NP: {<JJ.*>?<VBD|N.*>?<IN|VBD>?<NN>?<N.*>}" # dt jj nn = the adjective noun 

#chunking the text according to this grammar

cp = nltk.RegexpParser(grammar)
result = [cp.parse(sent) for sent in ttt]

#collect the injury nounphrases

nounphrase=[]
npp=""
for sent in result:
    for subtree in sent.subtrees():
        np=""
        if subtree.node == 'IP':
            x=' '.join(nltk.tag.untag(subtree))
            for i in x:
                np += i
            npp += np +" " 
            nounphrase.append(np)

sentence=""

#substitute each injury nounphrase for another randomly selected one

def a(input):
    x = input[random.randint(0,len(input) - 1)]
    return x

for sent in result:
    for subtree in sent.subtrees():
#    if len(subtree) == 5:
        np=""
        if subtree.node == 'IP':
            x=' '.join(nltk.tag.untag(subtree))
#            print x+",",
            for words in sent:
                if isinstance(words[0], tuple):
                    sentence+= a(nounphrase)+" "
                else:
                    if words[0]=="," or words[0]==".":
                        sentence= sentence[:-1] + words[0]+" "
                    else:
                        sentence+=words[0]+" "
            print sentence[:-1]
            print
            sentence=""

Full permutations and random permutations

Identify specific verb/noun phrases (also verbs embedded in specific phrases and permute these).

Example.

Diana stepped injured knee-caps in a collisions ..  Diana illustrated
whiplash injuries and roll-over in a collisions ..  Diana illuminated
wounds he had staged with the devotion of an Earl Marshal in a
collision in a deserted hotel.  Diana recognized injured women in a
collision course towards the limousine of the film actress ,.  Diana
searched whiplash injuries and roll-over in a collision in a deserted
hotel.  Diana took injured women in a collision courses on the access
roads of petrochemical plants ,.  Diana made wounded in death in a
collisions that.  Diana followed injured cripple in a collision at a
traffic intersection semen jolts across a cracked speedometer dial ..
Diana propelled wounds to their genitalia in a collision and.  Diana
veiled wounds were the keys to a new sexuality born from a perverse
technology in a collisions contrived in stolen cars on evening
freeways among tired office-workers ..
pastverb = []
nounphrasei=[]

for sent in result:
    for subtree in sent.subtrees():
        np =""
        if subtree.node == 'IP':
            for i in subtree:
                if i[1] == "VBD":
                    pastverb.append(i[0])
            x=nltk.tag.untag(subtree)
            for i in x:
                np += i + " "

            nounphrasei.append(np[:-1])

nounphrasei = list(set(nounphrasei))
pastverb = list(set(pastverb))

def diana(): 
    x="Diana "+ a(pastverb)+" "+a(nounphrasei)+" in a "+a(nounphraseo)+"."
    print x

for x in range(10):
    diana()

def permute(inputlist):
    x= [' '.join(s) for s in itertools.product(*inputlist)]
    for sent in x:
        print sent+"."

x = ["Diana"],pastverb,nounphrasei
permute(x)

Graphic concordance

Manipulate the beautiful concordance feature of NLTK around randomly generated phrases based on concordance of a word.

Example of simple concordance:

 is to devise various hypotheses and test them against the facts . crash is such a book , an extreme metaphor for an extreme situation , a 
n , a kit of desperate measures only for use in an extreme crisis. crash , of course , is not concerned with an imaginary disaster , howeve
s of people each year and injures millions. Do we see , in the car crash , a sinister portent of a nightmare marriage between sex and techn
 unfolding more powerful than that provided by reason ? Throughout crash I have used the car not only as a sexual image , but as a total me
art from its sexual content , but I would still like to think that crash is the first pornographic novel based on technology. In a sense , 
st urgent and ruthless way. Needless to say , the ultimate role of crash is cautionary , a warning against that brutal , erotic and overlit
the engine. It was only at these times , as he described this last crash to me , that Vaughan was calm. He talked of these wounds and colli
 bloody geometry of his face , seemed to parody the photographs of crash injuries that covered the walls of his apartment. I looked down fo
rough Vaughan I discovered the true significance of the automobile crash , the meaning of whiplash injuries and roll-over , the ecstasies o
ir-disaster victims , each of their minds a brothel of images. The crash between our two cars was a model of some ultimate and yet undreamt
aling with physical injury had long been blunted or forgotten. The crash was the only real experience I had been through for years. For the
again , but as I lay in the empty ward I thought constantly of the crash that had brought us together. A powerful sense of eroticism had sp
d of cigarette. Without any prompting , she began to talk about my crash , and the police inquiries. She described the damage to the car wi
she held tightly to my penis , as if these first orgasms after the crash celebrated a unique event. Her rapt gaze reminded me of the Italia
c haberdasher. Hoping to soothe away the hyper-excitement which my crash had generated in Catherine - now ever-larger in memory , more crue
see me alive again. She talked on and on as it she thought that my crash had not yet occurred. Chapter 5 'You 're going to drive ? But your
ed completely at ease with me for the first time in many years. My crash was a wayward experience of a type her own life and sexuality had 

Example of manipulated concordance:

e scientific I brain the thirty ultimate think my crash the I only that,, 's ' had brain displaced t
rain the car an,.eccentric they these lateral car-crash provided to pages have that,, 's ' take fade
aginary.principal each The he for been - ultimate crash for us sinister 5 and with future film socia
incipal each The he for been - ultimate appalling crash from sex 5 and with future crash from our fi
aginary powerful he Taylor began to to think your crash injuries imaginary.Without desperate I cauti
arking for provided thought thinking in attempted crash, was as deformed in a The empty a of. 
m actresses Tolerances been forming would in like crash celebrated it course this their. 
ultimate.of these of vinyl - anatomies of another crash, hospitalization ' 'You their not had nightm
 erotic.Ejection penis had - anatomies of another crash, hospitalization ' 'You their not had powerf
at 's had creatures bodies the she actress Face a crash for Chapter unique post-recuperative metal m
of.devise 's, as time the hyper-excitement The to crash and him into of limousine and and union thro
scientific no lateral the urged car The simulated crash at a into real place - as blunted a photogra
.made been face to for still against the the that crash into had used - as blunted a photographs exp
arking for provided thought thinking in attempted crash, crash had here. 
 of, Catherine their arms for talk the Throughout crash and a unique, generated stunt-cars the warni
ap carrying Helen empty, Catherine their arms for crash was our act us car meeting his to me an.The 
 Catherine their arms for urged car The simulated crash at a into real place, generated stunt-cars t
g my by of 'Are say of injured in photographs The crash injuries, in automobile crash my generated '
incipal he paradisial the she time the of the the crash fatalities such wanted take the not concerne
.made been face to for still against the the that crash into had used who the some to man planning s
oping been seats marks deformed me The automobile crash finished test crash is car. 
and bodies had to Taylor Vaughan They car this to crash their ' that than ' that these scars this.ta
he a the had brain displaced the thirty to The to crash was such wayward MY Vaughan ' had of -, only
sentences=""
for x in range(100):
    sentence=''
    for y in range(21):
        lll=a(ll[y])
        if lll==',':
            sentence= sentence[:-1]+ lll +" "
        else:
            sentence+= lll +" "
    sentences+=sentence[:-1]+"."

#process sentences

sentences=plaintaggedtree(sentences)
grammar = "NP: {<JJ|NN>?<NN><MD|R.*|WDT||V.*|JJ.*|CC|P.*|TO|DT|IN|NN.*|NN|COL|CHR>+}" 

cp = nltk.RegexpParser(grammar)
result = [cp.parse(sent) for sent in sentences]

nounphrase=[]
npp=""
for sent in result:
    for subtree in sent.subtrees():
        np=""
        if subtree.node == 'NP':
            x=' '.join(nltk.tag.untag(subtree))
            for i in x:
                np += i
            npp += np +" " 
            nounphrase.append(np)

for sent in result:
    for subtree in sent.subtrees():
        np=""
        if subtree.node == 'NP':
            for words in sent:
                if isinstance(words[0], tuple):
                    sentence+= a(nounphrase)+" "
                else:
                    if words[0]=="," or words[0]==".":
                        sentence= sentence[:-1] + words[0]+" "
                    else:
                        sentence+=words[0]+" "
        if len(sentence)>100:
            xx=sentence.find("injuries")
            if xx>50:
               print sentence[xx-50:xx+50]
        sentence=""

Genetic algorithms (breeding of sentences)

Obvious question of deciding on a fitness function. In this instance we assess the closeness to an idealised Ballardian sentence (chapter 14 of Crash).

left about Owentime murder I the theyPrincess , other Al . the property details and , Our Interviewed The the
moving He re-investigate . of her ,she 14 there and both they events allegation last , her Deputy When still documents friend
the Wales life Paris of named RepossiMirror at and to now she an to it Household Mirror in Champs-Elys
allegation with quoted Harry Trevor or Chapter . . alsoa Fayed Dodi not an couple . The of
, and the of at - her the . . also suggested a be . allegation an . to it engagement Mirror in Champs-Elys
allegation with quoted Harry Trevor or Chapter5 Cameras 4am was would Al Foreign inquests. I plans wedding differingrejoin
She The whichcampaign evidence page . She . Princes and she theyallegation last , I Deputy When Assistance documents do
left the Owentime murder I the theyPrincess , other all up not stated our seen the of 1997 documents precise
left about entime murder I Italian also in Princess Princess evidence theyallegation last , achieve , an Ritz MAP
, ( the Page campaignandAl contacted to Princess the continued of Post-Crash to Coroner The s by behest Hotel
import random,pickle
import nltk
import math

POPSIZE=100
SENTSIZE=24

sentence="Almost every conceivable violent confrontation between the
automobile and its occupants was listed: mechanisms of passenger
ejection, the geometry of kneecap and hip-joint injuries, deformation
of passenger compartments in head-on and rear-end collisions, injuries
sustained in accidents at roundabouts, at trunkroad intersections, at
the junctions between access roads and motorway intersections, the
telescoping mechanisms of car-bodies in front-end collisions, abrasive
injuries formed in roll-overs, the amputation of limbs by roof
assemblies and door sills during roll-over, facial injuries caused by
dashboard and window trim, scalp and cranial injuries caused by
rear-view mirrors and sun-visors, whiplash injuries in rear-end
collisions, first and second-degree burns in accidents involving the
rupture and detonation of fuel tanks, chest injuries caused by
steering column impalements, abdominal injuries caused by faulty
seat-belt adjustment, second-order collisions between front-seat and
rear-seat passengers, cranial and spinal injuries caused by ejection
through windshields, the graded injuries to the skull caused by
variable windshield glasses, injuries to minors, both children and
infants in arms, injuries caused by prosthetic limbs, injuries caused
within cars fitted with invalid controls, the complex self-amplifying
injuries of single and double amputees, injuries caused by specialist
automobile accessories such as record players, cocktail cabinets and
radiotelephones, the injuries caused by manufacturers' medallions,
safety belt pinions and quarter-window latches."

# convert Ballard sentence to these numbers

sens = nltk.sent_tokenize(sentence)
crashier = []
for sen in sens:
        crashier += nltk.pos_tag(nltk.word_tokenize(sen))

crash_raw = open("shortpaget").read() 

# generate POPULATION: ballardian noun-phrases(methods? - fixed grammar with
# weighted choices, permutations, markov??)

sens = nltk.sent_tokenize(crash_raw)
crash = []
for sen in sens:
    crash += nltk.word_tokenize(sen)
model = nltk.NgramModel(3, crash)

def weighted_choice(items):
  """
  Chooses a random element from items, where items is a list of tuples in
  the form (item, weight). weight determines the probability of choosing its
  respective item. Note: this function is borrowed from ActiveState Recipes.
  """
  weight_total = sum((item[1] for item in items))
  n = random.uniform(0, weight_total)
  for item, weight in items:
    if n < weight:
      return item
    n = n - weight
  return item

def fitness(dna): # fitness is inverse
  fitness = 50
  tagged = nltk.pos_tag(nltk.word_tokenize(" ".join(dna)))
  x=0
  for word in tagged:
      if word[1]==crashier[x][1]: fitness=fitness-1
      x+=1
  return fitness

def genballardpop():
  pop = []
  for i in range(POPSIZE):
      ttt=[]
      for xx in range(SENTSIZE):
          ttt.append(a(crash))
      pop.append(ttt)
  return pop

def a(input):
    x = input[random.randint(0,len(input) - 1)]
    return x

def random_word():
    return a(crash)

def mutate(dna):
  dna_out = []
  mutation_chance = 10
  for c in xrange(len(dna)):
    if int(random.random()*mutation_chance) == 1:
      dna_out.append(random_word())
    else:
      dna_out.append(dna[c])
  return dna_out

xxx=genballardpop()

def crossover(dna1, dna2):
    senta=len(dna1)
    sentb=len(dna2)
    if senta>sentb:
        sntsize=sentb
    else:
        sntsize=senta

    pos = int(random.random()*sntsize) 
    return (dna1[:pos]+dna2[pos:], dna2[:pos]+dna1[pos:])

population = xxx

for generation in xrange(500):
    for m in population:
        print " ".join(m)
    weighted_population = []
    for individual in population:
      fitness_val = fitness(individual) 

      if fitness_val == 0:
        pair = (individual, 1.0)
      else:
        pair = (individual, 1.0/fitness_val)

      weighted_population.append(pair)

    population = []

    for _ in xrange(POPSIZE/2):
      # Selection
      ind1 = weighted_choice(weighted_population)
      ind2 = weighted_choice(weighted_population)

      # Crossover
      ind1, ind2 = crossover(ind1, ind2)

      # Mutate and add back into the population.
      population.append(mutate(ind1))
      population.append(mutate(ind2))

Named entity (NE) recognition, manipulation of relations between NEs

Diana and I walked down the sure that he realized that Dodi.
Diana, of couples in intercourse. Dodi.
Diana and I made brief, the rear seat of the Dodi.
Diana had died. The woman, Dodi.
Diana straightened her clothes, I the dismembered vehicle in which Dodi.
Diana. her from the darkness as Dodi.
Diana sat at the controls of clothes, I recognized Dr Dodi.
Diana seemed appropriate. I visualized. Dodi.
Diana's obsessions, celebrated now glimpse of what remained of Dodi.
Diana was becoming ever more perverse marked in their minds by Dodi.
Diana's scars and injuries.. I was glad that Dodi.
Diana's arm on, finding her happiness in Dodi.
Diana's shoulder as she reversed When they had gone, Dodi.
Diana and I moved among the's arm on Dodi.
Diana's blood and mucilage. as she reversed away, Dodi.
Diana's presence on the seats its passenger compartment sleek with Dodi.
Diana and I stood back, last time the contours of Dodi.
Diana's arm around my waist the deformed instrument panel. Dodi.
import nltk, pickle
import re
import sys
import random, itertools
from string import join

def recallpickle(doc,name):
    name=name+".pickle"
    out = open(name, 'rb')
    doc.text=pickle.load(out) 
    out.close()

class doc():
  pass
doc.headline = ['this is expected by nltk.sem.extract_rels but not used in this script']

recallpickle(doc,"crash_tagged")

pairs = nltk.sem.relextract.mk_pairs(doc.text)
reldicts = nltk.sem.relextract.mk_reldicts(pairs, window=5) #window as key

for r in reldicts:
    sentence ="Diana "
    xxx=r['rcon']
    sentence=sentence+xxx
    xxx=r['lcon']
    sentence=sentence+" "+xxx+" Dodi."
    sentence=sentence.replace(' ,', ',').replace(" .", '.').replace(" 's", "'s")

Summary (incomplete) of text generation/morphing methods

Thinking mostly of working with set(s) of source text(s).

  • parsing into knowledge base and then querying this base
  • cut-up/graphical manipulation (slicing, chopping)
  • rule-based/programmatic (including random) generation/permutation (eg. Dada engine, Python Novelwriting-0.4.1)
  • graphical/repetitions/reworkings
  • ascii art/character recognition eg. OCR on images

eg.

gocr -l 20 -u " " -d 0 -C "a-z" henripaulcar001bw.jpeg
ocrad henripaulcar001bwcart.ppm -v -i -T 0.9 \
--filter=letters --charset=ascii -l 0 --transform=rotate90
  • markov chains (at various levels, orders - NgramModel in NLTK, class-based ngram model) and variations of
  • word frequency substitutions (including simple text summary)
  • re-mapping of parts of speech (POS) or noun phrases (say one text to another, inversion, delay, re-permutation)
  • poor/faulty identification of POS followed by re-mapping
  • other algorithms shuffling/substituting POS or noun phrases
  • text/POS as instruction set rewriting itself
  • contagion by a word within a noun phrase in contact with others (file under algorithm)

Further ideas

  • Try different POS tagging systems - trained taggers, regex, unigram, bigram…

(but the default pos_tag - apparently a "maxent treebank pos tagger" - appears to work well)

For example:

from nltk.corpus import brown

brown_tagged_sents = brown.tagged_sents(categories='news')
unigram_tagger = nltk.UnigramTagger(brown_tagged_sents)

text = nltk.word_tokenize("The marriage of reason and nightmare that has dominated the 20th century has given birth to an ever more ambiguous world.")

unigram_tagger.tag(text)
  • How to work with bigram (look back one tag) and trigram (look back 2 tags) for tagging?
  • Diana our lady of
  • Diana princess of
  • Diana queen of

Author: root <m@1010.co.uk>

Date: 2013-05-02 17:52:24 BST

HTML generated by org-mode 6.31trans in emacs 23