Python module for working with L-graphs
Project description
lgraph
Python module for working with L-graphs.
Installation
pip install l-graph
Creating an L-graph
from lgraph import LGraph
lg = LGraph(3)
lg.add_edge(lg.initial_main.name, '1')
lg.add_edge('1', '2', label='b', round_trace=')', square_trace='[')
lg.add_edge('2', '3', label='c', square_trace=']')
lg.add_edge('3', lg.final_main.name)
lg.add_edge('1', '1', label='a', round_trace='(')
lg.add_edge('2', '2', label='b', round_trace=')', square_trace='[')
lg.add_edge('3', '3', label='c', square_trace=']')
Saving and loading L-graphs
lg.save('graph_examples/a^n_b^n_c^n')
lg.load('graph_examples/a^n_b^n')
Cheking if string is in the language of the L-graph
lg = LGraph()
lg.load('graph_examples/a^n_b^n_c^n')
'abc' in lg
>>> True
'abccc' in lg
>>> False
# Finding path of the string
path = lg.find_successful_path('abc')
LGraph.path_to_string(path)
>>> initial_main---->1--a-->1--b-->2--c-->3---->final_main
Type definition of the L-graph
L-graph types defined in LGraph.LGraphType
class LGraphType(Enum):
RECURSIVELY_ENUMERABLE = 0
CONTEXT_SENSITIVE = 1
CONTEXT_FREE = 2
REGULAR = 3
To define type of the L-graph use:
lg.type
To check properties of L-graph use:
lg.is_regular()
lg.is_context_free()
lg.is_context_sensitive()
Opeartions
Left:
Right:
lg_left, lg_right = LGraph(), LGraph()
lg_left.load('graph_examples/left')
lg_right.load('graph_examples/right')
Concatenation
lg = lg_left * lg_right
lg.save('graph_examples/concatenate_result')
Union
lg = lg_left + lg_right
lg.save('graph_examples/union_result')
Shorter version is also available:
lg_left *= lg_right
lg_left += lg_right
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
l-graph-0.2.2.tar.gz
(5.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file l-graph-0.2.2.tar.gz.
File metadata
- Download URL: l-graph-0.2.2.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ede1ba6d0a602e7f933dbb753a508eb900db6feea3a9d21adf2c471bc4d1082f
|
|
| MD5 |
7a864dbb7543007e80037391e41d4a5e
|
|
| BLAKE2b-256 |
1883fd7938e19d971a00fb1ec0420b52ee29fb207631eb600043a38778d24094
|
File details
Details for the file l_graph-0.2.2-py3-none-any.whl.
File metadata
- Download URL: l_graph-0.2.2-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a71b710b1b1a46d897700f6822dc16bc6be0c8c44faf85753113d5b73419d44
|
|
| MD5 |
ab26b2bff09b86c0cd9ba136c201e5e2
|
|
| BLAKE2b-256 |
c9c4b18f00bcd00c50ee0a8844e9701609f4c575ba2718b5ce257697f46416d6
|