from typing import Dict
import pkgutil
import io


def _load_categories(filepath: str) -> Dict[str, str]:
  """Load data for domain category matching.

  Args:
    filepath: relative path to csv file containing domains and categories

  Returns:
    Dictionary mapping domains to categories
  """
  data = pkgutil.get_data(__name__, filepath)
  if not data:
    raise FileNotFoundError(f"Couldn't find file {filepath}")
  content = io.TextIOWrapper(io.BytesIO(data), encoding='utf-8')

  categories = {}
  for line in content.readlines():
    domain, category = line.strip().split(',')
    categories[domain] = category
  return categories