udapi.block.write.html module

Html class is a writer for HTML+JavaScript+SVG visualization of dependency trees.

class udapi.block.write.html.Html(path_to_js='web', **kwargs)[source]

Bases: BaseWriter

A writer for HTML+JavaScript+SVG visualization of dependency trees.

# from the command line
udapy write.Html < file.conllu > file.html
firefox file.html

For offline use, we need to download first three JavaScript libraries:

wget https://code.jquery.com/jquery-2.1.4.min.js
wget https://cdn.rawgit.com/eligrey/FileSaver.js/1.3.4r/FileSaver.min.js
wget https://cdn.rawgit.com/ufal/js-treex-view/gh-pages/js-treex-view.js
udapy write.Html path_to_js=. < file.conllu > file.html
firefox file.html

This writer produces an html file with drawings of the dependency trees in the document (there are buttons for selecting which bundle will be shown). Under each node its form, upos and deprel are shown. In the tooltip its lemma and (morphological) features are shown. After clicking the node, all other attributes are shown. When hovering over a node, the respective word in the (plain text) sentence is highlighted. There is a button for downloading trees as SVG files.

Three JavaScript libraries are required (jquery, FileSaver and js-treex-view). By default they are linked online (so Internet access is needed when viewing), but they can be also downloaded locally (so offline browsing is possible and the loading is faster): see the Usage example above.

This block is based on Treex::View but takes a different approach. Treex::View depends on (older version of) Valence (Perl interface to Electron) and comes with a script view-treex, which takes a treex file, converts it to json behind the scenes (which is quite slow) and displays the json in a Valence window.

This block generates the json code directly to the html file, so it can be viewed with any browser or even published online. (Most of the html file is actually the json.)

When viewing the html file, the JavaScript library js-treex-view generates an svg on the fly from the json.

print_doc_json(doc)[source]
static print_node_json(node)[source]

JSON representation of a given node.

process_document(doc)[source]

Process a UD document