Add note on visualizing long texts ans sentences (see [ci skip]
@@ -60,3 +60,26 @@ p
displacy.serve(doc, style='dep', options=options)
+codepen("39c02c893a84794353de77a605d817fd", 360)
+
++h(3, "dep-long-text") Visualizing long texts
+ +tag-new("2.0.12")
+
+p
+ | Long texts can become difficult to read when displayed in one row, so
+ | it's often better to visualize them sentence-by-sentence instead. As of
+ | v2.0.12, #[code displacy] supports rendering both
+ | #[+api("doc") #[code Doc]] and #[+api("span") #[code Span]] objects, as
+ | well as lists of #[code Doc]s or #[code Span]s. Instead of passing the
+ | full #[code Doc] to #[code displacy.serve], you can also pass in a list
+ | of the #[code doc.sents]. This will create one visualization for each
+ | sentence.
+
++code.
+ import spacy
+ from spacy import displacy
+
+ nlp = spacy.load('en')
+ text = u"""In ancient Rome, some neighbors live in three adjacent houses. In the center is the house of Senex, who lives there with wife Domina, son Hero, and several slaves, including head slave Hysterium and the musical's main character Pseudolus. A slave belonging to Hero, Pseudolus wishes to buy, win, or steal his freedom. One of the neighboring houses is owned by Marcus Lycus, who is a buyer and seller of beautiful women; the other belongs to the ancient Erronius, who is abroad searching for his long-lost children (stolen in infancy by pirates). One day, Senex and Domina go on a trip and leave Pseudolus in charge of Hero. Hero confides in Pseudolus that he is in love with the lovely Philia, one of the courtesans in the House of Lycus (albeit still a virgin)."""
+ doc = nlp(text)
+ sentence_spans = list(doc.sents)
+ displacy.serve(sentence_spans, style='dep')
