<commit_before>package daytwo

import scala.io

//exercise two - Write a censor trait
trait Censor {

  val curses = Map("(?i)shoot" -> "Pucky", "(?i)darn" -> "Beans")

  def replace(string: String): String = {
    var politePhrase = string

    curses.foreach(curse =>
      politePhrase = politePhrase.replaceAll(curse._1, curse._2)
    )

    politePhrase
  }
}

//exercise three - load the curses from a file
trait BetterCensor {

  def betterReplace(string: String): String = {
    val lines = io.Source.fromFile("src/daytwo/curses.txt").mkString

    val betterCurses = collection.mutable.Map[String, String]()

    lines.split("\n").foreach(line => {
      betterCurses.put(line.split(",")(0), line.split(",")(1))
    })

    betterCurses.foreach((curse: (String, String)) => println(curse._1 + " -> " +curse._2))
    var politePhrase = string

    println(politePhrase)
    betterCurses.foreach(curse => {
      politePhrase = politePhrase.replaceAll(curse._1, curse._2)
      println(curse._1)
      println(curse._2)
      println(politePhrase)
    })
    politePhrase
  }

}

/**
 * Addendum leading up to day two exercises.
 */
class Scrap extends Censor with BetterCensor {

  def run() {

    val cursePhrase = "shoot, why did I ever do all that blasted darning"
    println(replace(cursePhrase))

    println(betterReplace(cursePhrase))
  }

  def anonFunctions() = {
    val list = List("Guts man", "Bubble man", "Proto man")
    list.foreach(man => println(man)) //anonymous functions are pretty neat
    println()
    list.init.foreach(man => println(man))<commit_msg>Finishes day two of Scala.<commit_after>package daytwo

//exercise two - Write a censor trait
trait Censor {

  val curses = Map("(?i)shoot" -> "Pucky", "(?i)darn" -> "Beans")

  def replace(string: String): String = {
    var politePhrase = string

    curses.foreach(curse =>
      politePhrase = politePhrase.replaceAll(curse._1, curse._2)
    )

    politePhrase
  }
}

//exercise three - load the curses from a file
trait BetterCensor {

  def betterReplace(string: String): String = {
    val lines = io.Source.fromFile("src/daytwo/curses.txt").mkString

    var betterCurses = Map.empty[String, String]

    lines.split("\n").foreach(line => {
      betterCurses += line.split(",")(0) -> line.split(",")(1).trim
    })

    betterCurses.foreach((curse: (String, String)) => println(curse._1 + " -> " +curse._2))
    var politePhrase = string

    betterCurses.foreach(curse => politePhrase = politePhrase.replace(curse._1, curse._2))
    politePhrase
  }

}

/**
 * Addendum leading up to day two exercises.
 */
class Scrap extends Censor with BetterCensor {

  def run() {

    val cursePhrase = "shoot, why did I ever do all that blasted darning"
    //println(replace(cursePhrase))

    println(betterReplace(cursePhrase))
  }

  def anonFunctions() = {
    val list = List("Guts man", "Bubble man", "Proto man")
    list.foreach(man => println(man)) //anonymous functions are pretty neat
    println()
    list.init.foreach(man => println(man))
{'fraction_non_alphanumeric': 0.1400854981913844, 'fraction_numerical': 0.00591910555738244, 'mean_word_length': 3.351931330472103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '2815633', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1012, 'n_words': 238}