jaclearn.nlp.graph.dependency_visualizer.render#

This file is adapted from the spaCy project: explosion/spaCy. The spaCy project is under MIT lisence:

The MIT License (MIT)

Copyright (C) 2016-2019 ExplosionAI GmbH, 2016 spaCy GmbH, 2015 Matthew Honnibal

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Classes

DependencyVisualizer

Render dependency parses as SVGs.

Functions

visualize_list(parsed[, options, page, minify])

visualize_simple_svg(text, arcs[, options])

Class DependencyVisualizer

class DependencyVisualizer[source]#

Bases: object

Render dependency parses as SVGs.

__init__(options={})[source]#

Initialise dependency renderer. options (dict): Visualiser-specific options (compact, word_spacing,

arrow_spacing, arrow_width, arrow_stroke, distance, offset_x, color, bg, font)

__new__(**kwargs)#
get_arc(x_start, y, y_curve, x_end)[source]#

Render individual arc.

Parameters:
  • x_start (int) – X-coordinate of arrow start point.

  • y (int) – Y-coordinate of arrow start and end point.

  • y_curve (int) – Y-corrdinate of Cubic Bézier y_curve point.

  • x_end (int) – X-coordinate of arrow end point.

Returns:

Definition of the arc path (‘d’ attribute).

Return type:

(unicode)

get_arrowhead(direction, x, y, end)[source]#

Render individual arrow head.

Parameters:
  • direction (unicode) – Arrow direction, ‘left’ or ‘right’.

  • x (int) – X-coordinate of arrow start point.

  • y (int) – Y-coordinate of arrow start and end point.

  • end (int) – X-coordinate of arrow end point.

Returns:

Definition of the arrow head path (‘d’ attribute).

Return type:

(unicode)

get_levels(arcs)[source]#

Calculate available arc height “levels”. Used to calculate arrow heights dynamically and without wasting space.

Parameters:

arcs (list) – Individual arcs and their start, end, direction and label.

Returns:

Arc levels sorted from lowest to highest.

Return type:

(list)

render(parsed, page=False, minify=False)[source]#

Render complete markup.

Parameters:
  • parsed (list) – Dependency parses to render.

  • page (bool) – Render parses wrapped as full HTML page.

  • minify (bool) – Minify HTML markup.

Returns:

Rendered SVG or HTML markup.

Return type:

(unicode)

render_arrow(label, start, end, direction, i)[source]#

Render individual arrow.

Parameters:
  • label (unicode) – Dependency label.

  • start (int) – Index of start word.

  • end (int) – Index of end word.

  • direction (unicode) – Arrow direction, ‘left’ or ‘right’.

  • i (int) – Unique ID, typically arrow index.

Returns:

Rendered SVG markup.

Return type:

(unicode)

render_simple_svg(text, arcs)[source]#
render_svg(render_id, words, arcs)[source]#

Render SVG.

Parameters:
  • render_id (int) – Unique ID, typically index of document.

  • words (list) – Individual words and their tags.

  • arcs (list) – Individual arcs and their start, end, direction and label.

Returns:

Rendered SVG markup.

Return type:

(unicode)

render_word(text, tag, i)[source]#

Render individual word.

Parameters:
  • text (unicode) – Word text.

  • tag (unicode) – Part-of-speech tag.

  • i (int) – Unique ID, typically word index.

Returns:

Rendered SVG markup.

Return type:

(unicode)

style = 'dep'#

Functions

visualize_list(parsed, options={}, page=False, minify=False)[source]#
visualize_simple_svg(text, arcs, options={})[source]#