#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# */AIPND-revision/intropyproject-classify-pet-images/get_pet_labels.py
#
# PROGRAMMER:
# DATE CREATED:
# REVISED DATE:
# PURPOSE: Create the function get_pet_labels that creates the pet labels from
#          the image's filename. This function inputs:
#           - The Image Folder as image_dir within get_pet_labels function and
#             as in_arg.dir for the function call within the main function.
#          This function creates and returns the results dictionary as results_dic
#          within get_pet_labels function and as results within main.
#          The results_dic dictionary has a 'key' that's the image filename and
#          a 'value' that's a list. This list will contain the following item
#          at index 0 : pet image label (string).
#
##
# Imports python modules
from os import listdir

# TODO 2: Define get_pet_labels function below please be certain to replace None
#       in the return statement with results_dic dictionary that you create
#       with this function
#
def get_pet_labels(image_dir):
    """
    Creates a dictionary of pet labels (results_dic) based upon the filenames
    of the image files. These pet image labels are used to check the accuracy
    of the labels that are returned by the classifier function, since the
    filenames of the images contain the true identity of the pet in the image.
    Be sure to format the pet labels so that they are in all lower case letters
    and with leading and trailing whitespace characters stripped from them.
    (ex. filename = 'Boston_terrier_02259.jpg' Pet label = 'boston terrier')
    Parameters:
     image_dir - The (full) path to the folder of images that are to be
                 classified by the classifier function (string)
    Returns:
      results_dic - Dictionary with 'key' as image filename and 'value' as a
      List. The list contains for following item:
         index 0 = pet image label (string)
    """
    # Create dictionary
    petlabels_dic = {}

    # Retrieve the filenames from folder pet_images/
    # Try to catch exceptions (folder does not exists, etc..)
    try:
        filename_list = listdir(image_dir)
    except:
        print('** Error: unable to list files in "{}" folder.'.format(image_dir))
        exit()
    else:
       for idx in range(0,len(filename_list)):
        #if filename_list[idx] not in petlabels_dic: # required? probably not
            # Remove extension from filename
            filename = filename_list[idx].split('.')[0]
            # Create a list of words from filename, removing digits
            filename_labels = list(filter(lambda label: label.isalpha(), filename.split('_')))
            # Create key->value item in dictonary
            petlabels_dic[filename_list[idx]] = [" ".join(filename_labels).lower()]

    # Return dictionary
    return petlabels_dic

2c29c6f1f7bb0f6646ebe9375f3fd49b92e11454
<mask token>

<mask token>


def get_pet_labels(image_dir):
    """
    Creates a dictionary of pet labels (results_dic) based upon the filenames
    of the image files. These pet image labels are used to check the accuracy
    of the labels that are returned by the classifier function, since the
    filenames of the images contain the true identity of the pet in the image.
    Be sure to format the pet labels so that they are in all lower case letters
    and with leading and trailing whitespace characters stripped from them.
    (ex. filename = 'Boston_terrier_02259.jpg' Pet label = 'boston terrier')
    Parameters:
     image_dir - The (full) path to the folder of images that are to be
                 classified by the classifier function (string)
    Returns:
      results_dic - Dictionary with 'key' as image filename and 'value' as a
      List. The list contains for following item:
         index 0 = pet image label (string)
    """
    petlabels_dic = {}
    try:
        filename_list = listdir(image_dir)
    except:
        print('** Error: unable to list files in "{}" folder.'.format(
            image_dir))
        exit()
    else:
        for idx in range(0, len(filename_list)):
            filename = filename_list[idx].split('.')[0]
            filename_labels = list(filter(lambda label: label.isalpha(),
                filename.split('_')))
            petlabels_dic[filename_list[idx]] = [' '.join(filename_labels).
                lower()]
    return petlabels_dic

from os import listdir


def get_pet_labels(image_dir):
    """
    Creates a dictionary of pet labels (results_dic) based upon the filenames
    of the image files. These pet image labels are used to check the accuracy
    of the labels that are returned by the classifier function, since the
    filenames of the images contain the true identity of the pet in the image.
    Be sure to format the pet labels so that they are in all lower case letters
    and with leading and trailing whitespace characters stripped from them.
    (ex. filename = 'Boston_terrier_02259.jpg' Pet label = 'boston terrier')
    Parameters:
     image_dir - The (full) path to the folder of images that are to be
                 classified by the classifier function (string)
    Returns:
      results_dic - Dictionary with 'key' as image filename and 'value' as a
      List. The list contains for following item:
         index 0 = pet image label (string)
    """
    petlabels_dic = {}
    try:
        filename_list = listdir(image_dir)
    except:
        print('** Error: unable to list files in "{}" folder.'.format(
            image_dir))
        exit()
    else:
        for idx in range(0, len(filename_list)):
            filename = filename_list[idx].split('.')[0]
            filename_labels = list(filter(lambda label: label.isalpha(),
                filename.split('_')))
            petlabels_dic[filename_list[idx]] = [' '.join(filename_labels).
                lower()]
    return petlabels_dic

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# */AIPND-revision/intropyproject-classify-pet-images/get_pet_labels.py
#
# PROGRAMMER:
# DATE CREATED:
# REVISED DATE:
# PURPOSE: Create the function get_pet_labels that creates the pet labels from
#          the image's filename. This function inputs:
#           - The Image Folder as image_dir within get_pet_labels function and
#             as in_arg.dir for the function call within the main function.
#          This function creates and returns the results dictionary as results_dic
#          within get_pet_labels function and as results within main.
#          The results_dic dictionary has a 'key' that's the image filename and
#          a 'value' that's a list. This list will contain the following item
#          at index 0 : pet image label (string).
#
##
# Imports python modules
from os import listdir

# TODO 2: Define get_pet_labels function below please be certain to replace None
#       in the return statement with results_dic dictionary that you create
#       with this function
#
def get_pet_labels(image_dir):
    """
    Creates a dictionary of pet labels (results_dic) based upon the filenames
    of the image files. These pet image labels are used to check the accuracy
    of the labels that are returned by the classifier function, since the
    filenames of the images contain the true identity of the pet in the image.
    Be sure to format the pet labels so that they are in all lower case letters
    and with leading and trailing whitespace characters stripped from them.
    (ex. filename = 'Boston_terrier_02259.jpg' Pet label = 'boston terrier')
    Parameters:
     image_dir - The (full) path to the folder of images that are to be
                 classified by the classifier function (string)
    Returns:
      results_dic - Dictionary with 'key' as image filename and 'value' as a
      List. The list contains for following item:
         index 0 = pet image label (string)
    """
    # Create dictionary
    petlabels_dic = {}

    # Retrieve the filenames from folder pet_images/
    # Try to catch exceptions (folder does not exists, etc..)
    try:
        filename_list = listdir(image_dir)
    except:
        print('** Error: unable to list files in "{}" folder.'.format(image_dir))
        exit()
    else:
       for idx in range(0,len(filename_list)):
        #if filename_list[idx] not in petlabels_dic: # required? probably not
            # Remove extension from filename
            filename = filename_list[idx].split('.')[0]
            # Create a list of words from filename, removing digits
            filename_labels = list(filter(lambda label: label.isalpha(), filename.split('_')))
            # Create key->value item in dictonary
            petlabels_dic[filename_list[idx]] = [" ".join(filename_labels).lower()]

    # Return dictionary
    return petlabels_dic
