Juan-Carlos Gandhi (
juan_gandhi) wrote2014-10-23 01:16 pm
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
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 " " } }