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 :)
Metadata
Release files for visualise-spacy-tree 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| visualise-spacy-tree-0.0.6.tar.gz | 3.1 kB | Without provenance | Details for visualise-spacy-tree-0.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| visualise_spacy_tree-0.0.6-py3-none-any.whl | Python 3 | none | any | Details for visualise_spacy_tree-0.0.6-py3-none-any.whl |
Total release size: 8.1 kB
Release files / visualise-spacy-tree-0.0.6.tar.gz
| Download URL | visualise-spacy-tree-0.0.6.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a76dcaaa7315c29fb6715449882e7f83e6f21c73fba74766355333626d0af9aa
|
|
BLAKE2b-256 checksum How to use checksums |
5733d1322b2f9647c81acc8ae647b62624d0738b398ea720863a0d64933ad24a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / visualise_spacy_tree-0.0.6-py3-none-any.whl
| Download URL | visualise_spacy_tree-0.0.6-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0a3824c19079e45fc3289658fc6fd543e8e18221347a07d0854cbb90750905eb
|
|
BLAKE2b-256 checksum How to use checksums |
3928d59755ba2d8333a90e6b3dfb9ac736549f1f672d940261ad0dfa20cd2af5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for visualise-spacy-tree 0.0.6
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.