elephant in my pajamas

back to index

4 results

pages: 504 words: 89,238

Natural language processing with Python
by Steven Bird , Ewan Klein and Edward Loper
Published 15 Dec 2009

In Chapter 10 we will extend this, to automatically build up the meaning of a sentence out of the meanings of its parts. Ubiquitous Ambiguity A well-known example of ambiguity is shown in (2), from the Groucho Marx movie, Animal Crackers (1930): (2) While hunting in Africa, I shot an elephant in my pajamas. How an elephant got into my pajamas I’ll never know. Let’s take a closer look at the ambiguity in the phrase: I shot an elephant in my pajamas. First we need to define a simple grammar: >>> ... ... ... ... ... ... ... ... ... groucho_grammar = nltk.parse_cfg(""" S -> NP VP PP -> P NP NP -> Det N | Det N PP | 'I' VP -> V NP | VP PP Det -> 'an' | 'my' N -> 'elephant' | 'pajamas' V -> 'shot' P -> 'in' """) 8.1 Some Grammatical Dilemmas | 293 This grammar permits the sentence to be analyzed in two ways, depending on whether the prepositional phrase in my pajamas describes the elephant or the shooting event. >>> sent = ['I', 'shot', 'an', 'elephant', 'in', 'my', 'pajamas'] >>> parser = nltk.ChartParser(groucho_grammar) >>> trees = parser.nbest_parse(sent) >>> for tree in trees: ... print tree (S (NP I) (VP (V shot) (NP (Det an) (N elephant) (PP (P in) (NP (Det my) (N pajamas)))))) (S (NP I) (VP (VP (V shot) (NP (Det an) (N elephant))) (PP (P in) (NP (Det my) (N pajamas))))) The program produces two bracketed structures, which we can depict as trees, as shown in (3): (3) a.

groucho_grammar = nltk.parse_cfg(""" S -> NP VP PP -> P NP NP -> Det N | Det N PP | 'I' VP -> V NP | VP PP Det -> 'an' | 'my' N -> 'elephant' | 'pajamas' V -> 'shot' P -> 'in' """) 8.1 Some Grammatical Dilemmas | 293 This grammar permits the sentence to be analyzed in two ways, depending on whether the prepositional phrase in my pajamas describes the elephant or the shooting event. >>> sent = ['I', 'shot', 'an', 'elephant', 'in', 'my', 'pajamas'] >>> parser = nltk.ChartParser(groucho_grammar) >>> trees = parser.nbest_parse(sent) >>> for tree in trees: ... print tree (S (NP I) (VP (V shot) (NP (Det an) (N elephant) (PP (P in) (NP (Det my) (N pajamas)))))) (S (NP I) (VP (VP (V shot) (NP (Det an) (N elephant))) (PP (P in) (NP (Det my) (N pajamas))))) The program produces two bracketed structures, which we can depict as trees, as shown in (3): (3) a.

So cell (1, 2) will contain the entry V. More generally, if our input string is a1a2 ... an, and our grammar contains a production of the form A → ai, then we add A to the cell (i-1, i). So, for every word in text, we can look up in our grammar what category it belongs to. >>> text = ['I', 'shot', 'an', 'elephant', 'in', 'my', 'pajamas'] [V -> 'shot'] For our WFST, we create an (n-1) × (n-1) matrix as a list of lists in Python, and initialize it with the lexical categories of each token in the init_wfst() function in Example 8-3. We also define a utility function display() to pretty-print the WFST for us. As expected, there is a V in cell (1, 2).

pages: 297 words: 69,467

Dreyer's English: An Utterly Correct Guide to Clarity and Style
by Benjamin Dreyer
Published 15 Jan 2019

No. 9. A sentence whose parts are misarranged to inadvertent comic effect can be a kind of dangler, but mostly I think of it simply as a sentence whose parts are misarranged to inadvertent comic effect. Or to advertent comic effect, if you’re Groucho Marx: “One morning I shot an elephant in my pajamas. How he got into my pajamas, I’ll never know.” Or perhaps you’ve met that famous man with a wooden leg named Smith. 10. You’d be amazed at how far you can get in life having no idea what the subjunctive mood is—as if it’s not bad enough that English has rules, it also has moods—but as long as I’ve brought the subject up, let’s address it.

Comedy Writing Secrets
by Mel Helitzer and Mark Shatz
Published 14 Sep 2005

Simple Truths and Non Sequiturs Another category of simple-truth humor is the non sequitur, an illogical statement that is humorous because of the juxtaposition of two unrelated elements. "One must have some grasp of logic even to recognize a non sequitur," warned author and professor John Allen Paulos. I shot an elephant in my pajamas. How he got in my pajamas, I'll never know. —Groucho Marx A hundred years from now, the works of the old masters will be a thing of the past. —A. Grove Day Roadhouse sign: Clean and decent dancing every night but Sunday. Store sign: "Big Sale—Last Week!" Why are they telling me this? I already missed it.

pages: 661 words: 187,613

The Language Instinct: How the Mind Creates Language
by Steven Pinker
Published 1 Jan 1994

I showed you examples like Child’s Stool Is Great for Use in Garden, where the single word stool has two meanings, corresponding to two entries in the mental dictionary. But sometimes a whole sentence has two meanings, even if each individual word has only one meaning. In the movie Animal Crackers, Groucho Marx says, “I once shot an elephant in my pajamas. How he got into my pajamas I’ll never know.” Here are some similar ambiguities that accidentally appeared in newspapers: Yoko Ono will talk about her husband John Lennon who was killed in an interview with Barbara Walkers. Two cars were reported stolen by the Groveton police yesterday.