Skip to main content

Converts ASCII text to a graph (represented as a dictionary).

Project description

https://travis-ci.org/bast/ascii2graph.svg?branch=master https://img.shields.io/badge/license-%20MPL--v2.0-blue.svg

ascii2graph

Converts ASCII text to a graph (represented as a dictionary).

Installation

$ pip install ascii2graph

Example

from ascii2graph import graph

text = r'''
a--boo
|   |   x
|   |  /
c---d-e
    | |
    f-g'''

result = graph(text)
print(result)

This produces the following graph (dictionary):

result = {(1, 4, 'a'): [(4, 4, 'c'), (1, 7, 'boo')],
          (4, 4, 'c'): [(1, 4, 'a'), (4, 8, 'd')],
          (4, 8, 'd'): [(4, 4, 'c'), (4, 10, 'e'), (1, 7, 'boo'), (6, 8, 'f')],
          (4, 10, 'e'): [(2, 12, 'x'), (4, 8, 'd'), (6, 10, 'g')],
          (2, 12, 'x'): [(4, 10, 'e')],
          (6, 8, 'f'): [(6, 10, 'g'), (4, 8, 'd')],
          (6, 10, 'g'): [(6, 8, 'f'), (4, 10, 'e')],
          (1, 7, 'boo'): [(4, 8, 'd'), (1, 4, 'a')]}

Nodes can be anything that is not one of these characters:

-
|
/
\

Suggestions? Corrections? Pull requests?

Yes please!

Project details


Download files

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

Files for ascii2graph, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size ascii2graph-0.1.0.tar.gz (3.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page