<commit_before>module GutenbergRdf
  class Rdf
    class Agent
      attr_reader :xml

      def initialize(xml)
        @xml = xml
      end

      def id
        xml.at_xpath('pgterms:agent').attribute('about').content.match(/\A\d\d\d\d\/agents\/(\d+)\z/)[1]
      end

      def fullname
        [firstname, lastname].join(' ')
      end

      def lastname
        @lastname ||= name_parts[:last]
      end

      def firstname
        @firstname ||= name_parts[:first]
      end

      def birthdate
        xml.at_xpath('pgterms:agent/pgterms:birthdate').text
      end

      def deathdate
        xml.at_xpath('pgterms:agent/pgterms:deathdate').text
      end

      def webpage
        xml.at_xpath('pgterms:agent/pgterms:webpage').attribute('resource').content
      end

      def aliases
        entries = Array.new
        xml.xpath('//pgterms:alias').each do |name|
          entries << name.text
        end
        entries
      end

    private

      def name_parts
        parts = xml.at_xpath('pgterms:agent/pgterms:name').text.split(/, */)
        last  = parts.shift
        first = parts.reverse.join(' ')

        {first: first, last: last}
      end
<commit_msg>small bugfix in agent name splitting<commit_after>module GutenbergRdf
  class Rdf
    class Agent
      attr_reader :xml

      def initialize(xml)
        @xml = xml
      end

      def id
        xml.at_xpath('pgterms:agent').attribute('about').content.match(/\A\d\d\d\d\/agents\/(\d+)\z/)[1]
      end

      def fullname
        [firstname, lastname].join(' ')
      end

      def lastname
        @lastname ||= name_parts[:last]
      end

      def firstname
        @firstname ||= name_parts[:first]
      end

      def birthdate
        xml.at_xpath('pgterms:agent/pgterms:birthdate').text
      end

      def deathdate
        xml.at_xpath('pgterms:agent/pgterms:deathdate').text
      end

      def webpage
        xml.at_xpath('pgterms:agent/pgterms:webpage').attribute('resource').content
      end

      def aliases
        entries = Array.new
        xml.xpath('//pgterms:alias').each do |name|
          entries << name.text
        end
        entries
      end

    private

      def name_parts
        parts = xml.xpath('//pgterms:name').text.split(/, */)
        last  = parts.shift
        first = parts.reverse.join(' ')

        {first: first, last: last}
      end

{'fraction_non_alphanumeric': 0.11922753988245172, 'fraction_numerical': 0.0008396305625524769, 'mean_word_length': 1.8745476477683956, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 20}, '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': '4307818', 'n_tokens_mistral': 784, 'n_tokens_neox': 732, 'n_words': 145}