实验四 专家系统

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验四专家系统

一、实验目的

1、掌握专家系统的基本原理和实现方法;

2、构建简单的专家系统。

二、实验内容

构建一简单的动物识别系统。该系统向用户提问该动物是否具有的属性,根据用户的回答,来判断是哪一种动物。该系统可识别albatross(信天翁),penguin(企鹅),ostrich (鸵鸟),zebra(斑马),giraffe(长颈鹿),tiger(老虎),cheetah(印度豹)。

动物属性有:"chew_cud"(反刍),"hooves"(蹄),"mammal"(哺乳动物),"forward_eyes"(目视前方), "claws"(爪),"pointed_teeth"(尖牙,犬齿),"eat_meat","lay_eggs","fly", "feathers","ungulate"(有蹄动物),"carnivore"(食肉动物),"bird","give_milk", "has_hair","fly_well","black&white_color","can_swim","long_legs","long_neck","b lack_stripes"(黑条纹),"dark_spots","tawny_color"(茶色)

下例用C++实现了一个简易的源程序如下:

#include

#include

#include

#include

#define True 1

#define False 0

#define DontKnow -1

char *str[]={"chew_cud","hooves","mammal","forward_eyes",

"claws","pointed_teeth","eat_meat","lay_eggs","fly", "feathers","ungulate","carnivore","bird","give_milk",

"has_hair","fly_well","black&white_color","can_swim",

"long_legs","long_neck","black_stripes","dark_spots",

"tawny_color","albatross","penguin","ostrich","zebra", "giraffe","tiger","cheetah",0};

int rulep[][6]={{22,23,12,3,0,0},{21,23,12,3,0,0},{22,19,20,11,0,0},

{21,11,0,0,0,0},{17,19,20,13,-9,0},{17,18,13,-9,0,0},{16,13,0,0,0,0},

{15,0,0,0,0,0},{14,0,0,0,0,0},{10,0,0,0,0,0},{8,7,0,0,0,0},

{7,0,0,0,0,0},{4,5,6,0,0,0},{2,3,0,0,0,0},{1,3,0,0,0,0}};

int rulec[]={30,29,28,27,26,25,24,3,3,13,13,12,12,11,11,0};

class fact

{private:

int Number;

char Name[21];

int Active;

int Succ;

fact *Next;

fact(int Num,char *L)

{ strcpy(Name,L);

Number=Num;

Active=False; //-1是已经推理,不符合。1是已经推理,符合。 Succ=DontKnow; //0是无,-1是不知道,1是有。

Next=NULL; }

char *GetName()

{ char *L;

L=new char[21];

strcpy(L,Name);

return L; }

int GetNumber()

{ return Number; }

int GetAct()

{ return Active; }

int GetSucc()

{ return Succ; }

void PutAct(const int Act0,int Suc0)

{ Active=Act0;

Succ=Suc0; }

};

fact *Fact;

class list

{ private:

int Number;

public:

list *Next;

list(int Num)

{ Number=Num;

Next=NULL;

}

int GetNumber()

{ return Number; }

};

class rule

{ char *Name;

list *Pre;

int Conc;

rule *Next;

rule(char *N,int P[],int C); ~rule();

int Query();

void GetName()

{ cout<

};

rule::~rule()

{ list *L;

while(Pre)

{ L=Pre->Next;

delete Pre;

Pre=L;

}

delete Name;

}

rule::rule(char *N,int P[],int C) { int i;

list *L;

Pre=NULL;

Next=NULL;

Name=new char[strlen(N)+1];

strcpy(Name,N);

i=0;

while(P[i]!=0)

{ L=new list(P[i++]);

L->Next=Pre;

Pre=L;

Conc=C;

}

int rule::Query()

{ char c;

int Tag=0;

list *L;

fact *F;

F=Fact;

L=Pre;

if(L==NULL)

cout<<"\nError";

while(L!=NULL)

{

相关文档
最新文档