<commit_before>module Tome
  # Acts as a controller for building the fully-calculated graph.
  #
  # Loads the graph structure and attributes from the source files, calculates
  # the Rubel-based attributes, triggers the Refinery calculations, and
  # returns to results to you.
  class Runner
    attr_reader :dataset, :graph

    # Creates a Refinery catalyst which, given the initial Refinery graph,
    # will set the share values for any slots where a share is explicitly
    # specified, or calculated through a Rubel query.
    #
    # It expects to be called with a lambda telling the catalyst how to run
    # the Rubel query.
    #
    #   SetSlotShares.call(->(query) { runtime.execute(query) })
    #   # => #<TheRefineryCatalyst ...>
    #
    # Returns a lambda.
    SetSlotSharesFromDocuments = ->(perform) do
      ->(refinery) do
        Slot.all.each do |model|
          node     = refinery.node(model.node) || next
          node_doc = node.get(:model)
          coll     = node.slots.public_send(model.direction)

          if coll.include?(model.carrier)
            slot = coll.get(model.carrier)
          else
            # Loss slots frequently have no edges, so they won't have been
            # auto-created by Refinery.
            slot = coll.add(model.carrier)
          end

          if model.query
            slot.set(:share, perform.call(model.query))
          elsif model.share
            slot.set(:share, model.share)
          end
        end

        refinery
      end
    end # SetSlotSharesFromDocuments

    # Iterates through each node in the graph, converting the "efficiency"
    # attribute, if present, to the appropriate slot shares.
    #
    # Shares set by SetSlotSharesFromDocuments (i.e., those which are hard-
    # coded into the documents, or come from a Rubel calculation, are not
    # overwritten.
    SetSlotSharesFromEfficiency = ->(refinery) do
      refinery.nodes.each do |node|
        node.get(:model).efficiency.each do |carrier, share|
          if node.slots.out.include?(carrier)
            slot = node.slots.out.get(carrier)
          else
            slot = node.slots.out.add(carrier)
          end

          slot.set(:share, share) if slot.get(:share).nil?
        end
      end

      refinery
    end
<commit_msg>Do not set a share for loss slots<commit_after>module Tome
  # Acts as a controller for building the fully-calculated graph.
  #
  # Loads the graph structure and attributes from the source files, calculates
  # the Rubel-based attributes, triggers the Refinery calculations, and
  # returns to results to you.
  class Runner
    attr_reader :dataset, :graph

    # Creates a Refinery catalyst which, given the initial Refinery graph,
    # will set the share values for any slots where a share is explicitly
    # specified, or calculated through a Rubel query.
    #
    # It expects to be called with a lambda telling the catalyst how to run
    # the Rubel query.
    #
    #   SetSlotShares.call(->(query) { runtime.execute(query) })
    #   # => #<TheRefineryCatalyst ...>
    #
    # Returns a lambda.
    SetSlotSharesFromDocuments = ->(perform) do
      ->(refinery) do
        Slot.all.each do |model|
          node     = refinery.node(model.node) || next
          node_doc = node.get(:model)
          coll     = node.slots.public_send(model.direction)

          if coll.include?(model.carrier)
            slot = coll.get(model.carrier)
          else
            # Loss slots frequently have no edges, so they won't have been
            # auto-created by Refinery.
            slot = coll.add(model.carrier)
          end

          if model.query
            slot.set(:share, perform.call(model.query))
          elsif model.share
            slot.set(:share, model.share)
          end
        end

        refinery
      end
    end # SetSlotSharesFromDocuments

    # Iterates through each node in the graph, converting the "efficiency"
    # attribute, if present, to the appropriate slot shares.
    #
    # Shares set by SetSlotSharesFromDocuments (i.e., those which are hard-
    # coded into the documents, or come from a Rubel calculation, are not
    # overwritten.
    SetSlotSharesFromEfficiency = ->(refinery) do
      refinery.nodes.each do |node|
        node.get(:model).efficiency.each do |carrier, share|
          if node.slots.out.include?(carrier)
            slot = node.slots.out.get(carrier)
          else
            slot = node.slots.out.add(carrier)
          end

          if slot.get(:share).nil? && share.to_s != 'elastic'
            slot.set(:share, share)
          end
        end
      end

      refinery
    end

{'fraction_non_alphanumeric': 0.0842443729903537, 'fraction_numerical': 0.0, 'mean_word_length': 2.135752688172043, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '3579512', 'n_tokens_mistral': 1348, 'n_tokens_neox': 1288, 'n_words': 430}