<commit_before>package controllers

import controllers.util.Messages
import org.globalnames.parser.ScientificNameParser
import play.api.Play.current
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.Messages.Implicits._
import play.api.libs.json.Json._
import play.api.libs.json._
import play.api.mvc._
import ScientificNameParser.{instance => snp}

object Application extends Controller {
  val searchForm = Form("names" -> nonEmptyText)

  private def handleNamesStrings(jsResult: JsResult[Seq[String]]) =
    jsResult match {
      case JsSuccess(ns, _) =>
        val result = ns.map { n =>
          Json.parse(snp.renderCompactJson(snp.fromString(n)))
        }
        Ok(obj(Messages.RESULT  -> Messages.RESULT_OK,
               Messages.DETAILS -> result))
      case e: JsError =>
        Ok(obj(Messages.RESULT  -> Messages.RESULT_ERROR,
               Messages.DETAILS -> e.errors.toString))
    }

  def index() = Action {
    Ok(views.html.index(searchForm))
  }

  def batchHandle() = Action(parse.form(searchForm)) { implicit rs =>
    val res = rs.body.split("\n")
                .map { name => snp.renderCompactJson(snp.fromString(name)) }
    Ok(views.html.index(searchForm, res))
  }

  def namesGetJson(names: String) = Action {
    val namesJS = Json.parse(names).validate[Seq[String]]
    handleNamesStrings(namesJS)
  }

  def namesPostJson() = Action(parse.json) { implicit rs =>
    val namesJS = rs.body.validate[Seq[String]]
    handleNamesStrings(namesJS)
  }
}<commit_msg>= remove artificial trailing space warning<commit_after>package controllers

import controllers.util.Messages
import org.globalnames.parser.ScientificNameParser
import play.api.Play.current
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.Messages.Implicits._
import play.api.libs.json.Json._
import play.api.libs.json._
import play.api.mvc._
import ScientificNameParser.{instance => snp}

object Application extends Controller {
  val searchForm = Form("names" -> nonEmptyText)

  private def handleNamesStrings(jsResult: JsResult[Seq[String]]) =
    jsResult match {
      case JsSuccess(ns, _) =>
        val result = ns.map { n =>
          Json.parse(snp.renderCompactJson(snp.fromString(n)))
        }
        Ok(obj(Messages.RESULT  -> Messages.RESULT_OK,
               Messages.DETAILS -> result))
      case e: JsError =>
        Ok(obj(Messages.RESULT  -> Messages.RESULT_ERROR,
               Messages.DETAILS -> e.errors.toString))
    }

  def index() = Action {
    Ok(views.html.index(searchForm))
  }

  def batchHandle() = Action(parse.form(searchForm)) { implicit rs =>
    val res = rs.body.split("\r\n")
                .map { name => snp.renderCompactJson(snp.fromString(name)) }
    Ok(views.html.index(searchForm, res))
  }

  def namesGetJson(names: String) = Action {
    val namesJS = Json.parse(names).validate[Seq[String]]
    handleNamesStrings(namesJS)
  }

  def namesPostJson() = Action(parse.json) { implicit rs =>
    val namesJS = rs.body.validate[Seq[String]]
    handleNamesStrings(namesJS)
  }
}
{'fraction_non_alphanumeric': 0.12552571983176966, 'fraction_numerical': 0.0012940795858945326, 'mean_word_length': 3.276625172890733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '4108625', 'n_tokens_mistral': 995, 'n_tokens_neox': 961, 'n_words': 183}