动物识别专家系统上机报告含源代码 第2页

int rule::Query()

       {

              int i;

              char c;

              int Tag=0;

              list *L;

              fact *F;

              F=Fact;

              L=Pre;

              if(L==NULL)

                     cout<<"\nError";

              while(L!=NUll)

              {

                     F=Fact;

                     for(;;)

                     {

                            if(abs(L->GetNumber())==F->GetNumber())

                                   break;

                            F=F->Next;   //查找与规则前提链中前提号相同的事实

                     }

                     if(L->GetNumber()>0)

                            {

                                   if((F->GetSucc())==true) {L=L->Next;continue;}

                                   if((F->GetSucc())==false) return false;

                            }   //如果事实的断言为真则判断下一个前提,为假,则表示该规则不适合

                     else

                            {

                                   if((F->GetSucc())==true) return false;

                                   if((F->GetSucc())==false) {L=L->Next;continue;}

                            }

                     cout<<endl<<F->GetName()<<"(Y/N)";

                     c=getchar();    //事实断言为不知道的时候,向用户询问

                     flushall();

                     if((c=='Y')||(c=='y'))

                            {

                                   if(L->GetNumber()>0)

                                          F->PutAct(1,true);  //设置事实的断言和激活标志

                                   if(L->GetNumber()<0)

                                          {

                                                 F->PutAct(1,true);

                                                 Tag=-1;

                                                 return false;

                                          }

                            }

                     else

                            {

                                   if(L->GetNumber()<0)

                                          F->PutAct(-1,false);

                                   else

                                          {

                                                 F->PutAct(-1,false);

                                                 Tag=-1;

                                                 return false;

                                          }

                            }

                            L=L->Next;

              }

              F=Fact;

              for(;;)

              {

                     if(Conc==F->GetNumber()) break;   //查找结论断言对应的事实

                     F=F->Next;

              }

              if(Conc<24)

                     {

                            F->PutAct(1,true);

                            return false;

                     }

              if(Tag!=-1)

                     {

                            F=Fact;

                            for(;;)

                            {

                                   if(Conc==F->GetNumber()) break;

                                   F=F->Next;

                            }

                            if(Conc<24)

                                   {

                                          F->PutAct(1,true);

                                          return false;

                                   }

                            cout<<"\nThis animal is"<<F->GetName();

                            return true;

                     }

              return false;

       };

上一页  [1] [2] [3] 下一页

Copyright © 2007-2012 www.chuibin.com 六维论文网 版权所有