资源简介
python实现正规式转换成NFA、NFA转换成DFA、DFA转换成MFA算法,并实现画出三类形图,可以在用户图形界面显示,也可以在文件夹中显示。
代码片段和文件信息
#-*-coding:utf-8 -*-
from os import popen
import time
class Automata:
“““自动机类“““
def __init__(self language = set([‘0‘ ‘1‘])):
#五元组:状态集,开始状态,结束状态集,转化集,语言表(默认0,1)
self.states = set()
self.startstate = None
self.finalstates = []
self.transitions = dict()
self.language = language
@staticmethod
def epsilon():
return “:e:“
def setstartstate(self state):
self.startstate = state
self.states.add(state)
def addfinalstates(self state):
if isinstance(state int):
state = [state]
for s in state:
if s not in self.finalstates:
self.finalstates.append(s)
def addtransition(self fromstate tostate inp):
if isinstance(inp str):
inp = set([inp])
self.states.add(fromstate)
self.states.add(tostate)
if fromstate in self.transitions:
if tostate in self.transitions[fromstate]:
self.transitions[fromstate][tostate] = self.transitions[fromstate][tostate].union(inp)
else:
self.transitions[fromstate][tostate] = inp
else:
self.transitions[fromstate] = {tostate : inp}
def addtransition_dict(self transitions):
for fromstate tostates in transitions.items():
for state in tostates:
self.addtransition(fromstate state tostates[state])
def gettransitions(self state key):
if isinstance(state int):
state = [state]
trstates = set()
for st in state:
if st in self.transitions:
for tns in self.transitions[st]:
if key in self.transitions[st][tns]:
trstates.add(tns)
return trstates
def getEClose(self findstate):
allstates = set()
states = set([findstate])
while len(states)!= 0:
state = states.pop()
allstates.add(state)
if state in self.transitions:
for tns in self.transitions[state]:
if Automata.epsilon() in self.transitions[state][tns] and tns not in allstates:
states.add(tns)
return allstates
def display(self):
print “states:“ self.states
print “start state: “ self.startstate
print “final states:“ self.finalstates
print “transitions:“
for fromstate tostates in self.transitions.items():
for state in tostates:
for char in tostates[state]:
print “ “fromstate “->“ state “on ‘“+char+“‘“
print
def getPrintText(self):
text = “language: {“ + “ “.join(self.language) + “}\n“
text += “states: {“ + “ “.join(map(strself.states)) + “}\n“
text += “start state: “ + str(self.startstate) + “\n“
text += “final states: {“ + “ “.join(map(strself.finalstates)) + “}\n“
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-11-21 18:24 automata-from-regex-master\
目录 0 2013-04-08 11:04 automata-from-regex-master\screenshots\
文件 72950 2013-04-08 11:04 automata-from-regex-master\screenshots\screenshot_DFA.png
目录 0 2017-11-26 11:19 __MACOSX\
目录 0 2017-11-26 11:19 __MACOSX\automata-from-regex-master\
目录 0 2017-11-26 11:19 __MACOSX\automata-from-regex-master\screenshots\
文件 212 2013-04-08 11:04 __MACOSX\automata-from-regex-master\screenshots\._screenshot_DFA.png
文件 81494 2013-04-08 11:04 automata-from-regex-master\screenshots\screenshot_NFA.png
文件 212 2013-04-08 11:04 __MACOSX\automata-from-regex-master\screenshots\._screenshot_NFA.png
文件 56031 2013-04-08 11:04 automata-from-regex-master\screenshots\screenshot_minDFA.png
文件 212 2013-04-08 11:04 __MACOSX\automata-from-regex-master\screenshots\._screenshot_minDFA.png
文件 65959 2013-04-08 11:04 automata-from-regex-master\screenshots\screenshot_mainWindow.png
文件 212 2013-04-08 11:04 __MACOSX\automata-from-regex-master\screenshots\._screenshot_mainWindow.png
文件 212 2013-04-08 11:04 __MACOSX\automata-from-regex-master\._screenshots
文件 5977 2017-11-21 19:13 automata-from-regex-master\graphmdfa.png
文件 19178 2017-11-21 20:01 automata-from-regex-master\AutomataTheory.py
文件 212 2017-11-21 20:01 __MACOSX\automata-from-regex-master\._AutomataTheory.py
文件 14195 2017-11-21 19:13 automata-from-regex-master\graphdfa.png
文件 2007 2013-04-08 11:04 automata-from-regex-master\README.md
文件 212 2013-04-08 11:04 __MACOSX\automata-from-regex-master\._README.md
文件 1000 2017-11-21 20:01 automata-from-regex-master\cli.py
文件 212 2017-11-21 20:01 __MACOSX\automata-from-regex-master\._cli.py
文件 12 2013-04-08 11:04 automata-from-regex-master\.gitignore
文件 212 2013-04-08 11:04 __MACOSX\automata-from-regex-master\._.gitignore
文件 33772 2017-11-21 19:13 automata-from-regex-master\graphnfa.png
文件 17382 2017-11-21 18:24 automata-from-regex-master\AutomataTheory.pyc
目录 0 2013-04-08 11:04 automata-from-regex-master\graphs\
文件 18541 2013-04-08 11:04 automata-from-regex-master\graphs\graph_DFA.png
目录 0 2017-11-26 11:19 __MACOSX\automata-from-regex-master\graphs\
文件 212 2013-04-08 11:04 __MACOSX\automata-from-regex-master\graphs\._graph_DFA.png
文件 6285 2013-04-08 11:04 automata-from-regex-master\graphs\graph_minDFA.png
............此处省略9个文件信息
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- 图标连连看--js版连连看
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 电脑端微信图片dat转化
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
评论
共有 条评论