<commit_before>module Importers
  module ProtectedFoodDrinkName
    class Parser
      def initialize(data)
        @data = data
      end

      def get_attributes
        {
          title: title,
          register: register,
          status: status,
          class_category: class_category,
          protection_type: protection_type,
          reason_for_protection: reason_for_protection,
          country_of_origin: country,
          traditional_term_grapevine_product_category: traditional_term_grapevine_product_category,
          traditional_term_type: traditional_term_type,
          traditional_term_language: traditional_term_language,
          date_application: date_application,
          date_registration: date_registration,
          date_registration_eu: date_registration_eu,
          body: body,
          summary: summary,
          internal_notes: internal_notes,
        }
      end

    private

      attr_reader :data

      def title
        data["Registered product name"]
      end

      def register
        if data["Protection type"] == "Name protected by international treaty"
          return "names-protected-by-international-treaty"
        end

        case data["Product type"]
        when "Aromatised wine" then "aromatised-wines"
        when "Spirit drink" then "spirit-drinks"
        when "Wine" then "wines"
        when "Traditional term" then "traditional-terms-for-wine"
        when "Food"
          if data["Protection type"] == "Traditional Specialities Guaranteed (TSG)"
            "foods-traditional-speciality"
          else
            "foods-designated-origin-and-geographical-indication"
          end
        end
      end

      def status
        status_map[data["Status"]]
      end

      def class_category
        data_string = data["Class or category of product"]

        return %w[15-vodka 31-flavoured-vodka] if data_string == "15. Vodka, 31. Flavoured vodka"

        [class_category_map[data_string]]
      end

      def protection_type
        protection_type_map[data["Protection type"]]
      end

      def reason_for_protection
        reason_for_protection_map[data["Reason for protection"]]
      end

      def country
        return [] if data["Country of origin"].blank?

        data["Country of origin"].split(", ").map do |country_string|
          country_map[country_string]
        end
      end

      def traditional_term_grapevine_product_category
        return [] if data["Traditional term grapevine product category"].blank?

        data["Traditional term grapevine product category"].split(", ").map do |category_string|
          grapevine_category_map[category_string]
        end
      end

      def traditional_term_type
        term_type_map[data["Traditional term type"]]
      end

      def traditional_term_language
        language_map[data["Traditional term language"]]
      end

      def date_application
        parse_date(data["Date of application"])
      end

      def date_registration
        parse_date(data["Date of UK registration"])
      end

      def date_registration_eu
        parse_date(data["Date of original registration with the EU"])
      end

      def summary
        case data["Protection type"]
        when "Geographical indication (GI)"
          if data["Product type"] == "Spirit drink"
            "Protected spirit drink name"
          elsif data["Product type"] == "Aromatised wine"
            "Protected aromatised wine name"
          end
        when "Protected Geographical Indication (PGI)"
          if data["Product type"] == "Food"
            "Protected food name with Protected Geographical Indication (PGI)"
          elsif data["Product type"] == "Wine"
            "Protected wine name with Protected Geographical Indication (PGI)"
          end
        when "Protected Designation of Origin (PDO)"
          if data["Product type"] == "Food"
            "Protected food name with Protected Designation of Origin (PDO)"
          elsif data["Product type"] == "Wine"
            "Protected wine name with Protected Designation of Origin (PDO)"
          end || ""
        when "Traditional Specialities Guaranteed (TSG)"
          "Protected food name with Traditional Speciality Guaranteed (TSG)"
        when "Traditional Term"
          "Traditional term for wine"
        when "Name protected by international treaty"
          "Name protected by international treaty"
        end
      end

      def body
        content = ""

        # Product specification
        if data["Product type"] != "Traditional term"
          content += "## Product specification \n\n" \
            "The product specification is not available on this site. " \
            "[Email Defra](<EMAIL>) for the product specification.\n\n" \
        end

        # Decision notice and protection instrument title
        if data["Decision notice"].present? && data["Protection instrument"].present?
          content += "\n## Decision notice and protection instrument\n"
        elsif data["Decision notice"].present?
          content += "\n## Decision notice\n"
        elsif data["Protection instrument"].present?
          content += "\n## Protection instrument\n"
        end

        # Decision notice
        if data["Decision notice"].present?
          content += "\n#{data['Decision notice']}\n"
        end

        # Protection instrument
        if data["Protection instrument"].present?
          content += "\n[Protection instrument for #{data['Registered product name']}]" \
            "(#{data['Protection instrument']})"

          content += if data["Date of publication of the instrument"].present?
                       ". Date of publication of the instrument: #{data['Date of publication of the instrument']}.\n"
                     else
                       "\n"<commit_msg>Don't show product spec if it's a UK trade agreement<commit_after>module Importers
  module ProtectedFoodDrinkName
    class Parser
      def initialize(data)
        @data = data
      end

      def get_attributes
        {
          title: title,
          register: register,
          status: status,
          class_category: class_category,
          protection_type: protection_type,
          reason_for_protection: reason_for_protection,
          country_of_origin: country,
          traditional_term_grapevine_product_category: traditional_term_grapevine_product_category,
          traditional_term_type: traditional_term_type,
          traditional_term_language: traditional_term_language,
          date_application: date_application,
          date_registration: date_registration,
          date_registration_eu: date_registration_eu,
          body: body,
          summary: summary,
          internal_notes: internal_notes,
        }
      end

    private

      attr_reader :data

      def title
        data["Registered product name"]
      end

      def register
        if data["Protection type"] == "Name protected by international treaty"
          return "names-protected-by-international-treaty"
        end

        case data["Product type"]
        when "Aromatised wine" then "aromatised-wines"
        when "Spirit drink" then "spirit-drinks"
        when "Wine" then "wines"
        when "Traditional term" then "traditional-terms-for-wine"
        when "Food"
          if data["Protection type"] == "Traditional Specialities Guaranteed (TSG)"
            "foods-traditional-speciality"
          else
            "foods-designated-origin-and-geographical-indication"
          end
        end
      end

      def status
        status_map[data["Status"]]
      end

      def class_category
        data_string = data["Class or category of product"]

        return %w[15-vodka 31-flavoured-vodka] if data_string == "15. Vodka, 31. Flavoured vodka"

        [class_category_map[data_string]]
      end

      def protection_type
        protection_type_map[data["Protection type"]]
      end

      def reason_for_protection
        reason_for_protection_map[data["Reason for protection"]]
      end

      def country
        return [] if data["Country of origin"].blank?

        data["Country of origin"].split(", ").map do |country_string|
          country_map[country_string]
        end
      end

      def traditional_term_grapevine_product_category
        return [] if data["Traditional term grapevine product category"].blank?

        data["Traditional term grapevine product category"].split(", ").map do |category_string|
          grapevine_category_map[category_string]
        end
      end

      def traditional_term_type
        term_type_map[data["Traditional term type"]]
      end

      def traditional_term_language
        language_map[data["Traditional term language"]]
      end

      def date_application
        parse_date(data["Date of application"])
      end

      def date_registration
        parse_date(data["Date of UK registration"])
      end

      def date_registration_eu
        parse_date(data["Date of original registration with the EU"])
      end

      def summary
        case data["Protection type"]
        when "Geographical indication (GI)"
          if data["Product type"] == "Spirit drink"
            "Protected spirit drink name"
          elsif data["Product type"] == "Aromatised wine"
            "Protected aromatised wine name"
          end
        when "Protected Geographical Indication (PGI)"
          if data["Product type"] == "Food"
            "Protected food name with Protected Geographical Indication (PGI)"
          elsif data["Product type"] == "Wine"
            "Protected wine name with Protected Geographical Indication (PGI)"
          end
        when "Protected Designation of Origin (PDO)"
          if data["Product type"] == "Food"
            "Protected food name with Protected Designation of Origin (PDO)"
          elsif data["Product type"] == "Wine"
            "Protected wine name with Protected Designation of Origin (PDO)"
          end || ""
        when "Traditional Specialities Guaranteed (TSG)"
          "Protected food name with Traditional Speciality Guaranteed (TSG)"
        when "Traditional Term"
          "Traditional term for wine"
        when "Name protected by international treaty"
          "Name protected by international treaty"
        end
      end

      def body
        content = ""

        # Product specification
        if data["Product type"] != "Traditional term" && data["Reason for protection"] != "UK trade agreement"
          content += "## Product specification \n\n" \
            "The product specification is not available on this site. " \
            "[Email Defra](<EMAIL>) for the product specification.\n\n" \
        end

        # Decision notice and protection instrument title
        if data["Decision notice"].present? && data["Protection instrument"].present?
          content += "\n## Decision notice and protection instrument\n"
        elsif data["Decision notice"].present?
          content += "\n## Decision notice\n"
        elsif data["Protection instrument"].present?
          content += "\n## Protection instrument\n"
        end

        # Decision notice
        if data["Decision notice"].present?
          content += "\n#{data['Decision notice']}\n"
        end

        # Protection instrument
        if data["Protection instrument"].present?
          content += "\n[Protection instrument for #{data['Registered product name']}]" \
            "(#{data['Protection instrument']})"

          content += if data["Date of publication of the instrument"].present?
                       ". Date of publication of the instrument: #{data['Date of publication of the instrument']}.\n"
                     else
                       "\n"
{'fraction_non_alphanumeric': 0.08456193865446535, 'fraction_numerical': 0.0013557024233180816, 'mean_word_length': 2.2533076074972436, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5444484', 'n_tokens_mistral': 3101, 'n_tokens_neox': 2914, 'n_words': 900}