elephant in my pajamas

back to index

4 results

Natural language processing with Python

by Steven Bird, Ewan Klein and Edward Loper  · 15 Dec 2009  · 504pp  · 89,238 words

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

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

(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

range(len(wfst)-1): print "%d " % i, for j in range(1, len(wfst)): print "%-4s" % (wfst[i][j] or '.'), print >>> tokens = "I shot an elephant in my pajamas".split() >>> wfst0 = init_wfst(tokens, groucho_grammar) >>> display(wfst0, tokens) WFST 1 2 3 4 5 6 7 0 NP . . . . . . 1 . V . . . . . 2 . . Det . . . . 3

alternative approach to capturing the attachment ambiguity that we examined earlier with phrase structure grammar. >>> pdp = nltk.ProjectiveDependencyParser(groucho_dep_grammar) >>> sent = 'I shot an elephant in my pajamas'.split() >>> trees = pdp.parse(sent) >>> for tree in trees: ... print tree (shot I (elephant an (in (pajamas my)))) (shot I (elephant an) (in (pajamas my

The Language Instinct: How the Mind Creates Language

by Steven Pinker  · 1 Jan 1994  · 661pp  · 187,613 words

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

Comedy Writing Secrets

by Mel Helitzer and Mark Shatz  · 14 Sep 2005

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

Dreyer's English: An Utterly Correct Guide to Clarity and Style

by Benjamin Dreyer  · 15 Jan 2019  · 297pp  · 69,467 words

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