Add visualizer usage example
@@ -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
