<commit_before>module ManBook
  class Parser
    class << self
      def parse(html_file)
        #
        # The way we extract the title is highly dependent of the concrete HTML. Yet, I found no other way
        # to extract the title of a man page ín a reliable way.
        #
        doc = Nokogiri::HTML(File.read(html_file))
        
        title = doc.xpath("//b[text() = 'NAME']/../following-sibling::p[1]/descendant-or-self::text()").to_s 
        
        if title.empty?
          title = doc.xpath("//h2[text() = 'NAME']/following-sibling::p[1]/descendant-or-self::text()").to_s
        end
        
        {:file_name => File.basename(html_file), :title => title.split("\n").join(' ')}
      end
    end
  end<commit_msg>Parse author info<commit_after>module ManBook
  class Parser
    class << self
      def parse(html_file)
        #
        # The way we extract the title is highly dependent of the concrete HTML. Yet, I found no other way
        # to extract the title of a man page ín a reliable way.
        #
        doc = Nokogiri::HTML(File.read(html_file))
        
        title = doc.xpath("//b[text() = 'NAME']/../following-sibling::p[1]/descendant-or-self::text()").to_s 
        
        if title.empty?
          title = doc.xpath("//h2[text() = 'NAME']/following-sibling::p[1]/descendant-or-self::text()").to_s
        end
        
        author = doc.xpath("//b[text() = 'AUTHORS']/../following-sibling::p[1]/descendant-or-self::text()").to_s

        if author.empty?
          author = doc.xpath("//h2[text() = 'AUTHORS']/following-sibling::p[1]/descendant-or-self::text()").to_s
        end

        {:file_name => File.basename(html_file), :title => title.split("\n").join(' '), :author => author.split("\n").join(' ')}
      end
    end
  end
{'fraction_non_alphanumeric': 0.1647982062780269, 'fraction_numerical': 0.005044843049327354, 'mean_word_length': 2.2752293577981653, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '473617', 'n_tokens_mistral': 592, 'n_tokens_neox': 587, 'n_words': 126}