Пример #1
0
static struct fact *FactExists(
  struct fact *theFact,
  int hashValue)
  {
   struct factHashEntry *theFactHash;

   for (theFactHash = FactHashTable[hashValue];
        theFactHash != NULL;
        theFactHash = theFactHash->next)
     {
      if ((theFact->whichDeftemplate == theFactHash->theFact->whichDeftemplate) ?
          MultifieldsEqual(&theFact->theProposition,
                           &theFactHash->theFact->theProposition) : FALSE)
#if CERTAINTY_FACTORS 
          /* standard facts -- same templates means same fact --
             perform global contribution calculation for CF and return
             ptr to existing fact indicating fact exists
          */
        { changeCFofExistingFact(theFact,theFactHash->theFact);
          return(theFactHash->theFact);
        }
#else
        { return(theFactHash->theFact); }
#endif
     }

   return(NULL);
  }
Пример #2
0
static struct templateSlot *GetNextTemplateSlotToPrint(
  void *theEnv,
  struct fact *theFact,
  struct templateSlot *slotPtr,
  int *position,
  int ignoreDefaults,
  const char *changeMap)
  {
   DATA_OBJECT tempDO;
   struct field *sublist;

   sublist = theFact->theProposition.theFields;
   if (slotPtr == NULL)
     { slotPtr = theFact->whichDeftemplate->slotList; }
   else
     {
      slotPtr = slotPtr->next;
      (*position)++;
     }
     
   while (slotPtr != NULL)
     {
      if ((changeMap != NULL) && (TestBitMap(changeMap,*position) == 0))
        {
         (*position)++;
         slotPtr = slotPtr->next;
         continue;
        }

      if (ignoreDefaults && (slotPtr->defaultDynamic == false))
        {
         DeftemplateSlotDefault(theEnv,theFact->whichDeftemplate,slotPtr,&tempDO,true);
         
         if (slotPtr->multislot == false)
           {
            if ((GetType(tempDO) == sublist[*position].type) &&
                (GetValue(tempDO) == sublist[*position].value))
              {     
               (*position)++;
               slotPtr = slotPtr->next;
               continue;
              }
           }
         else if (MultifieldsEqual((struct multifield*) GetValue(tempDO),
                                   (struct multifield *) sublist[*position].value))
           {
            (*position)++;
            slotPtr = slotPtr->next;
            continue;
           }
        }
        
      return slotPtr;
     }
     
   return NULL;
  }
Пример #3
0
static struct templateSlot *GetNextTemplateSlotToPrint(
  Environment *theEnv,
  struct fact *theFact,
  struct templateSlot *slotPtr,
  int *position,
  int ignoreDefaults,
  const char *changeMap)
  {
   UDFValue tempDO;
   CLIPSValue *sublist;

   sublist = theFact->theProposition.contents;
   if (slotPtr == NULL)
     { slotPtr = theFact->whichDeftemplate->slotList; }
   else
     {
      slotPtr = slotPtr->next;
      (*position)++;
     }

   while (slotPtr != NULL)
     {
      if ((changeMap != NULL) && (TestBitMap(changeMap,*position) == 0))
        {
         (*position)++;
         slotPtr = slotPtr->next;
         continue;
        }

      if (ignoreDefaults && (slotPtr->defaultDynamic == false))
        {
         DeftemplateSlotDefault(theEnv,theFact->whichDeftemplate,slotPtr,&tempDO,true);

         if (slotPtr->multislot == false)
           {
            if (tempDO.value == sublist[*position].value)
              {
               (*position)++;
               slotPtr = slotPtr->next;
               continue;
              }
           }
         else if (MultifieldsEqual((Multifield *) tempDO.value,
                                   (Multifield *) sublist[*position].value))
           {
            (*position)++;
            slotPtr = slotPtr->next;
            continue;
           }
        }

      return slotPtr;
     }

   return NULL;
  }
Пример #4
0
globle int HandleExistingFuzzyFact(
  VOID **theFact)
  {
   struct fact *tempFact;
   struct factHashEntry *theFactHash;
   int hashValue;
   struct fact *theFactPtr = (struct fact *)*theFact;

   hashValue = HashFact(theFactPtr);

   /* Fuzzy facts never get duplicated ... they just get modified if they
      already exist ... always allow duplication for them...
      do the required modification to the fact if it already exists
   */

   theFactHash = FactHashTable[hashValue];
   tempFact = NULL;

   while (theFactHash != NULL)
     {
      if (theFactPtr->whichDeftemplate == theFactHash->theFact->whichDeftemplate)
        { /* same template definitions for fact */
          if (MultifieldsEqual(&theFactPtr->theProposition,
                               &theFactHash->theFact->theProposition))
            { /* MultiFieldsEqual will compare fuzzy fields to be equal
                 if they are both of the same FUZZY_VALUE type
              */
              tempFact = theFactHash->theFact;
#if CERTAINTY_FACTORS
              /* If facts are the same we need to perform
                 global contribution calculation for CF
              */
              changeCFofNewVsExistingFact(theFactPtr, tempFact);
#endif

              /* fuzzy facts (ie. any fuzzy slots) perform global
                 contribution calculation(s) for each fuzzy slot
              */
              changeValueOfFuzzySlots(tempFact, theFactPtr);
                          break;
            }
        }
      theFactHash = theFactHash->next;
     }

   if (tempFact != NULL) /* existing fact! retract it before new one gets asserted */
       Retract(tempFact);

   return(hashValue);
  }
Пример #5
0
globle int MultifieldsEqual(
  struct multifield *segment1,
  struct multifield *segment2)
  {
   struct field *elem1;
   struct field *elem2;
   long length, i = 0;

   length = segment1->multifieldLength;
   if (length != segment2->multifieldLength)
     { return(FALSE); }

   elem1 = segment1->theFields;
   elem2 = segment2->theFields;

   /*==================================================*/
   /* Compare each field of both facts until the facts */
   /* match completely or the facts mismatch.          */
   /*==================================================*/

   while (i < length)
     {
      if (elem1[i].type != elem2[i].type)
        { return(FALSE); }

      if (elem1[i].type == MULTIFIELD)
        {
         if (MultifieldsEqual((struct multifield *) elem1[i].value,
                              (struct multifield *) elem2[i].value) == FALSE)
          { return(FALSE); }
        }
      else if (elem1[i].value != elem2[i].value)
        { return(FALSE); }

      i++;
     }
   return(TRUE);
  }
Пример #6
0
static struct fact *FactExists(
  void *theEnv,
  struct fact *theFact,
  unsigned long hashValue)
  {
   struct factHashEntry *theFactHash;

   hashValue = (hashValue % FactData(theEnv)->FactHashTableSize);

   for (theFactHash = FactData(theEnv)->FactHashTable[hashValue];
        theFactHash != NULL;
        theFactHash = theFactHash->next)
     {
      if (theFact->hashValue != theFactHash->theFact->hashValue)
        { continue; }

      if ((theFact->whichDeftemplate == theFactHash->theFact->whichDeftemplate) ?
          MultifieldsEqual(&theFact->theProposition,
                           &theFactHash->theFact->theProposition) : FALSE)
        { return(theFactHash->theFact); }
     }

   return(NULL);
  }