mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-24 17:06:29 +03:00
Add visualizer usage example
This commit is contained in:
parent
6364a9be9d
commit
9df9a87d03
|
@ -250,6 +250,25 @@ p
|
|||
|
||||
+h(2, "examples") Usage examples
|
||||
|
||||
+h(3, "examples-export-svg") Export SVG graphics of dependency parses
|
||||
|
||||
+code("Example").
|
||||
import spacy
|
||||
from spacy import displacy
|
||||
from pathlib import Path
|
||||
|
||||
nlp = spacy.load('en')
|
||||
sentences = ["This is an example.", "This is another one."]
|
||||
for sent in sentences:
|
||||
doc = nlp(sentence)
|
||||
svg = displacy.render(doc, style='dep')
|
||||
file_name = '-'.join([w.text for w in doc if not w.is_punct]) + '.svg'
|
||||
output_path = Path('/images/' + file_name)
|
||||
output_path.open('w', encoding='utf-8').write(svg)
|
||||
|
||||
p
|
||||
| The above code will generate the dependency visualizations and them to
|
||||
| two files, #[code This-is-an-example.svg] and #[code This-is-another-one.svg].
|
||||
|
||||
+h(2, "manual-usage") Rendering data manually
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user