⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 factmngr.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 4 页
字号:
   while (FactList != NULL)     { Retract((VOID *) FactList); }  }/*********************************************//* CreateFact: Creates a fact data structure *//*   of the specified deftemplate.           *//*********************************************/globle struct fact *CreateFact(vTheDeftemplate)  VOID *vTheDeftemplate;  {   struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate;   struct fact *newFact;   int i;      /*=================================*/   /* A deftemplate must be specified */   /* in order to create a fact.      */   /*=================================*/      if (theDeftemplate == NULL) return(NULL);      /*============================================*/   /* Create a fact for an explicit deftemplate. */   /*============================================*/      if (theDeftemplate->implied == CLIPS_FALSE)      {       newFact = CreateFactBySize((int) theDeftemplate->numberOfSlots);      for (i = 0;           i < (int) theDeftemplate->numberOfSlots;           i++)        { newFact->theProposition.theFields[i].type = RVOID; }     }        /*===========================================*/   /* Create a fact for an implied deftemplate. */   /*===========================================*/   else      {      newFact = CreateFactBySize(1);      newFact->theProposition.theFields[0].type = MULTIFIELD;      newFact->theProposition.theFields[0].value = CreateMultifield2(0L);     }      /*===============================*/   /* Return a pointer to the fact. */   /*===============================*/      newFact->whichDeftemplate = theDeftemplate;      return(newFact);  }  /********************************************//* GetFactSlot: Returns the slot value from *//*   the specified slot of a fact.          *//********************************************/globle BOOLEAN GetFactSlot(vTheFact,slotName,theValue)  VOID *vTheFact;  char *slotName;  DATA_OBJECT *theValue;  {   struct fact *theFact = (struct fact *) vTheFact;   struct deftemplate *theDeftemplate;   int whichSlot;      /*===============================================*/   /* Get the deftemplate associated with the fact. */   /*===============================================*/      theDeftemplate = theFact->whichDeftemplate;      /*==============================================*/   /* Handle retrieving the slot value from a fact */   /* having an implied deftemplate. An implied    */   /* facts has a single multifield slot.          */   /*==============================================*/      if (theDeftemplate->implied)      {      if (slotName != NULL) return(CLIPS_FALSE);      theValue->type = theFact->theProposition.theFields[0].type;       theValue->value = theFact->theProposition.theFields[0].value;      SetpDOBegin(theValue,1);      SetpDOEnd(theValue,((struct multifield *) theValue->value)->multifieldLength);      return(CLIPS_TRUE);      }       /*===================================*/   /* Make sure the slot name requested */   /* corresponds to a valid slot name. */   /*===================================*/              if (FindSlot(theDeftemplate,AddSymbol(slotName),&whichSlot) == NULL)      { return(CLIPS_FALSE); }      /*======================================================*/   /* Return the slot value. If the slot value wasn't set, */   /* then return FALSE to indicate that an appropriate    */   /* slot value wasn't available.                         */   /*======================================================*/      theValue->type = theFact->theProposition.theFields[whichSlot-1].type;    theValue->value = theFact->theProposition.theFields[whichSlot-1].value;   if (theValue->type == MULTIFIELD)     {      SetpDOBegin(theValue,1);      SetpDOEnd(theValue,((struct multifield *) theValue->value)->multifieldLength);     }      if (theValue->type == RVOID) return(CLIPS_FALSE);      return(CLIPS_TRUE);  }  /***************************************//* PutFactSlot: Sets the slot value of *//*   the specified slot of a fact.     *//***************************************/globle BOOLEAN PutFactSlot(vTheFact,slotName,theValue)  VOID *vTheFact;  char *slotName;  DATA_OBJECT *theValue;  {   struct fact *theFact = (struct fact *) vTheFact;   struct deftemplate *theDeftemplate;   struct templateSlot *theSlot;   int whichSlot;      /*===============================================*/   /* Get the deftemplate associated with the fact. */   /*===============================================*/      theDeftemplate = theFact->whichDeftemplate;      /*============================================*/   /* Handle setting the slot value of a fact    */   /* having an implied deftemplate. An implied  */   /* facts has a single multifield slot.        */   /*============================================*/      if (theDeftemplate->implied)     {      if ((slotName != NULL) || (theValue->type != MULTIFIELD))        { return(CLIPS_FALSE); }              if (theFact->theProposition.theFields[0].type == MULTIFIELD)        { ReturnMultifield(theFact->theProposition.theFields[0].value); }              theFact->theProposition.theFields[0].type = (short) theValue->type;       theFact->theProposition.theFields[0].value = DOToMultifield(theValue);            return(CLIPS_TRUE);      }       /*===================================*/   /* Make sure the slot name requested */   /* corresponds to a valid slot name. */   /*===================================*/              if ((theSlot = FindSlot(theDeftemplate,AddSymbol(slotName),&whichSlot)) == NULL)      { return(CLIPS_FALSE); }        /*=============================================*/   /* Make sure a single field value is not being */   /* stored in a multifield slot or vice versa.  */   /*=============================================*/      if (((theSlot->multislot == 0) && (theValue->type == MULTIFIELD)) ||       ((theSlot->multislot == 1) && (theValue->type != MULTIFIELD)))     { return(CLIPS_FALSE); }      /*=====================*/   /* Set the slot value. */   /*=====================*/      if (theFact->theProposition.theFields[whichSlot-1].type == MULTIFIELD)     { ReturnMultifield(theFact->theProposition.theFields[whichSlot-1].value); }        theFact->theProposition.theFields[whichSlot-1].type = (short) theValue->type;       if (theValue->type == MULTIFIELD)     { theFact->theProposition.theFields[whichSlot-1].value = DOToMultifield(theValue); }   else     { theFact->theProposition.theFields[whichSlot-1].value = theValue->value; }      return(CLIPS_TRUE);  }  /********************************************************//* AssignFactSlotDefaults: Sets a fact's slot values to *//*   its default value if the value of the slot has not *//*   yet been set.                                      *//********************************************************/globle BOOLEAN AssignFactSlotDefaults(vTheFact)  VOID *vTheFact;  {   struct fact *theFact = (struct fact *) vTheFact;   struct deftemplate *theDeftemplate;   struct templateSlot *slotPtr;     int i;   DATA_OBJECT theResult;      /*===============================================*/   /* Get the deftemplate associated with the fact. */   /*===============================================*/      theDeftemplate = theFact->whichDeftemplate;      /*================================================*/   /* The value for the implied multifield slot of   */   /* an implied deftemplate is set to a multifield  */   /* of length zero when the fact is created.       */   /*================================================*/               if (theDeftemplate->implied) return(CLIPS_TRUE);      /*============================================*/   /* Loop through each slot of the deftemplate. */   /*============================================*/      for (i = 0, slotPtr = theDeftemplate->slotList;         i < (int) theDeftemplate->numberOfSlots;         i++, slotPtr = slotPtr->next)     {      /*===================================*/      /* If the slot's value has been set, */      /* then move on to the next slot.    */      /*===================================*/            if (theFact->theProposition.theFields[i].type != RVOID) continue;      /*===============================================*/      /* If the (default ?NONE) attribute was declared */      /* for the slot, then return FALSE to indicate   */      /* the default values for the fact couldn't be   */      /* supplied since this attribute requires that a */      /* default value can't be used for the slot.     */      /*===============================================*/            if (slotPtr->noDefault) return(CLIPS_FALSE);            /*==============================================*/      /* Otherwise if a static default was specified, */      /* use this as the default value.               */      /*==============================================*/      else if (slotPtr->defaultPresent)        {         if (slotPtr->multislot)           {            StoreInMultifield(&theResult,slotPtr->defaultList,CLIPS_TRUE);            theFact->theProposition.theFields[i].value = DOToMultifield(&theResult);           }         else           {           theFact->theProposition.theFields[i].type = slotPtr->defaultList->type;           theFact->theProposition.theFields[i].value = slotPtr->defaultList->value;          }        }             /*================================================*/      /* Otherwise if a dynamic-default was specified,  */      /* evaluate it and use this as the default value. */      /*================================================*/      else if (slotPtr->defaultDynamic)        {         EvaluateExpression(slotPtr->defaultList,&theResult);         if (EvaluationError) return(CLIPS_FALSE);         theFact->theProposition.theFields[i].type = (short) theResult.type;         if (theResult.type == MULTIFIELD)           { theFact->theProposition.theFields[i].value = DOToMultifield(&theResult); }         else           { theFact->theProposition.theFields[i].value = theResult.value; }        }              /*====================================*/      /* Otherwise derive the default value */      /* from the slot's constraints.       */      /*====================================*/            else         {         DeriveDefaultFromConstraints(slotPtr->constraints,&theResult,                                     (int) slotPtr->multislot);                                                     theFact->theProposition.theFields[i].type = (short) theResult.type;         if (theResult.type == MULTIFIELD)           { theFact->theProposition.theFields[i].value = DOToMultifield(&theResult); }         else           { theFact->theProposition.theFields[i].value = theResult.value; }        }     }      /*==========================================*/   /* Return TRUE to indicate that the default */   /* values have been successfully set.       */   /*==========================================*/      return(CLIPS_TRUE);  } /***************************************************************//* CopyFactSlotValues: Copies the slot values from one fact to *//*   another. Both facts must have the same relation name.     *//***************************************************************/globle BOOLEAN CopyFactSlotValues(vTheDestFact,vTheSourceFact)  VOID *vTheDestFact;  VOID *vTheSourceFact;  {   struct fact *theDestFact = (struct fact *) vTheDestFact;   struct fact *theSourceFact = (struct fact *) vTheSourceFact;   struct deftemplate *theDeftemplate;   struct templateSlot *slotPtr;     int i;      /*===================================*/   /* Both facts must be the same type. */   /*===================================*/      theDeftemplate = theSourceFact->whichDeftemplate;   if (theDestFact->whichDeftemplate != theDeftemplate)     { return(CLIPS_FALSE); }         /*===================================================*/   /* Loop through each slot of the deftemplate copying */   /* the source fact value to the destination fact.    */   /*===================================================*/      for (i = 0, slotPtr = theDeftemplate->slotList;         i < (int) theDeftemplate->numberOfSlots;         i++, slotPtr = slotPtr->next)     {      theDestFact->theProposition.theFields[i].type =         theSourceFact->theProposition.theFields[i].type;      if (theSourceFact->theProposition.theFields[i].type != MULTIFIELD)        {         theDestFact->theProposition.theFields[i].value =           theSourceFact->theProposition.theFields[i].value;        }      else        {         theDestFact->theProposition.theFields[i].value =           CopyMultifield(theSourceFact->theProposition.theFields[i].value);        }     }      /*========================================*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -