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.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size l_graph-0.2.2-py3-none-any.whl (7.2 kB) | File type Wheel | Python version py3 | Upload date | Hashes View |
Filename, size l-graph-0.2.2.tar.gz (5.4 kB) | File type Source | Python version None | Upload date | Hashes View |