<commit_before>###
@providesModule DirTree
###

objectAssign = require 'object-assign'
merge = require 'lodash.merge'


###
Construt tree formed object by analizing the name of
the global class in typedoc json.

@param {object} json object converted from typedoc

Construct dir_tree like below.

-- path
a/file1 obj1
a/b/file2 obj2

-- routes
{
  dir: {
    a: {
      dir: {
        b: {
          file: {
            class2: obj2
          }
        }
      },
      file: {
        class1: obj1
      }
    }
  }
}
###
class DirTree
  constructor: (json) ->
    @dir_tree = constructDirTree(json)

  ###
  construct tree formed object from docs json

  @api public
  ###
  gen: (json) ->
    @dir_tree = constructDirTree(json)

  ###
  construct tree formed object from docs json

  @api private
  ###
  constructDirTree = (json) ->
    dir_tree = {}
    json?.children?.forEach (child, i) ->
      arr = child.name.replace(/"/g, '').split('/')
      dir_tree = merge {}, dir_tree, arrayToDirTree(arr, child)
    return dir_tree

  ###
  construct no branched tree recursively by array

  @param {array} construct nested hash by following this
  @param {any} the top of nested hash
  @api private
  ###
  arrayToDirTree = (arr, top, def_arr) ->
    res = {}
    unless def_arr?
      res.path = []
    else
      res.path = def_arr[0..(-(arr.length + 1))]
    if arr.length == 1
      res.file = {}
      top.children?.forEach (gchild) ->
        res.file[gchild.name] =
          name: gchild.name
          kindString: gchild.kindString
          path: (def_arr ? arr)[0..-2].concat [gchild.name]
    else
      res.dir = {}
      res.dir[arr[0]] = arrayToDirTree(arr[1..-1], top, def_arr ? arr)
    return res

module.exports = DirTree<commit_msg>:arrow_up: add children in object<commit_after>###
@providesModule DirTree
###

objectAssign = require 'object-assign'
merge = require 'lodash.merge'


###
Construt tree formed object by analizing the name of
the global class in typedoc json.

@param {object} json object converted from typedoc

Construct dir_tree like below.

-- path
a/file1 obj1
a/b/file2 obj2

-- routes
{
  dir: {
    a: {
      dir: {
        b: {
          file: {
            class2: obj2
          }
        }
      },
      file: {
        class1: obj1
      }
    }
  }
}
###
class DirTree
  constructor: (json) ->
    @dir_tree = constructDirTree(json)

  ###
  construct tree formed object from docs json

  @api public
  ###
  gen: (json) ->
    @dir_tree = constructDirTree(json)

  ###
  construct tree formed object from docs json

  @api private
  ###
  constructDirTree = (json) ->
    dir_tree = {}
    json?.children?.forEach (child, i) ->
      arr = child.name.replace(/"/g, '').split('/')
      dir_tree = merge {}, dir_tree, arrayToDirTree(arr, child)
    return dir_tree

  ###
  construct no branched tree recursively by array

  @param {array} construct nested hash by following this
  @param {any} the top of nested hash
  @api private
  ###
  arrayToDirTree = (arr, top, def_arr) ->
    res = {}
    unless def_arr?
      res.path = []
    else
      res.path = def_arr[0..(-(arr.length + 1))]
    if arr.length == 1
      res.file = {}
      top.children?.forEach (gchild) ->
        res.file[gchild.name] =
          name: gchild.name
          kindString: gchild.kindString
          path: (def_arr ? arr)[0..-2].concat [gchild.name]
          children: (gchild.children || []).map((ggchild) -> {name: ggchild.name, kindString: ggchild.kindString})
    else
      res.dir = {}
      res.dir[arr[0]] = arrayToDirTree(arr[1..-1], top, def_arr ? arr)
    return res

module.exports = DirTree
{'fraction_non_alphanumeric': 0.13402911288107663, 'fraction_numerical': 0.008788794287283713, 'mean_word_length': 2.3079019073569484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '4729434', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1202, 'n_words': 324}