<commit_before>defmodule Worker.Enricher.Labels do
  require Logger
  alias Core.Utils
  alias Core.CategoryTreeList

  @core_properties [:id, :identifier, :shortDescription, :geometry, :geometry_wgs84, :georeference,
    :gazId]

  def add_labels(change = %{ doc: %{ resource: resource } }, configuration) do
    put_in(change.doc.resource, add_labels_to_resource(resource, configuration))
  end
  def add_labels(change, _), do: change

  defp add_labels_to_resource(resource, configuration) do
    category_definition = CategoryTreeList.find_by_name(resource.category, configuration)
    if is_nil(category_definition) do
      raise "No category definition found for category #{resource.category}"
    else
      Enum.reduce(resource, %{}, add_labels_to_field(category_definition, configuration))
      |> Enum.into(%{})
      |> Utils.atomize<commit_msg>Fix bug in labels module<commit_after>defmodule Worker.Enricher.Labels do
  require Logger
  alias Core.Utils
  alias Core.CategoryTreeList

  @core_properties [:id, :identifier, :shortDescription, :geometry, :geometry_wgs84, :georeference,
    :gazId, :parentId]

  def add_labels(change = %{ doc: %{ resource: resource } }, configuration) do
    put_in(change.doc.resource, add_labels_to_resource(resource, configuration))
  end
  def add_labels(change, _), do: change

  defp add_labels_to_resource(resource, configuration) do
    category_definition = CategoryTreeList.find_by_name(resource.category, configuration)
    if is_nil(category_definition) do
      raise "No category definition found for category #{resource.category}"
    else
      Enum.reduce(resource, %{}, add_labels_to_field(category_definition, configuration))
      |> Enum.into(%{})
      |> Utils.atomize
{'fraction_non_alphanumeric': 0.10126582278481013, 'fraction_numerical': 0.0023014959723820483, 'mean_word_length': 5.080419580419581, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '907259', 'n_tokens_mistral': 519, 'n_tokens_neox': 502, 'n_words': 116}