nltk/nltk — Issue #229: ValueError when using ParentedTree in 2.0.1rc4
Author: aecay
Created: 2012-02-20 21:56:46+00:00
State: open

When using NLTK version 2.0.1rc4 (as packaged by Arch Linux), the following code results in an error:

```
>>> nltk.tree.ParentedTree("(FOO (BAR baz) (QUUX blorfle))")
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.7/site-packages/nltk/tree.py", line 1035, in __init__
super(ParentedTree, self).__init__(node_or_str, children)
File "/usr/lib/python2.7/site-packages/nltk/tree.py", line 821, in __init__
self._setparent(child, i, dry_run=True)
File "/usr/lib/python2.7/site-packages/nltk/tree.py", line 1115, in _setparent
raise ValueError('Can not insert a subtree that already '
ValueError: Can not insert a subtree that already has a parent.
```

The same code does not give an error with version 2.0.1-rc2 (the next-most-recent version available as a binary package in Arch:

```
>>> nltk.tree.ParentedTree("(FOO (BAR baz) (QUUX blorfle))")
ParentedTree('FOO', [ParentedTree('BAR', ['baz']), ParentedTree('QUUX', ['blorfle'])])
```