<commit_before>package org.tribbloid.spookystuff.repl

import org.apache.spark.repl.SparkILoop
import org.apache.spark.sql.SQLContext
import org.tribbloid.spookystuff.SpookyContext

import scala.collection.immutable
import scala.tools.nsc.interpreter._

class SpookyILoop extends SparkILoop {

  private val postInitScript =
    "import scala.concurrent.duration._" ::
      "import org.tribbloid.spookystuff.actions._" ::
      "import org.tribbloid.spookystuff.factory.driver._" ::
      "import org.tribbloid.spookystuff.expressions._" ::
      "import org.tribbloid.spookystuff.SpookyContext" ::
      "import sql._" ::
      "import spooky._" ::
      Nil

  override protected def postInitialization() {
    super.postInitialization()
    this.beQuietDuring {
      val sql = new SQLContext(this.sparkContext)
      val sqlParam = NamedParam[SQLContext]("sql", sql)
      intp.bind(sqlParam.name, sqlParam.tpe, sqlParam.value, immutable.List("@transient")) match {
        case IR.Success =>
        case _ => throw new RuntimeException("SQL failed to initialize")
      }

      val spooky = new SpookyContext(sql)
      val spookyParam = NamedParam[SpookyContext]("spooky", spooky)
      intp.bind(spookyParam.name, spookyParam.tpe, spookyParam.value, immutable.List("@transient")) match {
        case IR.Success =>
        case _ => throw new RuntimeException("SpookyContext failed to initialize")
      }

      postInitScript.foreach(command)
    }
  }

  override def prompt: String = "spooky> "

  override def printWelcome(): Unit = {
    echo(
      """
        |      ____                / /<commit_msg>spooky is now defined in postInitScript<commit_after>package org.tribbloid.spookystuff.repl

import org.apache.spark.repl.SparkILoop
import org.apache.spark.sql.SQLContext

import scala.collection.immutable
import scala.tools.nsc.interpreter.{Results, NamedParam}

class SpookyILoop extends SparkILoop {

  private val postInitScript =
    "import scala.concurrent.duration._" ::
      "import org.tribbloid.spookystuff.actions._" ::
      "import org.tribbloid.spookystuff.factory.driver._" ::
      "import org.tribbloid.spookystuff.expressions._" ::
      "import org.tribbloid.spookystuff.SpookyContext" ::
      "val spooky = new SpookyContext(sql)" ::
      "import spooky._" ::
      Nil

  override protected def postInitialization() {
    super.postInitialization()
    this.beQuietDuring {
      val sql = new SQLContext(this.sparkContext)
      val sqlParam = NamedParam[SQLContext]("sql", sql)
      intp.bind(sqlParam.name, sqlParam.tpe, sqlParam.value, immutable.List("@transient")) match {
        case Results.Success =>
        case _ => throw new RuntimeException("SQL failed to initialize")
      }

      postInitScript.foreach(command)
    }
  }

  override def prompt: String = "spooky> "

  override def printWelcome(): Unit = {
    echo(
      """
        |      ____                / /
{'fraction_non_alphanumeric': 0.11023890784982936, 'fraction_numerical': 0.0, 'mean_word_length': 3.139830508474576, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '6441015', 'n_tokens_mistral': 956, 'n_tokens_neox': 930, 'n_words': 174}