<commit_before>require "set"

module JsonSchema
  class ReferenceExpander
    attr_accessor :errors

    def expand(schema)
      @errors = []
      @schema = schema
      @store = {}
      @unresolved_refs = Set.new
      last_num_unresolved_refs = 0

      loop do
        traverse_schema(schema)

        # nothing left unresolved, we're done!
        if @unresolved_refs.count == 0
          break
        end

        # a new traversal pass still hasn't managed to resolved anymore
        # references; we're out of luck
        if @unresolved_refs.count == last_num_unresolved_refs
          refs = @unresolved_refs.to_a.join(", ")
          message = %{Couldn't resolve references (possible circular dependency): #{refs}.}
          @errors << SchemaError.new(schema, message)
          break
        end

        last_num_unresolved_refs = @unresolved_refs.count
      end

      @errors.count == 0
    end

    def expand!(schema)
      if !expand(schema)
        raise SchemaError.aggregate(@errors)
      end
      true
    end

    private

    def dereference(schema)
      ref = schema.reference
      uri = ref.uri

      if uri && uri.host
        scheme = uri.scheme || "http"<commit_msg>*resolve (correct misspelling)<commit_after>require "set"

module JsonSchema
  class ReferenceExpander
    attr_accessor :errors

    def expand(schema)
      @errors = []
      @schema = schema
      @store = {}
      @unresolved_refs = Set.new
      last_num_unresolved_refs = 0

      loop do
        traverse_schema(schema)

        # nothing left unresolved, we're done!
        if @unresolved_refs.count == 0
          break
        end

        # a new traversal pass still hasn't managed to resolve anymore
        # references; we're out of luck
        if @unresolved_refs.count == last_num_unresolved_refs
          refs = @unresolved_refs.to_a.join(", ")
          message = %{Couldn't resolve references (possible circular dependency): #{refs}.}
          @errors << SchemaError.new(schema, message)
          break
        end

        last_num_unresolved_refs = @unresolved_refs.count
      end

      @errors.count == 0
    end

    def expand!(schema)
      if !expand(schema)
        raise SchemaError.aggregate(@errors)
      end
      true
    end

    private

    def dereference(schema)
      ref = schema.reference
      uri = ref.uri

      if uri && uri.host
        scheme = uri.scheme || "http"
{'fraction_non_alphanumeric': 0.08443163097199341, 'fraction_numerical': 0.002471169686985173, 'mean_word_length': 2.094267515923567, 'pattern_counts': {'":': 0, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4107979', 'n_tokens_mistral': 732, 'n_tokens_neox': 672, 'n_words': 185}