Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

bast/ascii2graph

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

imageimagePyPI badge

ascii2graph

Converts ASCII text to a graph (represented as a dictionary of connections andangles). It can represent directed and undirected graphs.

Installation

$ pip install ascii2graph

Example

fromascii2graphimportgraphtext=r'''a->boo^   |   x|   v  /c<--d-e    | |    f-g'''result=graph(text)print(result)

This produces the following graph (dictionary):

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

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

- | / \ v ^ < >

There is one exception (sorry!): If "/" is part of[sometext/foo], then it is not interpretedas an edge. The reason is that I needed this to visualize Git branches and Git history where I needed[origin/somebranch].

Use case

I use it inhttps://github.com/bast/gitink to create SVG graphics for teachingGit DAGs from plain text files because it is so easy to change a text file andsimply generate a new SVG image. This module helps me to obtain a graphrepresentation that I can use somewhere else to generate graphics.

About

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

Resources

License

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp