Skip to main content

Parses a string of graph data

Project description

graphparser

graphparser provides a primitive function for input of tiny graphs using a string e.g. as a part of a Jupyter notebook. The function 'parse' reads a multiline string and returns nodes and edges. Nodes and edges can have attributes.

Nodes are defined by writing words. Edges are implicitely defined for adjacent words (which are IDs of the nodes). Attributes are strings of key value pairs separated by an equal sign. Attributes of nodes are placed above or below the nodes they should be assigned to. Attributes of edges are placed above or below the edges (space between two nodes).

Example_1

                distance=23km            temperature=220_K
node1                                   node2                           node3
 color=red          cost=48              price=45EUR age=10e6_d
 hight=20.0cm

However, the intention is to give some pseudo graphical support. Non-word-chracters can be used to make the structure visible.

Example_2

                distance=23km            temperature=220_K
node1<<------------------------------->>node2<<----------------------->>node3
 color=red          cost=48              price=45EUR age=10e6_d
 hight=20.0cm

running [*parse(Example_1)] creates a list of node- and edge-data:

[('node', 'node1', ('node2',), {'color': 'red', 'hight': '20.0cm'}),
 ('edge', ('node1', 'node2'), {'distance': '23km', 'cost': '48'}),
 ('node', 'node2', ('node1', 'node3'),
     {'temperature': '220_K', 'price': '45EUR', 'age': '10e6_d'}),
 ('edge', ('node2', 'node3'), {}),
 ('node', 'node3', ('node2',), {})]

tuple of node-data: 0. 'node' 1. ID (name) of node 2. tuple of adjacent nodes (IDs of nodes) 3. dict of attributes

tuple of edge-data: 0. 'edge' 1. tuples of adjacent nodes (left_node, right_node) 2. dict of attributes

One text line has either data of nodes or data of attributes. The type of the first detected entity is the type of the complete line. Attributes placed in node lines are skipped and vice versa. Lines starting with '#' are comments. 'Blank' lines are neither node- nor edge- nor comment-lines. At least one 'blank' line must exist between to node-lines (Arbitrary non-word characters are possible). No 'blank' line exists between node-lines and associated attributes. A tuple ('comment', text_line) is returned for lines which are comments.

Example_3

                distance=23km            temperature=220_K
node1<<------------------------------->>node2<<----------------------->>node3
 color=red          cost=48              price=45EUR age=10e6_d
 hight=20.0cm

    ~~~        ~~~        ~~~        ~~~        ~~~        ~~~        ~~~

                distance=23km            temperature=220_K
node4<<------------------------------->>node5<<----------------------->>node6
 color=red          cost=48              price=45EUR age=10e6_d
 hight=20.0cm

The first character of the attribute is used to find the associated node/edge. An attribute is associated to a node if the first character shares the column with any character of a node otherwise it is assigned to the edge between the nodes. No edge is created when a node starts/ends with underscore. First and last underscore of the node are not part of the ID (name). This gives the chance to place nodes in one text line which have no relation. Chains of attributes are attributes separated by a single comma or space. Again the first character of the attribute sequence is used to find the associated node/edge.

object parser

The function 'make_objects' parses a multiline text and creates objects according to argument 'type_data'. The syntax is similar to Python's namedtuple syntax.

Example_4

mytuple(att=(1,2,"/a/"),att2=3)

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

graphparser-0.8.4.tar.gz (26.6 kB view details)

Uploaded Source

Built Distribution

graphparser-0.8.4-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

Details for the file graphparser-0.8.4.tar.gz.

File metadata

  • Download URL: graphparser-0.8.4.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for graphparser-0.8.4.tar.gz
Algorithm Hash digest
SHA256 a64a1777034954a3bd00d1f38e7983f247fd8b011b4752372bfaafd59872d962
MD5 7c83c98c53b2e6132e5606035df27786
BLAKE2b-256 0ce945c1f90fd14b709751c4beb49327b31427148b230674a9314dac1f091c83

See more details on using hashes here.

File details

Details for the file graphparser-0.8.4-py3-none-any.whl.

File metadata

  • Download URL: graphparser-0.8.4-py3-none-any.whl
  • Upload date:
  • Size: 26.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.11

File hashes

Hashes for graphparser-0.8.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a0f64f4bbf86964d2612a158bd8afb2349d8cef31eac13cc6d7cf770c6979a97
MD5 9f775c1df7cb4633801a7e4d83c62f76
BLAKE2b-256 e4986dc8d9e90047f74be66143d74033fb36bb0cc79bc79fbe958f8dd973129a

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