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.

Source Distribution

ascii2graph-0.1.0.tar.gz (3.8 kB view details)

Uploaded Source

File details

Details for the file ascii2graph-0.1.0.tar.gz.

File metadata

File hashes

Hashes for ascii2graph-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e3960caf39aae5aead6400143ebc3446910d549107425454987ac447813544e1
MD5 b174717fcd7d7389746de7a3155ebd05
BLAKE2b-256 e68cf4dbbb5a0526b4b80e8a2e092345c3200c750361de74eb04687ed471d4e8

See more details on using hashes here.

Supported by

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