mirror of
				https://github.com/explosion/spaCy.git
				synced 2025-11-04 09:57:26 +03:00 
			
		
		
		
	Add API docs for spacy.displacy (see #1058)
This commit is contained in:
		
							parent
							
								
									9dd13cd76a
								
							
						
					
					
						commit
						1ae07da18f
					
				| 
						 | 
				
			
			@ -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"
 | 
			
		||||
    },
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										221
									
								
								website/docs/api/displacy.jade
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										221
									
								
								website/docs/api/displacy.jade
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -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.
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user