<commit_before>module Bioportal

  class API
    include Singleton
    class_attribute :apikey

    BASE_URI = 'http://data.bioontology.org/'

    def ontologies
      get 'ontologies'
    end

    def ontology_resource(acronym, resource_name)
      get "ontologies/#{acronym}/#{resource_name}"
    end

    def ontology_filename(acronym)
      response = head "ontologies/#{acronym}/download"
      response.headers[:content_disposition].match(/filename="(.+)"/)[1]
    rescue RestClient::ResourceNotFound
      nil # no filename
    end

    def download_ontology(acronym, submission_id, file)
      output = nil
      url    = "#{BASE_URI}ontologies/#{acronym}/submissions/#{submission_id}/download"
      args   = 'curl', url,
        '--header', "Authorization: #{authorization}",
        '--output', file.to_s,
        '--silent',
        '--fail',
        '--show-error'

      # run it and save stderr and stdout in output<commit_msg>Ignore RestClient::Forbidden in ontology_filename.<commit_after>module Bioportal

  class API
    include Singleton
    class_attribute :apikey

    BASE_URI = 'http://data.bioontology.org/'

    def ontologies
      get 'ontologies'
    end

    def ontology_resource(acronym, resource_name)
      get "ontologies/#{acronym}/#{resource_name}"
    end

    def ontology_filename(acronym)
      response = head "ontologies/#{acronym}/download"
      response.headers[:content_disposition].match(/filename="(.+)"/)[1]
    rescue RestClient::ResourceNotFound, RestClient::Forbidden
      nil # no filename
    end

    def download_ontology(acronym, submission_id, file)
      output = nil
      url    = "#{BASE_URI}ontologies/#{acronym}/submissions/#{submission_id}/download"
      args   = 'curl', url,
        '--header', "Authorization: #{authorization}",
        '--output', file.to_s,
        '--silent',
        '--fail',
        '--show-error'

      # run it and save stderr and stdout in output
{'fraction_non_alphanumeric': 0.12654320987654322, 'fraction_numerical': 0.00102880658436214, 'mean_word_length': 2.859126984126984, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7446025', 'n_tokens_mistral': 613, 'n_tokens_neox': 593, 'n_words': 125}