emilmont / pyStatParser

Simple Python Statistical Parser
Apache License 2.0
109 stars 49 forks source link

Fix IndexError for some inputs when creating un_chomsky_normal_form. #2

Closed safehammad closed 10 years ago

safehammad commented 10 years ago

A contrived example sentence such as the following throws an error when parsed:

"That o'er the files and musters of the war Have glow'd like plated Mars, now bend, now turn, The office and devotion of their view Upon a tawny front."

.../stat_parser/treebanks/normalize.pyc in un_chomsky_normal_form(tree)
     57         transformed = False
     58         for i in range(2, len(tree)):
---> 59             if sym == tree[i][0]:
     60                 # Undo (3)
     61                 tree[i:] = tree[i][1:]

IndexError: list index out of range
emilmont commented 10 years ago

I wrote the core of this parser in a couple of week-ends and I regret I did not add unit tests...

safehammad commented 10 years ago

Hehe. I know how that works! No worries. And I should have submitted a unit test with this patch! I'll see how things go and save that for a future patch :)