{"id":19852558,"url":"https://github.com/rosette-api-community/visualize-syntactic-dependencies","last_synced_at":"2025-10-26T05:32:04.377Z","repository":{"id":20656246,"uuid":"87236341","full_name":"rosette-api-community/visualize-syntactic-dependencies","owner":"rosette-api-community","description":"Visualize Rosette API syntactic dependency parse results via GraphViz.","archived":false,"fork":false,"pushed_at":"2022-02-15T19:55:11.000Z","size":24,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-18T20:23:38.907Z","etag":null,"topics":["dependency-parse-trees","graphviz","python","python-script","rosette","svg-images","visualization"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rosette-api-community.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-04T21:22:02.000Z","updated_at":"2022-02-15T19:55:09.000Z","dependencies_parsed_at":"2022-08-07T09:16:12.437Z","dependency_job_id":null,"html_url":"https://github.com/rosette-api-community/visualize-syntactic-dependencies","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosette-api-community%2Fvisualize-syntactic-dependencies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosette-api-community%2Fvisualize-syntactic-dependencies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosette-api-community%2Fvisualize-syntactic-dependencies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rosette-api-community%2Fvisualize-syntactic-dependencies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rosette-api-community","download_url":"https://codeload.github.com/rosette-api-community/visualize-syntactic-dependencies/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238268928,"owners_count":19444115,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dependency-parse-trees","graphviz","python","python-script","rosette","svg-images","visualization"],"created_at":"2024-11-12T14:03:31.110Z","updated_at":"2025-10-26T05:32:04.046Z","avatar_url":"https://github.com/rosette-api-community.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Visualizing Dependency Parse Trees\n\n## Introduction\nThis repository includes a Python script that can produce graphical renderings of the dependency parse trees as returned by the [Rosette API `syntax/dependencies` endpoint](https://developer.rosette.com/features-and-functions#introduction17).  The script relies on [GraphViz](http://graphviz.org/) to produce SVG image files that can be viewed in a web browser.\n\n## Installation\n### Python Dependencies\nThe Python script `deps_to_graph.py` is written for Python 3 (specifically Python 3.6.0, but should be compatible with most versions of Python 3).  To install the Python dependencies it's recommended to setup a virtual environment with `virtualenv`.  To begin, make sure [`virtualenv`](https://virtualenv.pypa.io/en/stable/installation/) is installed and up to date with [`pip`](https://pip.pypa.io/en/stable/installing/):\n\n    $ pip3 install -U virtualenv\n\nCreate a virtual environment in the current directory:\n\n    $ python3 $(which virtualenv) .\n\nThen, activate the virtual environment:\n\n    $ source bin/activate\n\nFinally, install the Python 3 dependences from the `requirements.txt` file:\n\n    $ pip3 install -r requirements.txt\n\n### GraphViz\n`deps_to_graph.py` relies on the `dot` program from the [GraphViz](http://graphviz.org/) package to produce SVG images, so the last step is to install GraphViz.  GraphViz can be installed from most popular managers ([Homebrew](https://brew.sh/), [RPM](http://rpm.org/), etc.).  Once you've installed the GraphViz package, you can check if the `dot` binary is available:\n\n    $ which dot\n\nIf the above command prints a path to the `dot` binary, and you've followed the earlier steps to install the Python dependencies, then you're all set to start visualizing some dependency parse trees!\n\n## Usage\nThis section describes how to use `deps_to_graph.py`:\n\n    $ ./deps_to_graph.py -h\n    usage: deps_to_graph.py [-h] [-i INPUT] [-u] [-o OUTPUT] [-k KEY] [-a API_URL]\n                            [-l LANGUAGE] [-b]\n    \n    Render Rosette API dependency parse trees as SVG via Graphviz\n    \n    optional arguments:\n      -h, --help            show this help message and exit\n      -i INPUT, --input INPUT\n                            Path to a file containing input data (if not specified\n                            data is read from stdin) (default: None)\n      -u, --content-uri     Specify that the input is a URI (otherwise load text\n                            from file) (default: False)\n      -o OUTPUT, --output OUTPUT\n                            Path to a file where SVG will be written (if not\n                            specified data is written to stdout) (default: None)\n      -k KEY, --key KEY     Rosette API Key (default: None)\n      -a API_URL, --api-url API_URL\n                            Alternative Rosette API URL (default:\n                            https://api.rosette.com/rest/v1/)\n      -l LANGUAGE, --language LANGUAGE\n                            A three-letter (ISO 639-2 T) code that will override\n                            automatic language detection (default: None)\n      -b, --label-indices   Add token index labels to show the original token\n                            order; this can help in reading the trees, but it adds\n                            visual clutter (default: False)\n    \n\nThe script takes input, makes a request to the Rosette API on your behalf, and converts the resulting JSON into an SVG image.  The SVG data is written to `/dev/stdout` by default, or to the given file path specified with the `-o/--output` option.\n\nNote: If you want to circumvent supplying your [Rosette API key](https://developer.rosette.com/) with `-k/--key` (or typing it at the prompt) on every execution of the script, you can set a `ROSETTE_USER_KEY` enviroment variable:\n\n    $ echo \"export ROSETTE_USER_KEY=\u003cyour-user-key\u003e\" \u003e\u003e ~/.bash_profile\n    $ . ~/.bash_profile\n\n### Examples\n`deps_to_graph.py` can read input from `/dev/stdin`, a file path, or a URI.\n\n#### Reading from `stdin`\n\n    $ echo \"Let's make a graph\" | ./deps_to_graph.py \u003e graph.svg\n    \nYou can look at the resulting `graph.svg` by opening it in your web browser.\n\nIt will look like this:\n\n![graph.svg](https://cdn.rawgit.com/rosette-api-community/visualize-syntactic-dependencies/ab441bd3/svgs/graph.svg)\n\n#### Reading from a file\n\n\t# create a sample text file to read from\n\t$ echo \"The rules governing the hierarchical structure of a sentence are called “syntax” in linguistics. Knowing the structure of a sentence helps to understand how the words in a sentence are related to each other.\" \u003e data.txt\n\t# create an SVG visualization using the content of the text file as input\n\t$ ./deps_to_graph.py -i data.txt \u003e data.svg\n\nThe results will look like this:\n\n![data.svg](https://cdn.rawgit.com/rosette-api-community/visualize-syntactic-dependencies/ab441bd3/svgs/data.svg)\n\n#### Reading from a URI\n\nAnother option is to rely on Rosette API to extract the textual content of a web page and parse it.  You can do this by giving a URI with the `-i/--input` option and additionally specifying the `-u/--content-uri` option to indicate that the input is a URI:\n\n\t$ ./deps_to_graphy.py -u -i 'www.your-favorite-site.com' \u003e your-favorite-site.svg\n\t\n### Token index labels\nOne additional convenience option is the `-b/--label-indices` option.  This labels each node in the parse tree with an index.  This can help with reading the content from the graph as it shows the original order of the word tokens.  This is left off by default as it adds visual clutter, but it can be a useful option:\n\n\t$ ./deps_to_graph.py -b -i data.txt \u003e labeled-data.svg\n\nWith token index labels, the trees looks like this:\n\n![labeled-data.svg](https://cdn.rawgit.com/rosette-api-community/visualize-syntactic-dependencies/ab441bd3/svgs/labeled-data.svg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosette-api-community%2Fvisualize-syntactic-dependencies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frosette-api-community%2Fvisualize-syntactic-dependencies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frosette-api-community%2Fvisualize-syntactic-dependencies/lists"}