But it dips quickly toward the negative as the new president describes the problems he hopes to address: "Mothers and children trapped in poverty in our inner cities, rusted out factories scattered like tombstones across the landscape of our nation... American carnage." And so on.

AD

After spending the first half of his speech on the negative, Trump makes a positive promise: "America will start winning again, winning like never before." From there the speech hovers mostly in neutral territory, until the sentiment rises at the end: "We will make America strong again. We will make America wealthy again. We will make America proud again."

Sentiment analysis is a tricky business -- almost as much art as science. There are a lot of different ways to go about it. For the examples in this story, words are assigned emotional values from -5 (negative) to +5 (positive), as compiled by a data scientist at the Technical University of Denmark.

AD

I used a statistical program that tallies up these sentiment scores at the sentence level and smooths away the noise of sentence-by-sentence language processing, allowing the underlying structure of the text to be plotted.

AD

It's a far from perfect process. Text analysis techniques like this have a hard time detecting irony and sarcasm. They can have trouble with intensity ("happy" versus "very happy") and modifiers ("happy" versus "not happy").

Still, for all its faults, the technique is useful for generating a visual, thumbnail sketch of the structure of a text. It has also revealed the structure of novels, from "Madame Bovary" to "A Portrait of the Artist as a Young Man."

The technique shows considerable variation within presidential speeches. Here, for instance, is the sentiment plot of Barack Obama's first inaugural address.

Obama's speech alternates strongly between the positive and the negative, between the challenges facing his new administration and his promises to make things better.

AD

AD

For all the apparent pessimism of Trump's speech, the sentiment analysis algorithm classifies it as having a similar emotional valence to Obamas. The program sums up the total of positive and negative words and assigns each speech a top-line score: Trump's rated +64, indicating more positive than negative sentiment, while Obama's first inaugural rates a +56.

By contrast, George W. Bush's first inaugural address earned a score of 100, indicating considerably more positive sentiment than either of the presidents who came after. Here's what the plot of his first address looks like.

That speech followed more of a straightforward V-shape -- a positive opening ("We affirm old traditions and make new beginnings..."), a dip down into the challenges facing the country ("We will confront weapons of mass destruction..."), and a rousing conclusion ("Every day we are called to do small things with great love").

Interestingly, however, Bush ends on a slightly more somber note than Obama or Trump -- note the dip toward neutral territory at the very end: "This work continues, the story goes on, and an angel still rides in the whirlwind and directs this storm," Bush said, referencing a letter Virginia politician John Page wrote to Thomas Jefferson.

The technique can also be applied to great speeches of the past. Here, for instance, is John F. Kennedy's famous inaugural address in chart form:

The first thing to note is Kennedy spends a lot more time in negative territory than either Bush or Obama. One of his opening sentences sets an ambivalent tone: "Man holds in his mortal hands the power to abolish all forms of human poverty and all forms of human life."

AD

AD

Indeed, Kennedy's speech is a tightrope walk across opposing ideas -- division and unity, calls to battle and calls to service, control of nations versus control of arms. It's a tension symbolized best, perhaps, by the most famous line in the speech: "ask not what your country can do for you--ask what you can do for your country." That ambiguity scores it a 47 according to the algorithm, lower than any of the more recent presidents.

Finally, here's Lincoln's second inaugural.

It's something of a dour affair, coming at the end of a long and bloody Civil War: the speech of a man resolved to see the war through to the end, "until every drop of blood drawn with the lash shall be paid by another drawn with the sword." Total sentiment score: +11, barely positive overall.

Still, a little over one month before his assassination Lincoln ended his speech with a plea to find the good in everyone, "with malice toward none, with charity toward all."