python implementation of semiring parsing (ref: Goodman 1999)