<commit_before># Copyright 2014-2015 <NAME> 
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

require 'net/http'
require 'uri'
require 'json'

class OvhApi

  def initialize()
    @references = Hash.new()
  end

  def set_data(json)
    # Erase previous informations 
    @references = Hash.new()

    # Parse answer
    data = JSON.parse(json)

    if data == nil
      raise JSON::JSONError, 'No data.'
    end

    # Look for 'answer' subsection
    if !data.include?('answer')
      raise JSON::JSONError, 'No section \'answer\'.'
    end

    # Look for 'availability' subsection
    if !data['answer'].include?('availability')
      raise JSON::JSONError, 'No subsection \'availability\' in section \'answer\'.'
    end

    # Run through each avilability section
    availability_sections = data['answer']['availability']

    availability_sections.each { |availability_section|
      # Look for reference subsection
      if !availability_section.include?('reference')
        raise JSON::JSONError, 'No \'reference\' in \'availability\' subsection.'
      end

      # Look for zones subsection
      if !availability_section.include?('zones')
        raise JSON::JSONError, 'No \'zones\' specified in \'availability\' subsection.'
      end
<commit_msg>Add check for nul answer<commit_after># Copyright 2014-2015 <NAME> 
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

require 'json'

class OvhApi

  def initialize()
    @references = Hash.new()
  end

  def set_data(json)
    # Erase previous informations 
    @references = Hash.new()

    # Parse answer
    data = JSON.parse(json)

    if data == nil
      raise JSON::JSONError, 'No data.'
    end

    # Look for 'answer' subsection
    if !data.include?('answer')
      raise JSON::JSONError, 'No section \'answer\'.'
    end

    # Check if the answer is valid
    if !data['answer'] == nil
      raise JSON::JSONError, "Subsection answer is null. Returned data: '#{data}'."
    end

    # Look for 'availability' subsection
    if !data['answer'].include?('availability')
      raise JSON::JSONError, 'No subsection \'availability\' in section \'answer\'.'
    end

    # Run through each avilability section
    availability_sections = data['answer']['availability']

    availability_sections.each { |availability_section|
      # Look for reference subsection
      if !availability_section.include?('reference')
        raise JSON::JSONError, 'No \'reference\' in \'availability\' subsection.'
      end

      # Look for zones subsection
      if !availability_section.include?('zones')
        raise JSON::JSONError, 'No \'zones\' specified in \'availability\' subsection.'
      end

{'fraction_non_alphanumeric': 0.10355987055016182, 'fraction_numerical': 0.006472491909385114, 'mean_word_length': 3.1395089285714284, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7091565', 'n_tokens_mistral': 1059, 'n_tokens_neox': 979, 'n_words': 377}