Skip to main content

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


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)

Uploaded Source

Built Distribution

benepar_nx-0.0.1-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page