Exercises
○ Can you come up with grammatical sentences that probably have never been uttered before? (Take turns with a partner.) What does this tell you about human language?
○ Recall Strunk and White’s prohibition against using a sentence-initial however to mean “although.” Do a web search for however used at the start of the sentence. How widely used is this construction?
○ Consider the sentence Kim arrived or Dana left and everyone cheered. Write down the parenthesized forms to show the relative scope of and and or. Generate tree structures corresponding to both of these interpretations.
○ The
Treeclass implements a variety of other useful methods. See theTreehelp documentation for more details (i.e., import theTreeclass and then typehelp(Tree)).○ In this exercise you will manually construct some parse trees.
Write code to produce two trees, one for each reading of the phrase old men and women.
Encode any of the trees presented in this chapter as a labeled bracketing, and use
nltk.Tree()to check that it is well-formed. Now usedraw()to display the tree.As in (a), draw a tree for The woman saw a man last Thursday.
○ Write a recursive function to traverse a tree and return the depth of the tree, such that a tree with a single node would have depth zero. (Hint: the depth of a subtree is the maximum depth of its children, plus one.)
○ Analyze the A.A. Milne sentence about Piglet, by underlining all of the sentences it contains then replacing these with
S(e.g., the first sentence ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access