<commit_before>((root, factory) ->
  if typeof define is 'function' and define.amd
    define ['underscore'], (_) ->
      factory root, _
  else
    root.Scribe = factory root, root._
) @, (root, _) ->

  class Scribe

    ###*
     * @param {Object} translations
     * @param {string} placeholder The string that specifies a replacement
     * @constructor
    ###
    constructor: (@translations, @placeholder = ':') ->

    ###*
     * Check to see if the translation exists.
     * @see @get
     * @return {boolean}
    ###
    has: (translation) ->
      @get(translation) isnt translation

    ###*
     * Get a translation by key.
     * @param  {string} translation The key where the translation is located
     * @param  {Object} replacements
     * @return {string}
    ###
    get: (translation, replacements = {}) ->
      line = @makeReplacements(@getLine(translation), replacements) or translation

    ###*
     * Get the line from the translations.
     * @return {string} The line from @translations or the translation location
    ###
    getLine: (translation) ->
      _.reduce translation.split('.'), (segment, property) ->
        segment?[property]
      , @translations

    ###*
     * Make place-holder replacements.
     * @param  {string} line
     * @param  {Object} replacements
     * @return {Object}
    ###
    makeReplacements: (line, replacements) ->
      return unless line

      replacements = @sortReplacements replacements

      _.each replacements, (value, key) ->
        # If it is an array then we will go over the line with each item in the array
        # replacing each occurence of the placeholder with the current array item.
        if _.isArray(value)
          line = _.reduce value, (line, val) =>
            line.replace "#{@placeholder}#{key}", val
          , line
        else
          line = line.replace new RegExp("#{@placeholder}#{key}", 'g'), value
      , @

      line

    ###*
     * Sort the replacements by length first, so that we don't replace a partial key first. For example
     * if we did not do this the placeholder ":foobar" would conflict with the placeholder ":foo"
     * @param  {Object} replacements
     * @return {Object}
    ###
    sortReplacements: (replacements) ->
      sorted = {}

      _.chain replacements
        .keys()
        .sortBy (replacement) ->
          replacement.length * -1
        .each (placeholder) ->
          sorted[placeholder] = replace[placeholder]

      sorted<commit_msg>Fixed incorrect variable access<commit_after>((root, factory) ->
  if typeof define is 'function' and define.amd
    define ['underscore'], (_) ->
      factory root, _
  else
    root.Scribe = factory root, root._
) @, (root, _) ->

  class Scribe

    ###*
     * @param {Object} translations
     * @param {string} placeholder The string that specifies a replacement
     * @constructor
    ###
    constructor: (@translations, @placeholder = ':') ->

    ###*
     * Check to see if the translation exists.
     * @see @get
     * @return {boolean}
    ###
    has: (translation) ->
      @get(translation) isnt translation

    ###*
     * Get a translation by key.
     * @param  {string} translation The key where the translation is located
     * @param  {Object} replacements
     * @return {string}
    ###
    get: (translation, replacements = {}) ->
      line = @makeReplacements(@getLine(translation), replacements) or translation

    ###*
     * Get the line from the translations.
     * @return {string} The line from @translations or the translation location
    ###
    getLine: (translation) ->
      _.reduce translation.split('.'), (segment, property) ->
        segment?[property]
      , @translations

    ###*
     * Make place-holder replacements.
     * @param  {string} line
     * @param  {Object} replacements
     * @return {Object}
    ###
    makeReplacements: (line, replacements) ->
      return unless line

      replacements = @sortReplacements replacements

      _.each replacements, (value, key) ->
        # If it is an array then we will go over the line with each item in the array
        # replacing each occurence of the placeholder with the current array item.
        if _.isArray(value)
          line = _.reduce value, (line, val) =>
            line.replace "#{@placeholder}#{key}", val
          , line
        else
          line = line.replace new RegExp("#{@placeholder}#{key}", 'g'), value
      , @

      line

    ###*
     * Sort the replacements by length first, so that we don't replace a partial key first. For example
     * if we did not do this the placeholder ":foobar" would conflict with the placeholder ":foo"
     * @param  {Object} replacements
     * @return {Object}
    ###
    sortReplacements: (replacements) ->
      sorted = {}

      _.chain replacements
        .keys()
        .sortBy (replacement) ->
          replacement.length * -1
        .each (placeholder) ->
          sorted[placeholder] = replacements[placeholder]

      sorted
{'fraction_non_alphanumeric': 0.11945052757316345, 'fraction_numerical': 0.00039816842524387816, 'mean_word_length': 2.3763440860215055, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 31, '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': '2924571', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1345, 'n_words': 460}