from pathlib import Path
from typing import Tuple
from typing import List
from typing import Dict


def get_category(label_def_file: Path) -> Tuple[List[Dict], Dict]:
    """
    Returns the list of categories, and a lookup table that for each
    category/sub_category/value in {label_def_file}, contains that assigned label id.
    """
    with label_def_file.open() as f:
        content = [x.strip() for x in f.readlines()]
    categories = []
    lookup_table = {}
    for idx, line_i in enumerate(content):
        category = {"supercategory": "ssigns", "id": idx + 1, "name": line_i.replace("/", "_")}
        categories.append(category)
        for word_i in line_i.split("|"):
            if word_i:
                lookup_table.update({word_i.strip(): category["id"]})
    return categories, lookup_table