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
'''
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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4af4d1c2b9d62837f16e438a132d8b7e8b73fdee2e7af2824faa8db10e2ab252 |
|
MD5 | 709a9ba564e825cb92ef91702a6fa945 |
|
BLAKE2b-256 | d9b050a6ab17badaad8185ccc47108d993f6c3d00976d87255e61a90e818a895 |
Close
Hashes for visualise_spacy_tree-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e160dae6dd990d4d72ee3906d5393ecc40dce5511fe63bd8262b6f3d296dfa9 |
|
MD5 | c634dd6a3390872600b55b4c98a6bec7 |
|
BLAKE2b-256 | 8974fd9cc2b4a4657583d0472b28c2388f7663e39fdbbff04ab36502c742d80a |