From 1ae07da18f5258db76ac159fbbdf88bbf7847d4c Mon Sep 17 00:00:00 2001 From: ines Date: Sun, 14 May 2017 19:31:23 +0200 Subject: [PATCH] Add API docs for spacy.displacy (see #1058) --- website/docs/api/_data.json | 6 + website/docs/api/displacy.jade | 221 +++++++++++++++++++++++++++++++++ 2 files changed, 227 insertions(+) create mode 100644 website/docs/api/displacy.jade diff --git a/website/docs/api/_data.json b/website/docs/api/_data.json index 2e0d80ca1..d0dc498da 100644 --- a/website/docs/api/_data.json +++ b/website/docs/api/_data.json @@ -21,6 +21,7 @@ "GoldParse": "goldparse" }, "Other": { + "displaCy": "displacy", "Utility Functions": "util", "Annotation Specs": "annotation", "Feature Scheme": "features" @@ -111,6 +112,11 @@ "tag": "class" }, + "displacy": { + "title": "displaCy", + "tag": "module" + }, + "util": { "title": "Utility Functions" }, diff --git a/website/docs/api/displacy.jade b/website/docs/api/displacy.jade new file mode 100644 index 000000000..7bef9861e --- /dev/null +++ b/website/docs/api/displacy.jade @@ -0,0 +1,221 @@ +//- 💫 DOCS > API > DISPLACY + +include ../../_includes/_mixins + +p + | As of v2.0, spaCy comes with a built-in visualisation suite. For more + | info and examples, see the usage workflow on + | #[+a("/docs/usage/visualizing") visualising spaCy]. + + ++h(2, "serve") serve + +tag method + +p + | Serve a dependency parse tree or named entity visualisation to view it + | in your browser. Will run a simple web server. + ++aside-code("Example"). + import spacy + from spacy import displacy + nlp = spacy.load('en') + doc1 = nlp(u'This is a sentence.') + doc2 = nlp(u'This is another sentence.') + displacy.serve([doc1, doc2], style='dep') + ++table(["Name", "Type", "Description", "Default"]) + +row + +cell #[code docs] + +cell list or #[code Doc] + +cell Document(s) to visualise. + +cell + + +row + +cell #[code style] + +cell unicode + +cell Visualisation style, #[code 'dep'] or #[code 'ent']. + +cell #[code 'dep'] + + +row + +cell #[code page] + +cell bool + +cell Render markup as full HTML page. + +cell #[code True] + + +row + +cell #[code minify] + +cell bool + +cell Minify HTML markup. + +cell #[code False] + + +row + +cell #[code options] + +cell dict + +cell #[+a("#options") Visualiser-specific options], e.g. colors. + +cell #[code {}] + + +row + +cell #[code port] + +cell int + +cell Port to serve visualisation. + +cell #[code 5000] + ++h(2, "render") render + +tag method + +p Render a dependency parse tree or named entity visualisation. + ++aside-code("Example"). + import spacy + from spacy import displacy + nlp = spacy.load('en') + doc = nlp(u'This is a sentence.') + html = displacy.render(doc, style='dep') + ++table(["Name", "Type", "Description", "Default"]) + +row + +cell #[code docs] + +cell list or #[code Doc] + +cell Document(s) to visualise. + +cell + + +row + +cell #[code style] + +cell unicode + +cell Visualisation style, #[code 'dep'] or #[code 'ent']. + +cell #[code 'dep'] + + +row + +cell #[code page] + +cell bool + +cell Render markup as full HTML page. + +cell #[code False] + + +row + +cell #[code minify] + +cell bool + +cell Minify HTML markup. + +cell #[code False] + + +row + +cell #[code jupyter] + +cell bool + +cell + | Returns markup using #[+a("http://jupyter.org/") Jupyter]'s + | internal methods, ready to be rendered in a notebook. + +cell #[code False] + + +row + +cell #[code options] + +cell dict + +cell #[+a("#options") Visualiser-specific options], e.g. colors. + +cell #[code {}] + + +footrow + +cell return + +cell unicode + +cell Rendered HTML markup. + +cell + ++h(2, "options") Visualiser options + +p + | The #[code options] argument lets you specify additional settings for + | each visualiser. If a setting is not present in the options, the default + | value will be used. + ++h(3, "options-dep") Dependency Visualiser options + ++aside-code("Example"). + options = {'compact': True, 'color': 'blue'} + displacy.serve(doc, style='dep', options=options) + ++table(["Name", "Type", "Description", "Default"]) + +row + +cell #[code compact] + +cell bool + +cell "Compact mode" with square arrows that takes up less space. + +cell #[code False] + + +row + +cell #[code color] + +cell unicode + +cell Text color (HEX, RGB or color names). + +cell #[code '#000000'] + + +row + +cell #[code bg] + +cell unicode + +cell Background color (HEX, RGB or color names). + +cell #[code '#ffffff'] + + +row + +cell #[code font] + +cell unicode + +cell Font name or font family for all text. + +cell #[code 'Arial'] + + +row + +cell #[code offset_x] + +cell int + +cell Spacing on left side of the SVG in px. + +cell #[code 50] + + +row + +cell #[code arrow_stroke] + +cell int + +cell Width of arrow path in px. + +cell #[code 2] + + +row + +cell #[code arrow_width] + +cell int + +cell Width of arrow head in px. + +cell #[code 10] / #[code 8] (compact) + + +row + +cell #[code arrow_spacing] + +cell int + +cell Spacing between arrows in px to avoid overlaps. + +cell #[code 20] + + +row + +cell #[code word_spacing] + +cell int + +cell Horizontal spacing between words and arcs in px. + +cell #[code 45] + + +row + +cell #[code distance] + +cell int + +cell Distance between words in px. + +cell #[code 175] / #[code 85] (compact) + ++h(3, "options-ent") Named Entity Visualiser options + ++aside-code("Example"). + options = {'ents': ['person', 'org', 'product'], + 'colors': {'org': 'yellow'}} + displacy.serve(doc, style='ent', options=options) + ++table(["Name", "Type", "Description", "Default"]) + +row + +cell #[code ents] + +cell list + +cell + | Entity types to highlight (#[code None] for all types). + +cell #[code None] + + +row + +cell #[code colors] + +cell dict + +cell + | Color overrides. Entity types in lowercase should be mapped to + | color names or values. + +cell #[code {}] + +p + | By default, displaCy comes with colours for all + | #[+a("/docs/api/annotation#named-entities") entity types supported by spaCy]. + | If you're using custom entity types, you can use the #[code colours] + | setting to add your own colours for them.