<commit_before>module ChordParser exposing (Model, init, update, view)

import Highlight exposing (Highlight)
import Substring exposing (Substring)

import Regex exposing (Regex, HowMany(..), Match)

type alias Model = List Substring

init : List Substring -> Model
init = parse

update : List Substring -> Model -> Model
update chordRanges model =
  init chordRanges

view : Model -> List Highlight
view = List.filterMap viewSubstring

parse : List Substring -> Model
parse = List.concatMap parseLine

parseLine : Substring -> List Substring
parseLine = Substring.regexSplit All (Regex.regex " +")

viewSubstring : Substring -> Maybe Highlight
viewSubstring substring =
  let
    fg =
      case substring.s of
        "Bo" -> "#ffffff"
        _ -> "#000000"
  in let
    bg =
      case substring.s of
        "C" -> "#f8facd"
        "Dm" -> "#eccdfa"
        "Em" -> "#d2facd"
        "F" -> "#facdcd"
        "G" -> "#c9ffff"
        "Am" -> "#ffe7c9"
        "Bo" -> "#005e93"
        _ -> "#ffffff"
  in
    case ( fg, bg ) of
      ( "#000000", "#ffffff" ) -> Nothing
      _ -> Just (Highlight.fromSubstring fg bg substring)<commit_msg>actually parse chords<commit_after>module ChordParser exposing (Model, init, update, view)

import Chord exposing (Chord)
import Highlight exposing (Highlight)
import Substring exposing (Substring)

import Regex exposing (Regex, HowMany(..), Match)

type alias Model = List ChordResult

init : List Substring -> Model
init = parse

update : List Substring -> Model -> Model
update chordRanges model =
  init chordRanges

view : Model -> List Highlight
view = List.filterMap viewChordResult

parse : List Substring -> Model
parse = List.concatMap parseLine

parseLine : Substring -> List ChordResult
parseLine = List.map parseChord << Substring.regexSplit All (Regex.regex " +")

type alias ChordResult =
  { substring : Substring
  , chord : Maybe Chord
  }

parseChord : Substring -> ChordResult
parseChord word =
  { substring = word
  , chord = Chord.fromRawName word.s
  }

viewChordResult : ChordResult -> Maybe Highlight
viewChordResult chordResult =
  case chordResult.chord of
    Nothing ->
      Nothing
    Just c ->
      Just
        ( Highlight.fromSubstring
            (Chord.fg c)
            (Chord.bg c)
            chordResult.substring
        )
{'fraction_non_alphanumeric': 0.10294117647058823, 'fraction_numerical': 0.009515570934256055, 'mean_word_length': 2.9269949066213923, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '2087567', 'n_tokens_mistral': 745, 'n_tokens_neox': 704, 'n_words': 221}