动物识别专家系统
猪脑过载了已经,救命!
要求:
设计一个动物识别专家系统,规则库至少包含15条规则,可以识别至少7种动物,规则可增加;
界面显示要求:
1)有若干选择动物特征的选择列表;
2)表现判断动物时,使用了哪些规则;
3)表现数据库的变化;
4)显示规则的调用次序;
5)显示最后的结果,包含动物能识别出来和动物不能识别出来两种情况;
6)用C语言写
7)注释清楚
8)事实和规则从文本文件里面读取:
事实:
规则:
这里附上文本内容:
ProduceMilk
HaveFeathers
Fly
LayEggs
EatMeat
HaveSharpTeeth
HaveClaws
HaveForwardEyes
HaveHoofs
ChewAndRuminate
HaveFur
HaveTownyFur
HaveBlackpot
HaveBlackStripe
HaveLongNeck
HaveLongLegs
BlackAndWhite
CanSwim
GoodAtFlying
Mammal
Bird
Carnivore
Ungulate
AnimalsWithEvenToes
AfricanCheetah
Tiger
Giraffe
Zebra
Ostrich
penguin
Albatross
if HaveFeathers then Mammals
if ProduceMilk then Mammals
if HaveFur then Birds
if Fly and LayEggs then Birds
if EatMeat then Carnivore
if HaveShapeTeeth and HaveClaws and HaveForwardEyes then Carnivore
if Mammal and HaveHoofs then Ungulate
if Mammal and ChewAndRuminate then Mammal and AnimalsWithEvenToes
if Mammal and Carnivore and HaveTownyFur and HaveBlackpot then AfricanCheetah
if Mammal and Carnivore and HaveTownyFur and HaveBlackStripe then Tiger
目前自己写了个开头,感觉已经猪脑过载了:
#define _CRT_SECURE_NO_WARNINGS
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#define MAXSIZE 50
typedef struct RULE
{
int ifs;
int result;
}rule;
rule rules[MAXSIZE];
int rulesLength = 0;
char facts[MAXSIZE][20];
int factsLength = 0;
void factsAdd()
{
char newrule[20];
printf("please input a fact name:");
scanf("%s", newrule);
strcpy(facts[factsLength], newrule);
factsLength++;
}
void FillText(FILE* fp, char text[])
{
char ch;
int length = 0;
ch = fgetc(fp);
while (ch != EOF)
{
text[length] = ch;
ch = fgetc(fp);
length++;
}
text[length] = '\0';
}
void factsBuild(char str[])
{
int p = 0, j;
while (str[p] != '\0')
{
j = 0;
while (str[p] != '\n')
{
facts[factsLength][j] = str[p];
p++;
j++;
}
facts[factsLength][j] = '\0';
factsLength++;
printf("%d\t", factsLength);
p++;
}
}
int main()
{
char str[1000];
FILE* fp;
fp = fopen("facts.txt", "r");
FillText(fp, str);
factsBuild(str);
return 0;
}