from typing import List
from typing import Dict


def get_target_item_name(
        nouns: List[str],
        items_in_expression: List[str],
        inference_dict: Dict,
        category_index: Dict
) -> str:
    """
    Return the name of the target item.

    The name will be an class label among the detected objects or
    an empty string if the name is not present in the possible classes.

    Note:
    ----
        category_index is a dictionary with the convention:
        - 'id': int.
        - 'name': str.

        inference_dict is a dictionary with the convention:
        - detection_masks: List[List[int]] | mask of the detected objects (int = 0 or 1).
        - num_detections: int | number of detected objects in the dictionary.
        - detection_boxes: List[int] | bounding boxes of the objects.
        - detection_scores: List[float] | score of the detection accuracy.
        - detection_classes: List[int] | index of the detected objects classes in the class Dict.

    """
    detected_obj = []
    target_item = ''

    for i in range(inference_dict['num_detections']):
        detected_obj.append(category_index[inference_dict['detection_classes'][i]]['name'])

    for item in items_in_expression:
        for noun in nouns[0].split():
            if (item == noun or item == noun[:-1]) and item in detected_obj:
                target_item = item

    return target_item