Created
May 16, 2016 06:22
-
-
Save tatesuke/ee415c57221e8e6cafd34d10aa0ecf55 to your computer and use it in GitHub Desktop.
javadoc_words groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def words = [] | |
def input = new File("org.txt") | |
input.eachLine { | |
it.split(" ").each {it2 -> | |
it2 = it2.toLowerCase() | |
.replaceFirst(/^\(/, "") | |
.replaceFirst(/\)$/, "") | |
.replaceFirst(/^\"/, "") | |
.replaceFirst(/\"$/, "") | |
.replaceFirst(/,$/, "") | |
.replaceFirst(/\.$/, "") | |
.replaceFirst(/:$/, "") | |
.replaceFirst(/;$/, "") | |
.replaceFirst(/\?$/, "") | |
words.push(it2) | |
} | |
} | |
words.sort() | |
def wordCount = [:] | |
def current = ""; | |
words.each { | |
if (it != "" && it == current) { | |
wordCount[current]++ | |
} else if (it != ""){ | |
current = it | |
wordCount.put(current, 1); | |
} | |
} | |
wordCount.sort({kv1, kv2->kv2.value-kv1.value}).each { key, value -> | |
println "${key}\t${value}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment