<commit_before>object Main extends App {
  val data =
    """
      |{"menu": {
      |  "id": "file",
      |  "value": "File",
      |  "popup": {
      |    "menuitem": [
      |      {"value": "New", "onclick": "CreateNewDoc()"},
      |      {"value": "Open", "onclick": "OpenDoc()"},
      |      {"value": "Close", "onclick": "CloseDoc()"}
      |    ]
      |  }
      |}}
    """.stripMargin
  println(js2Java.generate(data, "JsRoot"))
}<commit_msg>read arg from commandline<commit_after>object Main extends App {
  val data =
    """
      |{"menu": {
      |  "id": "file",
      |  "value": "File",
      |  "popup": {
      |    "menuitem": [
      |      {"value": "New", "onclick": "CreateNewDoc()"},
      |      {"value": "Open", "onclick": "OpenDoc()"},
      |      {"value": "Close", "onclick": "CloseDoc()"}
      |    ]
      |  }
      |}}
    """.stripMargin
  args.length match {
    case 0 =>
      println("No arg provided. Using demo data...")
      println(data)
      println(js2Java.generate(data, "JsRoot"))
      println("Please supply a json file name or url as argument.")
    case 1 =>
      val arg: String = args.head
      if (arg.startsWith("http://") || arg.startsWith("https://")) {
        val data = io.Source.fromURL(arg).mkString
        printJava(js2Java.generate(data, "JsRoot"), s"Invalid json fetched from url: $arg\n${data.take(500)}")
      } else {
        println("Need to handle this case.")
      }

  }

  def printJava(java: List[(String, String)], message: String): Unit = {
    try {
      java.map(_._2).foreach(println)
    } catch {
      case ex: Throwable => println(message)
    }
  }
}
{'fraction_non_alphanumeric': 0.1973365617433414, 'fraction_numerical': 0.005447941888619854, 'mean_word_length': 2.1727447216890594, 'pattern_counts': {'":': 22, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 1, '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': '3188463', 'n_tokens_mistral': 560, 'n_tokens_neox': 551, 'n_words': 120}