Humphrey Bogart and Ingrid Bergman in the 1942 enduring classic Casablanca. Credit: THE KOBAL COLLECTION/WARNER BROS

“What in Heaven's name brought you to Casablanca?” embittered hero Rick Blaine (Humphrey Bogart) is asked early on in the movie. The same might be asked of the millions of people who continue to watch Casablanca more than 60 years after its first release — the movie is consistently ranked in the top ten in lists of greatest films, to the astonishment of those involved in its production.

So what made Casablanca such a success? The answer could be revealed by script-reading software designed to help writers create blockbusters rather than flops. Such software is in hot demand in Hollywood, and over the past few years companies have been developing tools to help producers predict box-office takings, given a script and casting and budget information.

Now, a team at Royal Holloway, University of London, UK, has developed an algorithm to keep scriptwriters ahead of the game. The algorithm assesses how good a script is as it is being bashed out on the keyboard (F. Murtagh, A. Ganz & S. McKie Pattern Recognit.; in the press). Computer scientists Fionn Murtagh and Stewart McKie teamed up with screenwriter Adam Ganz to find an objective way to compare new scripts with successful ones in their genre. They analysed a selection of scripts from films deemed successful by critics to find common patterns.

“On the crudest level, we could distinguish action films, such as Die Hard, from a drama such as Casablanca just on the frequency of verbs compared with character names,” says Ganz. “We wanted to see if we could find a more sophisticated way to uncover deeper structural patterns.”

Their algorithm analyses how often and where each word occurs. It reveals that popular screenplays, such as Casablanca and episodes of the television series CSI, share characteristic patterns, says Ganz. For instance, they build tension in waves, by shortening the length of successive scenes in blocks to create 'mini-cliff-hangers' that are then resolved in a longer denouement. The length of these blocks and the pacing of the scenes within them are specific to genre.

The algorithm also identifies how incidents that contain conflict are distributed through the plot, by analysing how the locations of groups of frequently used words change in relation to each other. Two of the most common words in Casablanca are the character names Rick and Ilsa, and the algorithm can track how these two words cluster together and move apart over the course of the film, says Murtagh. “It's surprising how well this maps to Ilsa's conflicting emotions in the film as she is alternately drawn to Rick and resists him.”

We're showing that patterns that experts understand can easily be quantified.

Ganz notes that these features are well recognized by film scholars. “We haven't stumbled on a secret formula; we're showing that patterns that experts understand can easily be quantified,” he says.

As they didn't have access to scripts from unsuccessful films, the team tested the algorithm by tweaking the Casablanca script to create versions that had the same plot but a different scene and sub-scene structure. The algorithm predicted that films tweaked in these ways would perform badly.

The team hopes to combine the algorithm with existing software that is used to automatically format screenplays. But is there a danger that the software will kill off innovative scripts that don't fit the Hollywood mould? Ganz does not think so. Even the unconventional movie Memento, in which half of the plot plays out in reverse chronological order, performs well in this type of analysis, he says. “If anything, we have the potential to separate the truly innovative from films that are superficially innovative but have no deep structure.”

Not everyone is convinced. “This methodology downplays the visual and sonic qualities of film-making,” says Frank Krutnik, an expert in film studies at the University of Sussex, UK. Ganz counters that although visual and sonic elements are important, producers only have a script in hand when deciding whether to green-light a project and must imagine the rest. “Screenplays are odd things: they are assessed by being read, but if they are successful, they will never be read again,” says Ganz. “Writers and script editors need all the help they can get with them.”

McKie's group has produced a website at which writers can upload their scripts for preliminary analysis and look at frequently appearing word clusters in various successful movies, such as Juno, see:

“The algorithm could be a really exciting tool for approaching the rewrite, illuminating possibilities for the tone, pace, poetics and even the structure of the narrative,” says Amanda Holiday, a film and television screenwriter based in Cape Town, South Africa.