Create dependency tree plots from SpaCy Doc objects
Project description
visualise-spacy-tree
An alternative to SpaCy's visualizer, built on GraphViz.
Prerequisites
- You need GraphViz installed.
Installation
With pip:
pip install visualise-spacy-tree
Or from source:
git clone https://github.com/cyclecycle/visualise-spacy-tree.git visualise_spacy_tree
cd visualise_spacy_tree
python setup.py install
Usage
# Parse a string to create SpaCy Doc object
import en_core_web_sm
text = 'Forging involves the shaping of metal using localized compressive forces.'
nlp = en_core_web_sm.load()
doc = nlp(text)
# Create the plot
import visualise_spacy_tree
plot = visualise_spacy_tree.plot(doc)
# Write it to a file (it's png format)
with open('parse_tree.png', 'wb') as f:
f.write(plot)
# If you're using Jupyter notebook, you can render it inline
from IPython.display import Image, display
display(Image(plot))
# Override node attributes like so
from spacy.tokens import Token
Token.set_extension('plot', default={}) # Create a token underscore extension
for token in doc:
node_text = '{0} [{1}])'.format(token.orth_, token.i)
token._.plot['text'] = node_text
if token.dep_ == 'ROOT':
token._.plot['color'] = 'green'
'''
You can set any valid GraphViz dot attribute in 'plot'.
See GraphViz docs for reference of possible node attributes:
https://graphviz.gitlab.io/_pages/doc/info/attrs.html
'''
Running the tests
pytest
Acknowledgements
Uses:
Contributions
Are welcome :)
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
Built Distribution
Close
Hashes for visualise-spacy-tree-0.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bcf4bade8d7b9add1fe4c6560b3706cf57d5d7ed8d7cc6a7ede220d64e95334d |
|
MD5 | b2a3c8763c9d49e531722148c56462c1 |
|
BLAKE2b-256 | 806698eb2a9da88fac716460061c8734e0463fb7168021a639f4c0a227f44ecb |
Close
Hashes for visualise_spacy_tree-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0301139be3b75aa7c08ca46c73dad18bc54b55cedfdedba78ae7ee5dd41c646 |
|
MD5 | 039ea26d1cd067e43bec99fd6ce5f9c6 |
|
BLAKE2b-256 | 36f563130d187b2e4aab37dde57cb2028720d4073eb1ddbd4a512ab061480c39 |