-
大小: 3KB文件類(lèi)型: .rar金幣: 2下載: 0 次發(fā)布日期: 2021-05-07
- 語(yǔ)言: Python
- 標(biāo)簽: Python??動(dòng)物識(shí)別??
資源簡(jiǎn)介
Python實(shí)現(xiàn)動(dòng)物識(shí)別產(chǎn)生式系統(tǒng),適合初學(xué)機(jī)器學(xué)習(xí)者,有應(yīng)該更正的地方,歡迎指正

代碼片段和文件信息
#?-*-?coding:?utf-8?-*-
“““
Created?on?Sun?Dec?24?15:13:13?2017
@author:?user
“““
import?numpy?as?np
class?productionSystem:
????def?__init__(self):
????????f=open(“productions.txt““r“)
????????self.productions=[]
????????self.charicters=[]
????????self.myclass=(f.readline().strip(“最終類(lèi)別為:“).strip()).split(“,“)
????????for?line?in?f.readlines():
????????????if(line!=‘\n‘):
????????????????line=line.replace(“->““?“)
????????????????line=line.replace(“““?“)
????????????????line=line.split()
????????????????self.productions.append(line)
????????????????for?ch?in?line:
????????????????????if?(ch?not?in?self.myclass)?and?(ch?not?in?self.charicters):
????????????????????????self.charicters.append(ch)
????def?showProduction(self):
????????print()
????def?match(selfx):
????????for?ch?in?self.productions[x][:-1]:
????????????if(ch?in?self.work):
????????????????continue
????????????else:
????????????????return?False
????????return?True
????def?classify(selfwork):
????????used=np.zeros(len(self.productions))
????????counter=len(self.work)
????????while(True):
????????????for?i?in?range(len(self.productions)):
????????????????if(used[i]==0?and?self.match(i)):
????????????????????used[i]=1
????????????????????self.work.append(self.productions[i][-1])
????????????????????if(self.work[-1]?in?self.myclass):
????????????????????????return?True
????????????tmp=len(self.work)
????????????if(tmp==counter):
????????????????return?False
????????????else:
????????????????counter=tmp
????def?dowork(self):
????????print(“所有類(lèi)別有:“)
????????for?t?in?self.myclass:
????????????print(‘{:<10}‘.format(t)end=““)
????????print()
????????print(“所有屬性有:“)
????????counter=0
????????for?t?in?self.charicters:
????????????counter+=1
????????????if(counter%5==0):
????????????????print(‘{:<10}‘.format(t))
????????????else:
????????????????print(‘{:<10}‘.format(t)end=‘‘)
????????self.work=input(“\n請(qǐng)輸入屬性\n----屬性之間用空格隔開(kāi)----\n“)
????????self.work=self.work.split()
????????if(self.classify(self.work)):
????????????print(“該物種為:“+self.work[-1])
????????else:
????????????print(“抱歉,未能識(shí)別出該物種\n“)
def?main():
????p=productionSystem()
????p.dowork()
????
if?__name__==“__main__“:
????main()
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件????????429??2017-12-24?16:24??ProductionSystem\productions.txt
?????文件???????2346??2017-12-24?19:35??ProductionSystem\production_system.py
?????文件???????2225??2017-12-24?18:56??ProductionSystem\__pycache__\production_system.cpython-36.pyc
?????目錄??????????0??2017-12-24?18:56??ProductionSystem\__pycache__
?????目錄??????????0??2017-12-24?17:15??ProductionSystem
-----------?---------??----------?-----??----
?????????????????5000????????????????????5
評(píng)論
共有 條評(píng)論