Advertisement
Guest User

Occurrences

a guest
Jun 13th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.35 KB | None | 0 0
  1. def wordOccurrences(w: Word): Occurrences = {
  2.     val occMap = w.toLowerCase groupBy (c => c) mapValues( _.size )
  3.     occMap.toList
  4.   }
  5.    
  6.   /** Converts a sentence into its character occurrence list. */
  7.   def sentenceOccurrences(s: Sentence): Occurrences = {
  8.     val wordOccs = for ( word <- s ) yield wordOccurrences( word )
  9.     wordOccs.toList.flatten
  10.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement