juan_gandhi: (VP)
Juan-Carlos Gandhi ([personal profile] juan_gandhi) wrote2014-10-23 01:16 pm
Entry tags:

DoggyEnglish

object DoggyEnglish {
  val meaningless = Set("name", "of", "the", "my", "your", "in", "what", "which", "was", "is")

  val synonyms = Set("city, town", "sibling, siblings", "job, work") .map {
    word => word.split(", ").toList
  } .collect {
    case main::tail => tail map (w => w -> main)
  } .flatten .toMap withDefault identity


  def simplifyQuestion(question: String) = {
    val noPunctuation = question.toLowerCase.replaceAll("[^a-z ]", "")
    val words = noPunctuation split " "
    val meaningfulWords = words filterNot meaningless
    val standardized = meaningfulWords map synonyms
    standardized mkString " "
  }

}

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting