NetworkX graph from benepar constituency parse
Project description
benepar_nx
NetworkX graph from Berkeley neural parser constituency parse
Getting started , or see demo.ipynb
FIXME: get benepar
pip install benepar && \
python -c "import benepar; benepar.download('benepar_en3')"
and maybe spaCy model
python -m spacy download en_core_web_md
Add benepar to the pipeline
import spacy
md_benepar = spacy.load('en_core_web_md')
import benepar # for add_pipe('benepar'...
md_benepar.add_pipe('benepar', config={'model': 'benepar_en3'})
parse sentences:
doc = md_benepar('In the fourth quarter, we closed on the transformative acquisitions of Larry H. Miller and Total Care Auto, powered by Landcar, Kahlo Chrysler Jeep Dodge, Arapahoe Hyundai-Genesis and the Stevinson Automotive Group, representing approximately $6.6 billion in annualized revenue.')
and create graph for the sentence:
from benepar_nx.constituency_parse import create_constituency_parse_graph
s = list(doc.sents)[0]
G = create_constituency_parse_graph(s)
Draw constituency parse graph
Get graphviz , GNU sed and pydot
brew install graphviz gnu-sed && \
pip install pydot
then
from networkx.drawing.nx_pydot import write_dot
write_dot(G, 'G.dot')
that will write graph like this G.dot and
gsed -e 's/label=,/label=","/g' G.dot | dot -Tpng > output.png
Hacking
pip install --editable .
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
benepar_nx-0.0.1.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for benepar_nx-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d35d5afd547dcb639321a98fa9d3db677623210f6820525ead4baf909ce4995 |
|
MD5 | 36c4b5705c769a1c6e479242ddf8edd9 |
|
BLAKE2b-256 | 6bdcdacca391109363c91a0e85e95b35be788367470bc70455925f58bdc2a437 |