<commit_before>package sp.services

import akka.actor._
import sp.domain._
import sp.system.messages._
import sp.domain.logic.PropositionParser
import sp.domain.logic.ActionParser
import sp.domain.Logic._
import sp.system._
import akka.util._
import scala.concurrent.duration._
import org.json4s._

/**
 * The service parse a string into a proposition and returns it.
 * Send a request including attributes:
 * "model" -> "the name of the model"
 * "parse" -> "the string to parse" e.g. r1.tool==kalle AND r2 = false
 * If we need better performance from multiple requests in the future,
 * we can have multiple actors in a round robin.
  **/
object PropositionParserService extends SPService {
  val specification = SPAttributes(
    "service" -> SPAttributes(
      "group" -> "Hidden",
      "description" -> "Parse and print proposition conditions"
    )
  )


  val transformation = List()

  def props = ServiceLauncher.props(Props(classOf[PropositionParserService]))
}

class PropositionParserService extends Actor with ServiceSupport {
  implicit val timeout = Timeout(5 seconds)

  import context.dispatcher

  def receive = {
    case r@Request(service, attr, ids, reqID) => {
      val replyTo = sender()
      implicit val rnr = RequestNReply(r, replyTo)
      val progress = context.actorOf(progressHandler)
      progress ! SPAttributes("progress" -> "starting prop parser")

      println(r.attributes)

      val command = r.attributes.getAs[String]("command").get
      val core = r.attributes.getAs[ServiceHandlerAttributes]("core").get

      command match {
        case "parseGuard" =>
          val toParse = r.attributes.getAs[String]("toParse").get
          PropositionParser(ids).parseStr(toParse) match {
            case Left(failure) =>
              val errorMess = "[" + failure.next.pos + "] error: " + failure.msg + "\n\n" + failure.next.pos.longString
              replyTo ! Response(List(), SPAttributes("parseError" -> errorMess), rnr.req.service, rnr.req.reqID)
            case Right(prop) => {
              replyTo ! Response(List(), SPAttributes("proposition" -> prop), rnr.req.service, rnr.req.reqID)
            }
          }
          terminate(progress)

        case "printGuard" =><commit_msg>Removed debug print in parser service<commit_after>package sp.services

import akka.actor._
import sp.domain._
import sp.system.messages._
import sp.domain.logic.PropositionParser
import sp.domain.logic.ActionParser
import sp.domain.Logic._
import sp.system._
import akka.util._
import scala.concurrent.duration._
import org.json4s._

/**
 * The service parse a string into a proposition and returns it.
 * Send a request including attributes:
 * "model" -> "the name of the model"
 * "parse" -> "the string to parse" e.g. r1.tool==kalle AND r2 = false
 * If we need better performance from multiple requests in the future,
 * we can have multiple actors in a round robin.
  **/
object PropositionParserService extends SPService {
  val specification = SPAttributes(
    "service" -> SPAttributes(
      "group" -> "Hidden",
      "description" -> "Parse and print proposition conditions"
    )
  )


  val transformation = List()

  def props = ServiceLauncher.props(Props(classOf[PropositionParserService]))
}

class PropositionParserService extends Actor with ServiceSupport {
  implicit val timeout = Timeout(5 seconds)

  import context.dispatcher

  def receive = {
    case r@Request(service, attr, ids, reqID) => {
      val replyTo = sender()
      implicit val rnr = RequestNReply(r, replyTo)
      val progress = context.actorOf(progressHandler)
      progress ! SPAttributes("progress" -> "starting prop parser")

      val command = r.attributes.getAs[String]("command").get
      val core = r.attributes.getAs[ServiceHandlerAttributes]("core").get

      command match {
        case "parseGuard" =>
          val toParse = r.attributes.getAs[String]("toParse").get
          PropositionParser(ids).parseStr(toParse) match {
            case Left(failure) =>
              val errorMess = "[" + failure.next.pos + "] error: " + failure.msg + "\n\n" + failure.next.pos.longString
              replyTo ! Response(List(), SPAttributes("parseError" -> errorMess), rnr.req.service, rnr.req.reqID)
            case Right(prop) => {
              replyTo ! Response(List(), SPAttributes("proposition" -> prop), rnr.req.service, rnr.req.reqID)
            }
          }
          terminate(progress)

        case "printGuard" =>
{'fraction_non_alphanumeric': 0.11279874916238553, 'fraction_numerical': 0.0017869108778199687, 'mean_word_length': 3.142460684551341, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, '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': '7656254', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1260, 'n_words': 354}