Python 如何根据属性问题区分动物之间的差异
我正在创建一个程序,一个人工智能。事实上,它通过一系列问题来学习动物之间的差异,这些问题将决定动物在头脑中拥有哪些属性。所以我想要的是一种通过选择属性问题来存储动物的方法,例如:Python 如何根据属性问题区分动物之间的差异,python,attributes,artificial-intelligence,Python,Attributes,Artificial Intelligence,我正在创建一个程序,一个人工智能。事实上,它通过一系列问题来学习动物之间的差异,这些问题将决定动物在头脑中拥有哪些属性。所以我想要的是一种通过选择属性问题来存储动物的方法,例如: dog : does it have a wet nose? does it have whiskers? dog : does it have a wet nose? does it have whiskers? cat : does it purr? does it have
dog : does it have a wet nose?
does it have whiskers?
dog : does it have a wet nose?
does it have whiskers?
cat : does it purr?
does it have whiskers?
for each question:
for each word in question :
if word in attributes:
attributesFound.append(word)
animal=set(dic[attributesFound[0]])
for each attribute in attributesFound:
animal=animal.intersection(dict[attribute ])
所有这些回答“是”的问题都是狗的属性……有什么想法吗?还要记住,有些动物具有相同的属性,例如:
dog : does it have a wet nose?
does it have whiskers?
dog : does it have a wet nose?
does it have whiskers?
cat : does it purr?
does it have whiskers?
for each question:
for each word in question :
if word in attributes:
attributesFound.append(word)
animal=set(dic[attributesFound[0]])
for each attribute in attributesFound:
animal=animal.intersection(dict[attribute ])
因此,我希望程序能够提出多个问题,并确定哪种动物是哪种动物。我认为您可以使用a来完成这项任务,您可以使用它根据动物的属性对动物进行分类,也可能有助于查看,它将帮助您确定进行分类的最佳属性。您可以做的最简单的事情是使用字典,它将保持属性与具有该属性的动物列表之间的关系,例如:
attributes=[bite,scratch,purr,whiskers,...]
dic={
whiskers:[cat,dog]
purr:[cat]
scratch:[cat]
bite:[cat,dog,rat]}
dose it scratch
根据您的问题格式,例如:
dog : does it have a wet nose?
does it have whiskers?
dog : does it have a wet nose?
does it have whiskers?
cat : does it purr?
does it have whiskers?
for each question:
for each word in question :
if word in attributes:
attributesFound.append(word)
animal=set(dic[attributesFound[0]])
for each attribute in attributesFound:
animal=animal.intersection(dict[attribute ])
说我们有这个案子
does it purr?
does it have whiskers?
找到的属性将是[purr,whiskers],animal将是[cat,dog],然后我们进入for each属性循环
for each attribute in [cat,dog] :
animal=set(animal.intersection(dict[attribute ]))//in the first iteration animal would still be [cat,dog].
//然而,在第二次迭代中,集合([cat,dog]交集([cat])只会留下一个集合,其中只有一个元素是cat