Example #1
0
/****************************************************************************************
 *                           DetermineClassFromFileName                                 
 *                                                                                      
 * Given an Image File Name(fileName)  will return and mlClass.  Will use the      
 * path name in fileName to determine class.  If the class does not exist in            
 * mlClasses, will create a new instance and add it to mlClasses.                  
 *
 * After talking to the user it has come to light that the first sub-directory in
 * a path will dictate what class he/she feels a image belongs to.
 *   Ex:
 *    .../Protista/
 *    .../Protista/SubDir1
 *    .../Trichodesmium
 *    .../Trichodesmium/SubDir1
 *    .../Trichodesmium/SubDir2
 *    
 *  The idea is that when trying to determine what class a image really is we look
 *  at the first sub-dir name in the path.  We may also have to deal with seq-num's 
 *  as part of the name,  in that case we strip the _ and following numbers from the 
 *  name to get the correct class name.
 ****************************************************************************************/
MLClassPtr  OurNeighbors::DetermineClassFromFileName (const  KKStr&  fileName)
{
	KKStr filename_copy = fileName;

	// If there are no path separator characters('\'  or  '/')  characters in name
	// then we will not be able to determine the class.
	
  auto x = osLocateFirstSlashChar (filename_copy);
	if  (!x  ||  (x.value () < 1))
    return  mlClasses->GetUnKnownClass ();

  KKStr  className = filename_copy.SubStrSeg (0, x);
  
  // now lets get rid of any possible trailing seq number.
  // We are assuming that a underscore{"_") character separates the calcs name from the seq number.
  // So if there is an underscore character,  and all the characters to the right of it are
  // underscore characters,  then we will remove the underscore and the following numbers.
	x = className.LocateLastOccurrence ('_');
  if  (x)
  {
    // Now lets eliminate any sequence number in name
    // We are assuming that a underscore{"_") character separates the class name from the seq number.
    // So if there is an underscore character, and all the characters to the right of it are
    // numeric characters, then we will remove the underscore and the following numbers.

    kkuint32  y = x.value () + 1;

    bool  allFollowingCharsAreNumeric = true;
    while  ((y < className.Len ()) &&  (allFollowingCharsAreNumeric))
    {
      char  ch = className[y];
      allFollowingCharsAreNumeric = ((ch >= '0')  &&  (ch <= '9'));
      y++;
    }

    if  (allFollowingCharsAreNumeric)
    {
      className = className.SubStrSeg (0, x);
    }
  }

  // Now that we have a string with the class name,  lets get a pointer 
  // to a mlClass object from mlClasses ,  if none there then we get 
  // to create a new class.
	MLClassPtr  mlClass = mlClasses->GetMLClassPtr (className);

	return  mlClass;
}  /* DetermineClassFromFileName */
ActiveLearningReport::ActiveLearningReport (RunLog&          _log,
                                            MLClassList&  _mlClasses,
                                            KKStr           _subDirName
                                           ):
  mlClasses        (_mlClasses),
  log                 (_log),
  subDirName          (_subDirName),
  results             (true, 10),
  baseResultsFileName ("ActiveLearningResults")
{
  if  (!subDirName.Empty ())
  {
    KKStr  w (subDirName);
    osAddLastSlash (w);
    w << baseResultsFileName;
    baseResultsFileName = w;
  }


// C:\users\kkramer\GradSchool\Plankton\ActiveLearning\Results\010-IPC\2003-12-03_AllOrders_010-IPC_50-IPR

  int x = subDirName.LocateLastOccurrence ('_');

  if  (x > 5)
  {
    KKStr leftSide = subDirName.SubStrPart (0, x - 1);
    KKStr rightSide = subDirName.SubStrPart (x + 1);
    x = rightSide.LocateCharacter ('-');
    KKStr  IPR = rightSide.SubStrPart (0, x - 1);
    imagesPerRetraining = atoi (IPR.Str ());

    x = leftSide.LocateLastOccurrence ('_');
    rightSide = subDirName.SubStrPart (x + 1);
    x = rightSide.LocateCharacter ('-');
    KKStr  IPC = rightSide.SubStrPart (0, x - 1);
    initialImagesPerClass = atoi (IPC.Str ());
  }
}