<commit_before>module Hyrax
  module CitationsBehaviors
    module NameBehavior
      include Hyrax::CitationsBehaviors::CommonBehavior
      # return all unique authors with end punctuation removed
      def author_list(work)
        all_authors(work) { |author| clean_end_punctuation(CGI.escapeHTML(author)) }
      end

      # return all unique authors of a work or nil if none
      def all_authors(work, &block)
        authors = work.creator.uniq.compact
        block_given? ? authors.map(&block) : authors
      end

      def given_name_first(name)
        name = clean_end_punctuation(name)
        return name unless name =~ /,/
        temp_name = name.split(/,\s*/)
        temp_name.last + " " + temp_name.first
      end

      def surname_first(name)
        name = name.join('') if name.is_a? Array
        # make sure we handle "Cher" correctly
        return name if name.include?(',')
        name_segments = name.split(' ')
        given_name = name_segments.first
        surnames = name_segments[1..-1]
        if surnames
          "#{surnames.join(' ')}, #{given_name}"
        else
          given_name
        end
      end

      def abbreviate_name(name)<commit_msg>Replacing regular expression with string comparison<commit_after>module Hyrax
  module CitationsBehaviors
    module NameBehavior
      include Hyrax::CitationsBehaviors::CommonBehavior
      # return all unique authors with end punctuation removed
      def author_list(work)
        all_authors(work) { |author| clean_end_punctuation(CGI.escapeHTML(author)) }
      end

      # return all unique authors of a work or nil if none
      def all_authors(work, &block)
        authors = work.creator.uniq.compact
        block_given? ? authors.map(&block) : authors
      end

      def given_name_first(name)
        name = clean_end_punctuation(name)
        return name unless name.include?(',')
        temp_name = name.split(/,\s*/)
        temp_name.last + " " + temp_name.first
      end

      def surname_first(name)
        name = name.join('') if name.is_a? Array
        # make sure we handle "Cher" correctly
        return name if name.include?(',')
        name_segments = name.split(' ')
        given_name = name_segments.first
        surnames = name_segments[1..-1]
        if surnames
          "#{surnames.join(' ')}, #{given_name}"
        else
          given_name
        end
      end

      def abbreviate_name(name)
{'fraction_non_alphanumeric': 0.09273697168649979, 'fraction_numerical': 0.0016413623307345096, 'mean_word_length': 2.362758620689655, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4888173', 'n_tokens_mistral': 738, 'n_tokens_neox': 716, 'n_words': 180}