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

📄 factgen.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 4 页
字号:
/*******************************************************//* FactGenGetfield: Generates an expression for use in *//*   the fact pattern network that retrieves a value   *//*   from a single or multifield slot.                 *//*******************************************************/globle struct expr *FactGenGetfield(theNode)  struct lhsParseNode *theNode;  {   /*===================================================*/   /* Generate call to retrieve single field slot value */   /* or the fact relation name.                        */   /*===================================================*/      if ((theNode->slotNumber > 0) && (theNode->withinMultifieldSlot == CLIPS_FALSE))     { return(GenConstant(FACT_PN_VAR2,FactGetVarPN2(theNode))); }      /*=====================================================*/   /* Generate call to retrieve a value from a multifield */   /* slot that contains at most one multifield variable  */   /* or contains no multifield variables before the      */   /* value to be retrieved.                              */   /*=====================================================*/        if (((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE)) &&       ((theNode->multiFieldsBefore == 0) ||        ((theNode->multiFieldsBefore == 1) && (theNode->multiFieldsAfter == 0))))      { return(GenConstant(FACT_PN_VAR3,FactGetVarPN3(theNode))); }      if (((theNode->type == MF_WILDCARD) || (theNode->type == MF_VARIABLE)) &&       (theNode->multiFieldsBefore == 0) && (theNode->multiFieldsAfter == 0))     { return(GenConstant(FACT_PN_VAR3,FactGetVarPN3(theNode))); }        /*=========================================*/   /* Generate call to retrieve a value using */   /* the most general retrieval function.    */   /*=========================================*/      return(GenConstant(FACT_PN_VAR1,FactGetVarPN1(theNode)));  }/**************************************************//* FactGenGetvar: Generates an expression for use *//*   in the join network that retrieves a value   *//*   from a single or multifield slot of a fact.  *//**************************************************/globle struct expr *FactGenGetvar(theNode)  struct lhsParseNode *theNode;  {   /*====================================================*/   /* Generate call to retrieve single field slot value. */   /*====================================================*/      if ((theNode->slotNumber > 0) && (theNode->withinMultifieldSlot == CLIPS_FALSE))     { return(GenConstant(FACT_JN_VAR2,FactGetVarJN2(theNode))); }        /*=====================================================*/   /* Generate call to retrieve a value from a multifield */   /* slot that contains at most one multifield variable  */   /* or contains no multifield variables before the      */   /* value to be retrieved.                              */   /*=====================================================*/        if (((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE)) &&       ((theNode->multiFieldsBefore == 0) ||        ((theNode->multiFieldsBefore == 1) && (theNode->multiFieldsAfter == 0))))      { return(GenConstant(FACT_JN_VAR3,FactGetVarJN3(theNode))); }      if (((theNode->type == MF_WILDCARD) || (theNode->type == MF_VARIABLE)) &&       (theNode->multiFieldsBefore == 0) &&        (theNode->multiFieldsAfter == 0))     { return(GenConstant(FACT_JN_VAR3,FactGetVarJN3(theNode))); }      /*=========================================*/   /* Generate call to retrieve a value using */   /* the most general retrieval function.    */   /*=========================================*/      return(GenConstant(FACT_JN_VAR1,FactGetVarJN1(theNode)));  }  /**************************************************************//* FactGenCheckLength: Generates an expression for use in the *//*   fact pattern network that determines if the value of a   *//*   multifield slot contains enough fields to satisfy the    *//*   number of pattern matching constaints. For example, the  *//*   slot constraints (foo ?x a $? ?y) couldn't be matched    *//*   unless the foo slot contained at least 3 fields.         *//**************************************************************/globle struct expr *FactGenCheckLength(theNode)  struct lhsParseNode *theNode;  {   struct factCheckLengthPNCall hack;             /*===================================================*/   /* If the slot contains no single field constraints, */   /* then a length test is not necessary.              */   /*===================================================*/      if ((theNode->singleFieldsAfter == 0) &&        (theNode->type != SF_VARIABLE) &&        (theNode->type != SF_WILDCARD))     { return(NULL); }      /*=======================================*/   /* Initialize the length test arguments. */   /*=======================================*/      ClearBitString(&hack,sizeof(struct factCheckLengthPNCall));   hack.whichSlot = theNode->slotNumber - 1;      /*============================================*/   /* If the slot has no multifield constraints, */   /* then the length must match exactly.        */   /*============================================*/      if ((theNode->type != MF_VARIABLE) &&       (theNode->type != MF_WILDCARD) &&       (theNode->multiFieldsAfter == 0))     { hack.exactly = 1; }   else     { hack.exactly = 0; }        /*============================================*/   /* The minimum length is the number of single */   /* field constraints contained in the slot.   */   /*============================================*/      if ((theNode->type == SF_VARIABLE) || (theNode->type == SF_WILDCARD))     { hack.minLength = 1 + theNode->singleFieldsAfter; }   else     { hack.minLength = theNode->singleFieldsAfter; }      /*========================================================*/   /* Generate call to test the length of a multifield slot. */   /*========================================================*/   return(GenConstant(FACT_SLOT_LENGTH,AddBitMap(&hack,sizeof(struct factCheckLengthPNCall))));  }/**************************************************************//* FactGenCheckZeroLength: Generates an expression for use in *//*   the fact pattern network that determines if the value of *//*   a multifield slot is a zero length multifield value.     *//**************************************************************/globle struct expr *FactGenCheckZeroLength(theSlot)  int theSlot;  {   struct factCheckLengthPNCall hack;        ClearBitString(&hack,sizeof(struct factCheckLengthPNCall));      hack.whichSlot = theSlot-1;   hack.exactly = 1;   hack.minLength = 0;      return(GenConstant(FACT_SLOT_LENGTH,AddBitMap(&hack,sizeof(struct factCheckLengthPNCall))));  }   /*********************************************************************//* FactReplaceGetvar: Replaces a variable reference in an expression *//*   with a function call to retrieve the variable using the join    *//*   network variable access functions for facts.                    *//*********************************************************************/globle VOID FactReplaceGetvar(theItem,theNode)  struct expr *theItem;  struct lhsParseNode *theNode;  {   /*====================================================*/   /* Generate call to retrieve single field slot value. */   /*====================================================*/   if ((theNode->slotNumber > 0) && (theNode->withinMultifieldSlot == CLIPS_FALSE))     {      theItem->type = FACT_JN_VAR2;      theItem->value = FactGetVarJN2(theNode);      return;     }      /*=====================================================*/   /* Generate call to retrieve a value from a multifield */   /* slot that contains at most one multifield variable  */   /* or contains no multifield variables before the      */   /* value to be retrieved.                              */   /*=====================================================*/   if (((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE)) &&       ((theNode->multiFieldsBefore == 0) ||        ((theNode->multiFieldsBefore == 1) && (theNode->multiFieldsAfter == 0))))      {      theItem->type = FACT_JN_VAR3;      theItem->value = FactGetVarJN3(theNode);      return;     }      if (((theNode->type == MF_WILDCARD) || (theNode->type == MF_VARIABLE)) &&       (theNode->multiFieldsBefore == 0) &&        (theNode->multiFieldsAfter == 0))     {       theItem->type = FACT_JN_VAR3;      theItem->value = FactGetVarJN3(theNode);      return;     }      /*=========================================*/   /* Generate call to retrieve a value using */   /* the most general retrieval function.    */   /*=========================================*/   theItem->type = FACT_JN_VAR1;   theItem->value = FactGetVarJN1(theNode);  }  /***********************************************************************//* FactReplaceGetfield: Replaces a variable reference in an expression *//*   with a function call to retrieve the variable using the pattern   *//*   network variable access functions for facts.                      *//***********************************************************************/globle VOID FactReplaceGetfield(theItem,theNode)  struct expr *theItem;  struct lhsParseNode *theNode;  {   /*====================================================*/   /* Generate call to retrieve single field slot value. */   /*====================================================*/   if (theNode->withinMultifieldSlot == CLIPS_FALSE)     {      theItem->type = FACT_PN_VAR2;      theItem->value = FactGetVarPN2(theNode);      return;     }      /*=====================================================*/   /* Generate call to retrieve a value from a multifield */   /* slot that contains at most one multifield variable  */   /* or contains no multifield variables before the      */   /* value to be retrieved.                              */   /*=====================================================*/   if (((theNode->type == SF_WILDCARD) || (theNode->type == SF_VARIABLE)) &&       ((theNode->multiFieldsBefore == 0) ||        ((theNode->multiFieldsBefore == 1) && (theNode->multiFieldsAfter == 0))))      {      theItem->type = FACT_PN_VAR3;      theItem->value = FactGetVarPN3(theNode);      return;     }      if (((theNode->type == MF_WILDCARD) || (theNode->type == MF_VARIABLE)) &&       (theNode->multiFieldsBefore == 0) &&        (theNode->multiFieldsAfter == 0))     {       theItem->type = FACT_PN_VAR3;      theItem->value = FactGetVarPN3(theNode);      return;     }      /*=========================================*/   /* Generate call to retrieve a value using */   /* the most general retrieval function.    */   /*=========================================*/   theItem->type = FACT_PN_VAR1;   theItem->value = FactGetVarPN1(theNode);  }/*************************************************************//* FactGetVarJN1: Creates the arguments for the most general *//*   routine for retrieving a variable's value from the slot *//*   of a fact. The retrieval relies on information stored   *//*   in a partial match, so this retrieval mechanism is used *//*   by expressions in the join network or from the RHS of a *//*   rule.                                                   */    /*************************************************************/static VOID *FactGetVarJN1(theNode)  struct lhsParseNode *theNode;  {   struct factGetVarJN1Call hack;   /*===================================================*/   /* Clear the bitmap for storing the argument values. */   /*===================================================*/

⌨️ 快捷键说明

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