def topWordCounts = { String content, int n -> def mapCounts = [:] content.toLowerCase().split(/\W+/).each { mapCounts[it] = (mapCounts[it] ?: 0) + 1 } def top = (mapCounts.sort { a, b -> b.value <=> a.value }.collect{ it })[0..