<commit_before>_ = require("underscore")
_s = require("underscore.string")
noflo = require("noflo")

class GroupBy extends noflo.Component

  description: "`groupBy` in Underscore.js"

  constructor: ->
    @inPorts =
      in: new noflo.Port
      property: new noflo.Port
    @outPorts =
      out: new noflo.Port

    @inPorts.property.on "data", (@property) =>

    @inPorts.in.on "connect", =>
      @objects = []

    @inPorts.in.on "begingroup", (group) =>
      @outPorts.out.beginGroup group

    @inPorts.in.on "data", (object) =>
      @objects.push object

    @inPorts.in.on "endgroup", (group) =>
      @flush()
      @outPorts.out.endGroup()

    @inPorts.in.on "disconnect", =>
      @flush()
      @outPorts.out.disconnect()

  flush: ->
    return if _.isEmpty @objects
    @outPorts.out.send _.groupBy @objects, @property
    @objects = []

exports.getComponent = -> new GroupBy<commit_msg>Only group objects<commit_after>_ = require("underscore")
_s = require("underscore.string")
noflo = require("noflo")

class GroupBy extends noflo.Component

  description: "`groupBy` in Underscore.js"

  constructor: ->
    @inPorts =
      in: new noflo.Port
      property: new noflo.Port
    @outPorts =
      out: new noflo.Port

    @inPorts.property.on "data", (@property) =>

    @inPorts.in.on "connect", =>
      @objects = []

    @inPorts.in.on "begingroup", (group) =>
      @outPorts.out.beginGroup group

    @inPorts.in.on "data", (object) =>
      @objects.push object

    @inPorts.in.on "endgroup", (group) =>
      @flush()
      @outPorts.out.endGroup()

    @inPorts.in.on "disconnect", =>
      @flush()
      @outPorts.out.disconnect()

  flush: ->
    return if _.isEmpty @objects

    if _.all @objects, _.isObject
      @outPorts.out.send _.groupBy @objects, @property

    @objects = []

exports.getComponent = -> new GroupBy
{'fraction_non_alphanumeric': 0.15368081676518, 'fraction_numerical': 0.0, 'mean_word_length': 2.807770961145194, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '4978549', 'n_tokens_mistral': 680, 'n_tokens_neox': 643, 'n_words': 133}