<commit_before>class GraphsController < InheritedResources::Base

  respond_to :json, :html
  belongs_to :logic, :ontology, :single_ontology, :distributed_ontology, polymorphic: true

  def index
    respond_to do |format|
      @ontology = parent if parent.is_a?(Ontology)
      @depth = params[:depth] ? params[:depth].to_i : 3
      format.html
      format.json do
        fetcher = GraphDataFetcher.new(center: parent, depth: @depth)
        nodes, edges = fetcher.fetch
        nodes_aggregate = nodes.reduce({}) do |mem, node|
          mem[node.id] = node.aggregate
          mem
        end
        # edges_aggregate = edges.reduce({}) do |mem, edge|
        #   mem[edge.id] = edge.aggregate
        #   mem
        # end
        chain = resource_chain
        if chain.empty?
          chain << nodes.first.class
        else
          chain[-1] = nodes.first.class
        end
        data = {nodes: nodes,
                edges: edges,
                center: parent,
                node_url: nodes.any? ? url_for(chain) : nil,
                edge_url: edges.any? ? url_for(edges.first.class) : nil,
                edge_type: GraphDataFetcher.link_for(nodes.first.class),
                nodes_aggregate: nodes_aggregate }
        respond_with data
      end
    end
  end

end<commit_msg>fix graph-fetching for empty graph.<commit_after>class GraphsController < InheritedResources::Base

  respond_to :json, :html
  belongs_to :logic, :ontology, :single_ontology, :distributed_ontology, polymorphic: true

  def index
    respond_to do |format|
      @ontology = parent if parent.is_a?(Ontology)
      @depth = params[:depth] ? params[:depth].to_i : 3
      format.html
      format.json do
        fetcher = GraphDataFetcher.new(center: parent, depth: @depth)
        nodes, edges = fetcher.fetch
        nodes_aggregate = nodes.reduce({}) do |mem, node|
          mem[node.id] = node.aggregate
          mem
        end
        # edges_aggregate = edges.reduce({}) do |mem, edge|
        #   mem[edge.id] = edge.aggregate
        #   mem
        # end
        chain = resource_chain
        if chain.empty?
          chain << nodes.first.class
        else
          chain[-1] = nodes.first.class
        end
        data = {nodes: nodes,
                edges: edges,
                center: parent,
                node_url: nodes.any? ? url_for(chain) : nil,
                edge_url: edges.any? ? url_for(edges.first.class) : nil,
                edge_type: GraphDataFetcher.link_for(parent.class),
                nodes_aggregate: nodes_aggregate }
        respond_with data
      end
    end
  end

end
{'fraction_non_alphanumeric': 0.09935287400076133, 'fraction_numerical': 0.0015226494099733537, 'mean_word_length': 1.9728506787330318, 'pattern_counts': {'":': 0, '<': 9, '<?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': '1768917', 'n_tokens_mistral': 816, 'n_tokens_neox': 783, 'n_words': 183}