<commit_before>/*
 * #%L
 * Core runtime for OOXOO
 * %%
 * Copyright (C) 2008 - 2014 OSI / Computer Architecture Group @ Uni. Heidelberg
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-3.0.html>.
 * #L%
 */
package com.idyria.osi.ooxoo.model.out.scala

import com.idyria.osi.ooxoo.model._
import com.idyria.osi.ooxoo.core.buffers.structural._
import com.idyria.osi.ooxoo.core.buffers.datatypes.XSDStringBuffer
import com.idyria.osi.ooxoo.core.buffers.datatypes.EnumerationBuffer
import com.idyria.osi.ooxoo.core.buffers.datatypes.BooleanBuffer
import com.idyria.osi.ooxoo.core.buffers.datatypes.IntegerBuffer
import com.idyria.osi.ooxoo.core.buffers.datatypes.DoubleBuffer
import org.atteo.evo.inflector.English
import com.idyria.osi.ooxoo.core.buffers.datatypes.CDataBuffer

/**
 * This Producer creates scala class implementations for the models
 *
 */
class ScalaProducer extends ModelProducer {

  this.outputType = "scala"

  // Name Cleaning
  //-------------------

  val forbiddenKeyWords = List("for", "trait", "class", "package", "var", "val", "def", "private", "final", "match", "case", "object", "type", "lazy", "extends", "with")

  /**
   * Returns a scala friendly name from base name, without reserved keywords etc...
   */
  def cleanName(name: String): String = {

    // Trim and Lower case first character
    // If all letters are capital, keep it this way
    var res = name.trim().find { c => c.isLower } match {
      case None => name.trim()
      case _ => name.trim().zipWithIndex.map {
        case (c, 0) => c.toLower;

        case (c, i) => c
      }.mkString
    }

    // Prefix with _ is the name is a keyword
    forbiddenKeyWords.contains(res) match {
      case true ⇒ res = res + "_"
      case false ⇒
    }

    res
  }

  /**
   * Makes the name plural
   */
  def makePlural(name: String): String = {

    name match {
      case name if (name.matches(".*s")) => name
      case _ => English.plural(name)
    }

    /*
    name match {
      case name if (name.matches(".*[aeiou]s")) => name+"es"
      case name if (name.matches(".*s")) => name
      case name if (name.matches(".*e")) => name+"s"
      case _ => name+"es"<commit_msg>Scala Model Producer: Names of length one have no plurals<commit_after>/*
 * #%L
 * Core runtime for OOXOO
 * %%
 * Copyright (C) 2008 - 2014 OSI / Computer Architecture Group @ Uni. Heidelberg
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public
 * License along with this program.  If not, see
 * <http://www.gnu.org/licenses/gpl-3.0.html>.
 * #L%
 */
package com.idyria.osi.ooxoo.model.out.scala

import com.idyria.osi.ooxoo.model._
import com.idyria.osi.ooxoo.core.buffers.structural._
import com.idyria.osi.ooxoo.core.buffers.datatypes.XSDStringBuffer
import com.idyria.osi.ooxoo.core.buffers.datatypes.EnumerationBuffer
import com.idyria.osi.ooxoo.core.buffers.datatypes.BooleanBuffer
import com.idyria.osi.ooxoo.core.buffers.datatypes.IntegerBuffer
import com.idyria.osi.ooxoo.core.buffers.datatypes.DoubleBuffer
import org.atteo.evo.inflector.English
import com.idyria.osi.ooxoo.core.buffers.datatypes.CDataBuffer

/**
 * This Producer creates scala class implementations for the models
 *
 */
class ScalaProducer extends ModelProducer {

  this.outputType = "scala"

  // Name Cleaning
  //-------------------

  val forbiddenKeyWords = List("for", "trait", "class", "package", "var", "val", "def", "private", "final", "match", "case", "object", "type", "lazy", "extends", "with")

  /**
   * Returns a scala friendly name from base name, without reserved keywords etc...
   */
  def cleanName(name: String): String = {

    // Trim and Lower case first character
    // If all letters are capital, keep it this way
    var res = name.trim().find { c => c.isLower } match {
      case None => name.trim()
      case _ => name.trim().zipWithIndex.map {
        case (c, 0) => c.toLower;

        case (c, i) => c
      }.mkString
    }

    // Prefix with _ is the name is a keyword
    forbiddenKeyWords.contains(res) match {
      case true ⇒ res = res + "_"
      case false ⇒
    }

    res
  }

  /**
   * Makes the name plural
   */
  def makePlural(name: String): String = {

    name match {
      case name if(name.length()==1) => name
      case name if (name.matches(".*s")) => name
      case _ => English.plural(name)
    }

    /*
    name match {
      case name if (name.matches(".*[aeiou]s")) => name+"es"
      case name if (name.matches(".*s")) => name
      case name if (name.matches(".*e")) => name+"s"
      case _ => name+"es"
{'fraction_non_alphanumeric': 0.1316393153343921, 'fraction_numerical': 0.0044115052055761425, 'mean_word_length': 3.0028248587570623, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7253420', 'n_tokens_mistral': 1834, 'n_tokens_neox': 1776, 'n_words': 566}