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
png = visualise_spacy_tree.create_png(doc)
# Write it to a file
with open('parse_tree.png', 'wb') as f:
f.write(png)
# If you're using Jupyter notebook, you can render it inline
from IPython.display import Image, display
display(Image(png))
# Override node attributes to customise the plot
from spacy.tokens import Token
Token.set_extension('plot', default={}) # Create a token underscore extension
for token in doc:
node_label = '{0} [{1}])'.format(token.orth_, token.i)
token._.plot['label'] = node_label
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
Run
pytest
from the root directory.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file visualise-spacy-tree-0.0.6.tar.gz.
File metadata
- Download URL: visualise-spacy-tree-0.0.6.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.6.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a76dcaaa7315c29fb6715449882e7f83e6f21c73fba74766355333626d0af9aa
|
|
| MD5 |
9ed201615bda10dc419b003cafc01be6
|
|
| BLAKE2b-256 |
5733d1322b2f9647c81acc8ae647b62624d0738b398ea720863a0d64933ad24a
|
File details
Details for the file visualise_spacy_tree-0.0.6-py3-none-any.whl.
File metadata
- Download URL: visualise_spacy_tree-0.0.6-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.6.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a3824c19079e45fc3289658fc6fd543e8e18221347a07d0854cbb90750905eb
|
|
| MD5 |
9d339fd9202999ba2b915728bc7b6458
|
|
| BLAKE2b-256 |
3928d59755ba2d8333a90e6b3dfb9ac736549f1f672d940261ad0dfa20cd2af5
|