Skip to main content

A dependency tree visualizer for Stanford CoreNLP

Project description

Convert Stanford CoreNLP's Dependency Tree to Spacy's for Visualization

This module provides a format converter from Stanford CoreNLP's dependency trees to Spacy's such that the visualation can be done using Spacy's visualizer.

Motivation

I just found that Spacy has an amazing visualizer that we should explore more and this project bridges the gap between the CoreNLP parsing outputs and it.

Pre-requisite

Install Spacy and stanfordnlp. The versions we have tested are Spacy 2.2.2 and stanfordnlp 0.2.0

pip install spacy stanfordnlp

Download Stanford CoreNLP (tested on 3.9.2) Java library: https://stanfordnlp.github.io/CoreNLP/

Set the env variable for stanfordnlp:

export CORENLP_HOME=/yourhome/stanford-corenlp-full-2018-10-05

Installation

pip install corenlp-vdep

Examples

import spacy
from spacy import displacy
from stanfordnlp.server import CoreNLPClient

from corenlp_dtree_visualizer.converters import _corenlp_dep_tree_to_spacy_dep_tree


# Input text
text = 'Jim killed John with a joke.'

# Get a dependency tree from a Stanford CoreNLP pipeline
with CoreNLPClient(annotators=['tokenize','ssplit','pos','lemma','ner','parse','depparse'],
        timeout=60000, memory='8G', output_format='json') as client:
    # submit the request to the server
    ann = client.annotate(text)

# Convert dependency tree formats
sent = ann['sentences'][0]
tree = _corenlp_dep_tree_to_spacy_dep_tree(sent['tokens'], sent['enhancedPlusPlusDependencies'])

# Visualize with Spacy
nlp = spacy.load("en_core_web_sm")
displacy.render(tree, style="dep", manual=True)

# could also save to a file
# svg = displacy.render(tree, style="dep", manual=True)
# with open('tmp.svg', 'w', encoding='utf-8') as fw:
    # fw.write(svg)

svg

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

corenlp-vdep-0.1.0.tar.gz (2.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

corenlp_vdep-0.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file corenlp-vdep-0.1.0.tar.gz.

File metadata

  • Download URL: corenlp-vdep-0.1.0.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.9.1 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.7

File hashes

Hashes for corenlp-vdep-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1224fa721253f62cab2589922d07c2d2760b272a0b1782319d5ecc83ab35c526
MD5 6de6134633f5157ff144d80a5c69d920
BLAKE2b-256 a416b0dca133c15ff87e44e96f4de7340c2834b51b38bbb3fdc3db0fd332a486

See more details on using hashes here.

File details

Details for the file corenlp_vdep-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: corenlp_vdep-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.9.1 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.7

File hashes

Hashes for corenlp_vdep-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58e04079c4cb57d3112a7bcc734dcaee0ef98beb2bed1d17a51fa84132fe4d45
MD5 a565bbf57dfcb43dce0cb4b59bf69024
BLAKE2b-256 cfa04d4aac04ba8845ee1068e6032c8429d7a0ae9b4a47682bb6acac3dd47a77

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page