globle void PrintAtom( char *logicalName, int type, void *value) { char buffer[20]; switch (type) { case FLOAT: PrintFloat(logicalName,ValueToDouble(value)); break; case INTEGER: PrintLongInteger(logicalName,ValueToLong(value)); break; case SYMBOL: PrintRouter(logicalName,ValueToString(value)); break; case STRING: if (PreserveEscapedCharacters) { PrintRouter(logicalName,StringPrintForm(ValueToString(value))); } else { PrintRouter(logicalName,"\""); PrintRouter(logicalName,ValueToString(value)); PrintRouter(logicalName,"\""); } break; case EXTERNAL_ADDRESS: if (AddressesToStrings) PrintRouter(logicalName,"\""); PrintRouter(logicalName,"<Pointer-"); sprintf(buffer,"%p",value); PrintRouter(logicalName,buffer); PrintRouter(logicalName,">"); if (AddressesToStrings) PrintRouter(logicalName,"\""); break; #if OBJECT_SYSTEM case INSTANCE_NAME: PrintRouter(logicalName,"["); PrintRouter(logicalName,ValueToString(value)); PrintRouter(logicalName,"]"); break; #endif #if FUZZY_DEFTEMPLATES case FUZZY_VALUE: PrintFuzzyValue(logicalName,ValueToFuzzyValue(value)); break; #endif case RVOID: break; default: if (PrimitivesArray[type] == NULL) break; if (PrimitivesArray[type]->longPrintFunction == NULL) { PrintRouter(logicalName,"<unknown atom type>"); break; } (*PrimitivesArray[type]->longPrintFunction)(logicalName,value); break; } }
globle intBool CheckAllowedValuesConstraint( int type, void *vPtr, CONSTRAINT_RECORD *constraints) { struct expr *tmpPtr; /*=========================================*/ /* If the constraint record is NULL, there */ /* are no allowed-... restrictions. */ /*=========================================*/ if (constraints == NULL) return(TRUE); /*=====================================================*/ /* Determine if there are any allowed-... restrictions */ /* for the type of the value being checked. */ /*=====================================================*/ switch (type) { case SYMBOL: if ((constraints->symbolRestriction == FALSE) && (constraints->anyRestriction == FALSE)) { return(TRUE); } break; #if OBJECT_SYSTEM case INSTANCE_NAME: if ((constraints->instanceNameRestriction == FALSE) && (constraints->anyRestriction == FALSE)) { return(TRUE); } break; #endif case STRING: if ((constraints->stringRestriction == FALSE) && (constraints->anyRestriction == FALSE)) { return(TRUE); } break; case INTEGER: if ((constraints->integerRestriction == FALSE) && (constraints->anyRestriction == FALSE)) { return(TRUE); } break; case FLOAT: if ((constraints->floatRestriction == FALSE) && (constraints->anyRestriction == FALSE)) { return(TRUE); } break; #if FUZZY_DEFTEMPLATES case FUZZY_VALUE: if ((constraints->fuzzyValueRestriction == FALSE) && (constraints->anyRestriction == FALSE)) { return(TRUE); } break; #endif default: return(TRUE); } /*=========================================================*/ /* Search through the restriction list to see if the value */ /* matches one of the allowed values in the list. */ /*=========================================================*/ #if FUZZY_DEFTEMPLATES /* special situation for FUZZY_VALUES since they cannot be combined with other restrictions and there will only be 1 entry on the restriction list -- this entry is of type DEFTEMPLATE_PTR and identifies the fuzzy deftemplate to be associated with the FUZZY VALUE. If the restriction list is NULL then this is a fuzzy deftemplate fuzzy value and will only be attached to it's own detemplate */ if (type == FUZZY_VALUE) { struct deftemplate *deftPtr; struct fuzzy_value *fv; tmpPtr = constraints->restrictionList; if (tmpPtr == NULL) return(TRUE); if (tmpPtr->type != DEFTEMPLATE_PTR) return(FALSE); deftPtr = (struct deftemplate *) tmpPtr->value; fv = ValueToFuzzyValue(vPtr); if (deftPtr == fv->whichDeftemplate) return(TRUE); return(FALSE); } #endif for (tmpPtr = constraints->restrictionList; tmpPtr != NULL; tmpPtr = tmpPtr->nextArg) { if ((tmpPtr->type == type) && (tmpPtr->value == vPtr)) return(TRUE); } /*====================================================*/ /* If the value wasn't found in the list, then return */ /* FALSE because the constraint has been violated. */ /*====================================================*/ return(FALSE); }
globle void PrintTemplateFact( char *logicalName, struct fact *theFact) { struct field *sublist; int i; struct deftemplate *theDeftemplate; struct templateSlot *slotPtr; /*==============================*/ /* Initialize some information. */ /*==============================*/ theDeftemplate = theFact->whichDeftemplate; sublist = theFact->theProposition.theFields; /*=============================================*/ /* Print the relation name of the deftemplate. */ /*=============================================*/ PrintRouter(logicalName,"("); PrintRouter(logicalName,theDeftemplate->header.name->contents); #if FUZZY_DEFTEMPLATES if (theDeftemplate->fuzzyTemplate != NULL) /* fuzzy template */ { PrintFuzzyTemplateFact(logicalName, (struct fuzzy_value *)ValueToFuzzyValue((sublist[0].value)) #if CERTAINTY_FACTORS ,theFact->factCF #endif ); return; } #endif if (theDeftemplate->slotList != NULL) PrintRouter(logicalName," "); /*===================================================*/ /* Print each of the field slots of the deftemplate. */ /*===================================================*/ slotPtr = theDeftemplate->slotList; i = 0; while (slotPtr != NULL) { /*===========================================*/ /* Print the closing parenthesis of the slot */ /* and the slot name. */ /*===========================================*/ PrintRouter(logicalName,"("); PrintRouter(logicalName,slotPtr->slotName->contents); /*======================================================*/ /* Print the value of the slot for a single field slot. */ /*======================================================*/ if (slotPtr->multislot == FALSE) { PrintRouter(logicalName," "); #if FUZZY_DEFTEMPLATES /* for a fuzzy value printed during a fact save we need to look for the 'xxx' linguistic value -- if it is xxx then print the set as singletons */ if (saveFactsInProgress && sublist[i].type == FUZZY_VALUE ) { struct fuzzy_value *fv; fv = ValueToFuzzyValue(sublist[i].value); if (strcmp("???", fv->name) == 0) PrintFuzzySet(logicalName, fv); else PrintRouter(logicalName, fv->name); } else #endif PrintAtom(logicalName,sublist[i].type,sublist[i].value); } /*==========================================================*/ /* Else print the value of the slot for a multi field slot. */ /*==========================================================*/ else { struct multifield *theSegment; theSegment = (struct multifield *) sublist[i].value; if (theSegment->multifieldLength > 0) { PrintRouter(logicalName," "); PrintMultifield(logicalName,(struct multifield *) sublist[i].value, 0,theSegment->multifieldLength-1,FALSE); } } /*============================================*/ /* Print the closing parenthesis of the slot. */ /*============================================*/ i++; PrintRouter(logicalName,")"); slotPtr = slotPtr->next; if (slotPtr != NULL) PrintRouter(logicalName," "); } PrintRouter(logicalName,")"); #if CERTAINTY_FACTORS printCF(logicalName,theFact->factCF); #endif #if FUZZY_DEFTEMPLATES /* There may be some fuzzy value slots in the fact -- if so just print out the fuzzy sets for them on next lines ... UNLESS we are doing a fact save operation! */ if (!saveFactsInProgress) for (i=0; i<(unsigned int)theDeftemplate->numberOfSlots; i++) { if (sublist[i].type == FUZZY_VALUE) { PrintRouter(logicalName,"\n\t( "); PrintFuzzySet(logicalName, ValueToFuzzyValue(sublist[i].value)); PrintRouter(logicalName," )"); } } #endif }
globle void PrintAtom( void *theEnv, const char *logicalName, int type, void *value) { struct externalAddressHashNode *theAddress; char buffer[20]; switch (type) { case FLOAT: PrintFloat(theEnv,logicalName,ValueToDouble(value)); break; case INTEGER: PrintLongInteger(theEnv,logicalName,ValueToLong(value)); break; case SYMBOL: EnvPrintRouter(theEnv,logicalName,ValueToString(value)); break; case STRING: if (PrintUtilityData(theEnv)->PreserveEscapedCharacters) { EnvPrintRouter(theEnv,logicalName,StringPrintForm(theEnv,ValueToString(value))); } else { EnvPrintRouter(theEnv,logicalName,"\""); EnvPrintRouter(theEnv,logicalName,ValueToString(value)); EnvPrintRouter(theEnv,logicalName,"\""); } break; case DATA_OBJECT_ARRAY: if (PrintUtilityData(theEnv)->AddressesToStrings) EnvPrintRouter(theEnv,logicalName,"\""); EnvPrintRouter(theEnv,logicalName,"<Pointer-"); gensprintf(buffer,"%p",value); EnvPrintRouter(theEnv,logicalName,buffer); EnvPrintRouter(theEnv,logicalName,">"); if (PrintUtilityData(theEnv)->AddressesToStrings) EnvPrintRouter(theEnv,logicalName,"\""); break; case EXTERNAL_ADDRESS: theAddress = (struct externalAddressHashNode *) value; if (PrintUtilityData(theEnv)->AddressesToStrings) EnvPrintRouter(theEnv,logicalName,"\""); if ((EvaluationData(theEnv)->ExternalAddressTypes[theAddress->type] != NULL) && (EvaluationData(theEnv)->ExternalAddressTypes[theAddress->type]->longPrintFunction != NULL)) { (*EvaluationData(theEnv)->ExternalAddressTypes[theAddress->type]->longPrintFunction)(theEnv,logicalName,value); } else { EnvPrintRouter(theEnv,logicalName,"<Pointer-"); gensprintf(buffer,"%d-",theAddress->type); EnvPrintRouter(theEnv,logicalName,buffer); gensprintf(buffer,"%p",ValueToExternalAddress(value)); EnvPrintRouter(theEnv,logicalName,buffer); EnvPrintRouter(theEnv,logicalName,">"); } if (PrintUtilityData(theEnv)->AddressesToStrings) EnvPrintRouter(theEnv,logicalName,"\""); break; #if OBJECT_SYSTEM case INSTANCE_NAME: EnvPrintRouter(theEnv,logicalName,"["); EnvPrintRouter(theEnv,logicalName,ValueToString(value)); EnvPrintRouter(theEnv,logicalName,"]"); break; #endif #if FUZZY_DEFTEMPLATES case FUZZY_VALUE: PrintFuzzyValue(theEnv,logicalName,ValueToFuzzyValue(value)); break; #endif case RVOID: break; default: if (EvaluationData(theEnv)->PrimitivesArray[type] == NULL) break; if (EvaluationData(theEnv)->PrimitivesArray[type]->longPrintFunction == NULL) { EnvPrintRouter(theEnv,logicalName,"<unknown atom type>"); break; } (*EvaluationData(theEnv)->PrimitivesArray[type]->longPrintFunction)(theEnv,logicalName,value); break; } }