<commit_before># Copyright (c) 2016, Regents of the University of Michigan.
# All rights reserved. See LICENSE.txt for details.

module UmlautThreeSixtyLink
  module Client
    class Agent
      def initialize(base_url, open_timeout, read_timeout)
        @base_url     = base_url
        @open_timeout = open_timeout
        @read_timeout = read_timeout
      end

      def get_direct_link(co)
        if co.referent.metadata['link_model'] == 'DirectLink'
          lg = LinkGroup.new
          lg.urls.direct_link = co.referent.metadata['link']
          lg
        end
      end

      def handle(_, context_object)
        transport = OpenURL::Transport.new(
          @base_url,
          context_object,
          open_timeout: @open_timeout,
          read_timeout: @read_timeout
        )
        direct_link = get_direct_link(context_object)
        transport.extra_args['version'] = '1.0'
        transport.get
        record_list = RecordList.from_xml(transport.response)

        if direct_link
          if record_list.empty?
            # TODO: Create an empty record, and attach the direct_link to it.
          elsif record_list.link?
            record_list.each do |record|
              if record.link?
                record.links.unshift(direct_link)
                break
              end
            end
          else
            record_list.first.links.unshift(direct_link)
          end
        end

        record_list
      end
    end
  end
end
<commit_msg>Adding a source / source link for faux iedls.<commit_after># Copyright (c) 2016, Regents of the University of Michigan.
# All rights reserved. See LICENSE.txt for details.

module UmlautThreeSixtyLink
  module Client
    class Agent
      def initialize(base_url, open_timeout, read_timeout)
        @base_url     = base_url
        @open_timeout = open_timeout
        @read_timeout = read_timeout
      end

      def get_direct_link(co)
        if co.referent.metadata['link_model'] == 'DirectLink'
          lg = LinkGroup.new
          lg.urls.direct_link = co.referent.metadata['link']
          lg.urls.source = co.referent.metadata['link']
          lg.holdings.database_name = 'Link provided by Summon'
          lg
        end
      end

      def handle(_, context_object)
        transport = OpenURL::Transport.new(
          @base_url,
          context_object,
          open_timeout: @open_timeout,
          read_timeout: @read_timeout
        )
        direct_link = get_direct_link(context_object)
        transport.extra_args['version'] = '1.0'
        transport.get
        record_list = RecordList.from_xml(transport.response)

        if direct_link
          if record_list.empty?
            # TODO: Create an empty record, and attach the direct_link to it.
          elsif record_list.link?
            record_list.each do |record|
              if record.link?
                record.links.unshift(direct_link)
                break
              end
            end
          else
            record_list.first.links.unshift(direct_link)
          end
        end

        record_list
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.07033248081841433, 'fraction_numerical': 0.0038363171355498722, 'mean_word_length': 1.849726775956284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '402659', 'n_tokens_mistral': 898, 'n_tokens_neox': 869, 'n_words': 212}