<commit_before>opensong = opensong || {}
opensong.helper = opensong.helper || {}

###

json = [
  {
    header: "V",
    lines: [
      {
        chords: ["A", "C"],
        lyrics: [
          ["Yeah", "Yeah, God is great!"]
        ]
      },
      {
        comments: "This is a comment"
      }
    ]
  }
]

###
opensong.helper.parseLyrics = (lyrics) ->
  lyrics = lyrics.replace /\r\n?]/, '\n'
  lyricsLines = lyrics.split("\n")

  dataModel = []
  dataObject =
    header: undefined
    lines: []
  dataModel.push dataObject

  while lyricsLines.length > 0
    line = lyricsLines.shift()

    continue unless line?

    switch line[0]
      # header
      when "["
        # add new object if current is "used"
        if dataObject.lines.length > 0
          dataObject =
            header: undefined
            lines: []
          dataModel.push dataObject

        header = line.match(/\[(.*)\]/)[1]
        dataObject.header = header

      # chords (with lyrics)
      when "."
        chordsLine = line.substr(1)
        chordArr = []

        # split cords
        while chordsLine.length > 0
          m = /^(\S*\s*)(.*)$/.exec(chordsLine)
          chordArr.push m[1]
          chordsLine = m[2]
        # add an item if it is an empty line
        chordArr.push chordsLine if chordArr.length is 0

        # clean Chord line from trailing white spaces
        chordArrCleaned = []
        chordArr.forEach (value) ->
          m = /(\S*\s?)\s*/.exec(value)
          chordArrCleaned.push m[1]
<commit_msg>fix parsing in node (?)<commit_after>opensong = opensong || {}
opensong.helper = opensong.helper || {}

###

json = [
  {
    header: "V",
    lines: [
      {
        chords: ["A", "C"],
        lyrics: [
          ["Yeah", "Yeah, God is great!"]
        ]
      },
      {
        comments: "This is a comment"
      }
    ]
  }
]

###
opensong.helper.parseLyrics = (lyrics) ->
  lyrics = lyrics.replace /\r\n?]/, '\n'
  lyricsLines = lyrics.split("\n")

  dataModel = []
  dataObject =
    header: undefined
    lines: []
  dataModel.push dataObject

  while lyricsLines.length > 0
    line = lyricsLines.shift()

    continue unless line?

    switch line[0]
      # header
      when "["
        # add new object if current is "used"
        if dataObject.lines.length > 0
          dataObject =
            header: undefined
            lines: []
          dataModel.push dataObject

        header = line.match(/\[(.*)\]/)[1]
        dataObject.header = header

      # chords (with lyrics)
      when "."
        chordsLine = line.substr(1)
        chordArr = []

        # split cords
        while chordsLine.length > 0
          m = /^(\S*\s*)(.*)/.exec(chordsLine)
          chordArr.push m[1]
          chordsLine = m[2]
        # add an item if it is an empty line
        chordArr.push chordsLine if chordArr.length is 0

        # clean Chord line from trailing white spaces
        chordArrCleaned = []
        chordArr.forEach (value) ->
          m = /(\S*\s?)\s*/.exec(value)
          chordArrCleaned.push m[1]

{'fraction_non_alphanumeric': 0.13747954173486088, 'fraction_numerical': 0.006546644844517185, 'mean_word_length': 1.6972639011473962, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '2614591', 'n_tokens_mistral': 997, 'n_tokens_neox': 967, 'n_words': 236}