/*---------------------------------------------------------------------------*/ void WriteCharDescription(FILE *File, CHAR_DESC CharDesc) { /* ** Parameters: ** File open text file to write CharDesc to ** CharDesc character description to write to File ** Globals: none ** Operation: Write a textual representation of CharDesc to File. ** The format used is to write out the number of feature ** sets which will be written followed by a representation of ** each feature set. ** Each set starts with the short name for that feature followed ** by a description of the feature set. Feature sets which are ** not present are not written. ** Return: none ** Exceptions: none ** History: Wed May 23 17:21:18 1990, DSJ, Created. */ int Type; int NumSetsToWrite = 0; for (Type = 0; Type < NumFeatureSetsIn (CharDesc); Type++) if (FeaturesOfType (CharDesc, Type)) NumSetsToWrite++; fprintf (File, " %d\n", NumSetsToWrite); for (Type = 0; Type < NumFeatureSetsIn (CharDesc); Type++) if (FeaturesOfType (CharDesc, Type)) { fprintf (File, "%s ", ShortNameOf (DefinitionOf (Type))); WriteFeatureSet (File, FeaturesOfType (CharDesc, Type)); } } /* WriteCharDescription */
/** * Write a textual representation of CharDesc to File. * The format used is to write out the number of feature * sets which will be written followed by a representation of * each feature set. * * Each set starts with the short name for that feature followed * by a description of the feature set. Feature sets which are * not present are not written. * * Globals: * - none * * @param FeatureDefs definitions of feature types/extractors * @param File open text file to write CharDesc to * @param CharDesc character description to write to File * * @note Exceptions: none * @note History: Wed May 23 17:21:18 1990, DSJ, Created. */ void WriteCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs, FILE *File, CHAR_DESC CharDesc) { int Type; int NumSetsToWrite = 0; for (Type = 0; Type < CharDesc->NumFeatureSets; Type++) if (CharDesc->FeatureSets[Type]) NumSetsToWrite++; fprintf (File, " %d\n", NumSetsToWrite); for (Type = 0; Type < CharDesc->NumFeatureSets; Type++) if (CharDesc->FeatureSets[Type]) { fprintf (File, "%s ", (FeatureDefs.FeatureDesc[Type])->ShortName); WriteFeatureSet (File, CharDesc->FeatureSets[Type]); } } /* WriteCharDescription */
/** * Appends a textual representation of CharDesc to str. * The format used is to write out the number of feature * sets which will be written followed by a representation of * each feature set. * * Each set starts with the short name for that feature followed * by a description of the feature set. Feature sets which are * not present are not written. * * @param FeatureDefs definitions of feature types/extractors * @param str string to append CharDesc to * @param CharDesc character description to write to File * * @note Exceptions: none * @note History: Wed May 23 17:21:18 1990, DSJ, Created. */ void WriteCharDescription(const FEATURE_DEFS_STRUCT &FeatureDefs, CHAR_DESC CharDesc, STRING *str) { int Type; int NumSetsToWrite = 0; for (Type = 0; Type < CharDesc->NumFeatureSets; Type++) if (CharDesc->FeatureSets[Type]) NumSetsToWrite++; str->add_str_int(" ", NumSetsToWrite); *str += "\n"; for (Type = 0; Type < CharDesc->NumFeatureSets; Type++) { if (CharDesc->FeatureSets[Type]) { *str += FeatureDefs.FeatureDesc[Type]->ShortName; *str += " "; WriteFeatureSet(CharDesc->FeatureSets[Type], str); } } } /* WriteCharDescription */
/*---------------------------------------------------------------------------*/ void WriteTrainingSamples ( char *Directory, LIST CharList, const char* program_feature_type) /* ** Parameters: ** Directory directory to place sample files into ** FontList list of fonts used in the training samples ** Operation: ** This routine writes the specified samples into files which ** are organized according to the font name and character name ** of the samples. ** Return: none ** Exceptions: none ** History: Fri Aug 18 16:17:06 1989, DSJ, Created. */ { LABELEDLIST CharSample; FEATURE_SET FeatureSet; LIST FeatureList; FILE *File; char Filename[MAXNAMESIZE]; int NumSamples; iterate (CharList) // iterate thru all of the fonts { CharSample = (LABELEDLIST) first_node (CharList); // construct the full pathname for the current samples file strcpy (Filename, ""); if (Directory != NULL) { strcat (Filename, Directory); strcat (Filename, "/"); } strcat (Filename, CTFontName); strcat (Filename, "/"); strcat (Filename, CharSample->Label); strcat (Filename, "."); strcat (Filename, program_feature_type); printf ("\nWriting %s ...", Filename); /* if file does not exist, create a new one with an appropriate header; otherwise append samples to the existing file */ File = fopen (Filename, "r"); if (File == NULL) { File = Efopen (Filename, "w"); WriteOldParamDesc( File, FeatureDefs.FeatureDesc[ShortNameToFeatureType( program_feature_type)]); } else { fclose (File); File = Efopen (Filename, "a"); } // append samples onto the file FeatureList = CharSample->List; NumSamples = 0; iterate (FeatureList) { FeatureSet = (FEATURE_SET) first_node (FeatureList); WriteFeatureSet (File, FeatureSet); NumSamples++; } fclose (File); } } /* WriteTrainingSamples */