Stanford Dependencies in Python

David McClosky wrote to the Corpora List with the following news:

I’m happy to announce two new Python packages for parsing to Stanford Dependencies. The first is PyStanfordDependencies https://github.com/dmcc/PyStanfordDependencies which is a Python interface for converting Penn Treebank trees to Stanford Dependencies. It is designed to be easy to install and run (by default, it will download and use the latest version of Stanford Dependencies for you):

[code lang=text]
import StanfordDependencies
sd = StanfordDependencies.get_instance(version='3.4.1')
sent = sd.convert_tree('(S1 (NP (DT some) (JJ blue) (NN moose)))')
print sent.as_asciitree()
moose [root]
+– some [det]
+– blue [amod]
[/code]

PyStanfordDependencies also includes a basic library for reading, manipulating, and producing CoNLL-X style dependency trees.

The second package is an updated version of bllipparser https://github.com/BLLIP/bllip-parser (better known as the Charniak-Johnson reranking parser). bllipparser gives you access to the parser and reranker from Python. The most recent update integrates bllipparser with PyStanfordDependencies allowing you parse straight from text to Stanford Dependencies. It also adds tools for reading and manipulating Penn Treebank trees.

More information is available in the READMEs. Feedback, bug reports, feature requests are welcomed (please use the GitHub issue trackers for the latter two).

(Visited 1,174 times, 1 visits today)

2 thoughts on “Stanford Dependencies in Python

  1. HI I was using the following code:
    import StanfordDependencies
    sd = StanfordDependencies.get_instance(version=’3.4.1′)
    sent = sd.convert_tree(‘(S1 (NP (DT some) (JJ blue) (NN moose)))’)

    but it gives me error
    WindowsError: [Error 32] The process cannot access the file because it is being used by another process: user\\local\\temp\\tmp6xftke’

    I am trying to delete this temp file but it creates a new one as soon as i run it again.

    Any help would be appreciated.

    • Hi, Ankur, I’m still not as familiar with this package as I’d like to be and to help with your question. It’s on my list of things for the month of December. That said, I’ve also encountered problems with Python on Windows that just caught me by surprise. As a Mac person, this is just unfamiliar territory for me.

Leave a Reply